pages/index: на главную страницу добавлен компонент чата, предлагающий начать общение
This commit is contained in:
@@ -1,12 +1,26 @@
|
|||||||
import Link from '@docusaurus/Link';
|
import Link from '@docusaurus/Link';
|
||||||
|
import { useHistory } from '@docusaurus/router';
|
||||||
|
import useBaseUrl from '@docusaurus/useBaseUrl';
|
||||||
import useDocusaurusContext from '@docusaurus/useDocusaurusContext';
|
import useDocusaurusContext from '@docusaurus/useDocusaurusContext';
|
||||||
import Heading from '@theme/Heading';
|
import Heading from '@theme/Heading';
|
||||||
import Layout from '@theme/Layout';
|
import Layout from '@theme/Layout';
|
||||||
import clsx from 'clsx';
|
import clsx from 'clsx';
|
||||||
import type { ReactNode } from 'react';
|
import type { ReactNode } from 'react';
|
||||||
|
|
||||||
|
import { IChat } from '@docuservix/models/chat';
|
||||||
|
import { Chat } from '@docuservix/widgets/chat';
|
||||||
|
|
||||||
import styles from './index.module.css';
|
import styles from './index.module.css';
|
||||||
|
|
||||||
|
const startDialog: IChat = {
|
||||||
|
messages: [
|
||||||
|
{
|
||||||
|
role: 'assistant',
|
||||||
|
content: 'Чем могу помочь?',
|
||||||
|
},
|
||||||
|
],
|
||||||
|
};
|
||||||
|
|
||||||
function HomepageHeader() {
|
function HomepageHeader() {
|
||||||
const { siteConfig } = useDocusaurusContext();
|
const { siteConfig } = useDocusaurusContext();
|
||||||
|
|
||||||
@@ -35,6 +49,12 @@ function HomepageHeader() {
|
|||||||
|
|
||||||
export default function Home(): ReactNode {
|
export default function Home(): ReactNode {
|
||||||
const { siteConfig } = useDocusaurusContext();
|
const { siteConfig } = useDocusaurusContext();
|
||||||
|
const history = useHistory();
|
||||||
|
const chatUrl = useBaseUrl('/chat');
|
||||||
|
|
||||||
|
const handleSend = (text: string) => {
|
||||||
|
history.push(`${chatUrl}?q=${encodeURIComponent(text)}`);
|
||||||
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Layout
|
<Layout
|
||||||
@@ -42,6 +62,12 @@ export default function Home(): ReactNode {
|
|||||||
description="Description will go into a meta tag in <head />"
|
description="Description will go into a meta tag in <head />"
|
||||||
>
|
>
|
||||||
<HomepageHeader />
|
<HomepageHeader />
|
||||||
|
<main className="container margin-vert--lg">
|
||||||
|
<Chat
|
||||||
|
dialog={startDialog}
|
||||||
|
onSend={handleSend}
|
||||||
|
/>
|
||||||
|
</main>
|
||||||
</Layout>
|
</Layout>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user