2023-06-11 00:59:16 +03:00
|
|
|
"use client";
|
2023-06-15 12:52:46 +03:00
|
|
|
|
2024-02-07 10:34:50 +03:00
|
|
|
import { UUID } from "crypto";
|
|
|
|
import { useEffect } from "react";
|
|
|
|
|
2024-02-07 03:05:07 +03:00
|
|
|
import { AddBrainModal } from "@/lib/components/AddBrainModal";
|
|
|
|
import { useBrainCreationContext } from "@/lib/components/AddBrainModal/components/AddBrainSteps/brainCreation-provider";
|
|
|
|
import PageHeader from "@/lib/components/PageHeader/PageHeader";
|
|
|
|
import { UploadDocumentModal } from "@/lib/components/UploadDocumentModal/UploadDocumentModal";
|
2024-02-07 10:34:50 +03:00
|
|
|
import { useChatContext } from "@/lib/context";
|
|
|
|
import { useBrainContext } from "@/lib/context/BrainProvider/hooks/useBrainContext";
|
2023-09-29 11:24:31 +03:00
|
|
|
import { useKnowledgeToFeedContext } from "@/lib/context/KnowledgeToFeedProvider/hooks/useKnowledgeToFeedContext";
|
2024-01-25 23:44:24 +03:00
|
|
|
import { useDevice } from "@/lib/hooks/useDevice";
|
2023-09-28 12:29:55 +03:00
|
|
|
import { useCustomDropzone } from "@/lib/hooks/useDropzone";
|
2024-02-07 03:05:07 +03:00
|
|
|
import { ButtonType } from "@/lib/types/QuivrButton";
|
2023-12-14 18:22:09 +03:00
|
|
|
import { cn } from "@/lib/utils";
|
2023-09-28 12:29:55 +03:00
|
|
|
|
2023-08-11 11:06:20 +03:00
|
|
|
import { ActionsBar } from "./components/ActionsBar";
|
2023-09-12 18:44:15 +03:00
|
|
|
import { ChatDialogueArea } from "./components/ChatDialogueArea/ChatDialogue";
|
2024-01-25 23:44:24 +03:00
|
|
|
import DataPanel from "./components/DataPanel/DataPanel";
|
2023-12-14 18:22:09 +03:00
|
|
|
import { useChatNotificationsSync } from "./hooks/useChatNotificationsSync";
|
2024-01-25 23:44:24 +03:00
|
|
|
import styles from "./page.module.scss";
|
2023-06-11 00:59:16 +03:00
|
|
|
|
2023-07-05 19:33:18 +03:00
|
|
|
const SelectedChatPage = (): JSX.Element => {
|
2024-01-25 23:44:24 +03:00
|
|
|
const { getRootProps } = useCustomDropzone();
|
|
|
|
const { isMobile } = useDevice();
|
2023-12-14 18:22:09 +03:00
|
|
|
|
2024-02-07 03:05:07 +03:00
|
|
|
const { setShouldDisplayFeedCard } = useKnowledgeToFeedContext();
|
|
|
|
const { setIsBrainCreationModalOpened } = useBrainCreationContext();
|
|
|
|
|
2024-02-07 10:34:50 +03:00
|
|
|
const { currentBrain, setCurrentBrainId } = useBrainContext();
|
|
|
|
const { messages } = useChatContext();
|
|
|
|
|
2024-01-25 23:44:24 +03:00
|
|
|
useChatNotificationsSync();
|
2023-09-27 16:39:04 +03:00
|
|
|
|
2024-02-07 03:05:07 +03:00
|
|
|
const buttons: ButtonType[] = [
|
|
|
|
{
|
|
|
|
label: "Create brain",
|
|
|
|
color: "primary",
|
|
|
|
onClick: () => {
|
|
|
|
setIsBrainCreationModalOpened(true);
|
|
|
|
},
|
2024-02-07 10:34:50 +03:00
|
|
|
iconName: "brain",
|
2024-02-07 03:05:07 +03:00
|
|
|
},
|
|
|
|
{
|
|
|
|
label: "Add knowledge",
|
|
|
|
color: "primary",
|
|
|
|
onClick: () => {
|
|
|
|
setShouldDisplayFeedCard(true);
|
|
|
|
},
|
2024-02-11 03:17:05 +03:00
|
|
|
iconName: "uploadFile",
|
2024-02-07 10:34:50 +03:00
|
|
|
},
|
|
|
|
{
|
|
|
|
label: "Manage current brain",
|
|
|
|
color: "primary",
|
|
|
|
onClick: () => {
|
|
|
|
window.location.href = `/studio/${currentBrain?.id}`;
|
|
|
|
},
|
|
|
|
iconName: "edit",
|
2024-02-07 03:05:07 +03:00
|
|
|
},
|
|
|
|
];
|
|
|
|
|
2024-02-07 10:34:50 +03:00
|
|
|
useEffect(() => {
|
|
|
|
if (!currentBrain && messages.length > 0) {
|
|
|
|
setCurrentBrainId(messages[messages.length - 1].brain_id as UUID);
|
|
|
|
}
|
|
|
|
}, [messages]);
|
|
|
|
|
2024-01-25 23:44:24 +03:00
|
|
|
return (
|
2024-02-07 03:05:07 +03:00
|
|
|
<div className={styles.main_container}>
|
|
|
|
<div className={styles.page_header}>
|
|
|
|
<PageHeader iconName="chat" label="Chat" buttons={buttons} />
|
|
|
|
</div>
|
2024-01-25 23:44:24 +03:00
|
|
|
<div
|
2024-02-07 03:05:07 +03:00
|
|
|
className={styles.chat_page_container}
|
|
|
|
data-testid="chat-page"
|
|
|
|
{...getRootProps()}
|
2024-01-25 23:44:24 +03:00
|
|
|
>
|
|
|
|
<div
|
2024-02-07 03:05:07 +03:00
|
|
|
className={cn(
|
|
|
|
"flex flex-col flex-1 items-center justify-stretch w-full h-full overflow-hidden",
|
|
|
|
"dark:bg-black transition-colors ease-out duration-500"
|
|
|
|
)}
|
2024-01-25 23:44:24 +03:00
|
|
|
>
|
2024-02-07 03:05:07 +03:00
|
|
|
<div
|
|
|
|
className={`flex flex-col flex-1 w-full max-w-4xl h-full dark:shadow-primary/25 overflow-hidden`}
|
|
|
|
>
|
|
|
|
<div className="flex flex-1 flex-col overflow-y-auto">
|
|
|
|
<ChatDialogueArea />
|
|
|
|
</div>
|
|
|
|
<ActionsBar />
|
2024-01-25 23:44:24 +03:00
|
|
|
</div>
|
2023-08-11 11:06:20 +03:00
|
|
|
</div>
|
2024-02-07 03:05:07 +03:00
|
|
|
{!isMobile && (
|
|
|
|
<div className={styles.data_panel_wrapper}>
|
|
|
|
<DataPanel />
|
|
|
|
</div>
|
|
|
|
)}
|
|
|
|
<UploadDocumentModal />
|
|
|
|
<AddBrainModal />
|
2024-01-25 23:44:24 +03:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
);
|
2023-07-05 10:30:22 +03:00
|
|
|
};
|
|
|
|
|
2023-07-05 19:33:18 +03:00
|
|
|
export default SelectedChatPage;
|