From 82abbf5baddb0c7a6fb69e15e9b65e4604f3186f Mon Sep 17 00:00:00 2001 From: n4ze3m Date: Sat, 6 Apr 2024 10:48:51 +0530 Subject: [PATCH] Add SelectedKnowledge component to OptionLayout and KnowledgeSelect --- src/components/Layouts/Layout.tsx | 2 + .../Option/Knowledge/KnowledgeSelect.tsx | 78 ++++++++++--------- .../Option/Knowledge/SelectedKnwledge.tsx | 51 ++++++------ .../Option/Playground/PlaygroundForm.tsx | 4 +- 4 files changed, 66 insertions(+), 69 deletions(-) diff --git a/src/components/Layouts/Layout.tsx b/src/components/Layouts/Layout.tsx index f5455c1..3cf9c94 100644 --- a/src/components/Layouts/Layout.tsx +++ b/src/components/Layouts/Layout.tsx @@ -19,6 +19,7 @@ import { getAllPrompts } from "@/db" import { ShareBtn } from "~/components/Common/ShareBtn" import { useTranslation } from "react-i18next" import { OllamaIcon } from "../Icons/Ollama" +import { SelectedKnowledge } from "../Option/Knowledge/SelectedKnwledge" export default function OptionLayout({ children @@ -166,6 +167,7 @@ export default function OptionLayout({ }))} /> +
diff --git a/src/components/Option/Knowledge/KnowledgeSelect.tsx b/src/components/Option/Knowledge/KnowledgeSelect.tsx index 0e4de2b..95b036a 100644 --- a/src/components/Option/Knowledge/KnowledgeSelect.tsx +++ b/src/components/Option/Knowledge/KnowledgeSelect.tsx @@ -19,42 +19,46 @@ export const KnowledgeSelect: React.FC = () => { }) return ( - ({ - key: d.id, - label: ( -
-
- -
- {d.title} -
- ), - onClick: () => { - const knowledge = data?.find((k) => k.id === d.id) - if (selectedKnowledge?.id === d.id) { - setSelectedKnowledge(null) - } else { - setSelectedKnowledge(knowledge) - } - } - })) || [], - style: { - maxHeight: 500, - overflowY: "scroll" - }, - className: "no-scrollbar", - activeKey: selectedKnowledge?.id - }} - placement={"topLeft"} - trigger={["click"]}> - - - -
+ <> + {data && data.length > 0 && ( + ({ + key: d.id, + label: ( +
+
+ +
+ {d.title} +
+ ), + onClick: () => { + const knowledge = data?.find((k) => k.id === d.id) + if (selectedKnowledge?.id === d.id) { + setSelectedKnowledge(null) + } else { + setSelectedKnowledge(knowledge) + } + } + })) || [], + style: { + maxHeight: 500, + overflowY: "scroll" + }, + className: "no-scrollbar", + activeKey: selectedKnowledge?.id + }} + placement={"topLeft"} + trigger={["click"]}> + + + +
+ )} + ) } diff --git a/src/components/Option/Knowledge/SelectedKnwledge.tsx b/src/components/Option/Knowledge/SelectedKnwledge.tsx index 7cdc0ca..c217465 100644 --- a/src/components/Option/Knowledge/SelectedKnwledge.tsx +++ b/src/components/Option/Knowledge/SelectedKnwledge.tsx @@ -1,39 +1,32 @@ -import { Knowledge } from "@/db/knowledge" -import { XIcon } from "lucide-react" -import { KnowledgeIcon } from "./KnowledgeIcon" +import { Blocks, XIcon } from "lucide-react" +import { useMessageOption } from "@/hooks/useMessageOption" -type Props = { - knowledge: Knowledge - onClose: () => void -} +export const SelectedKnowledge = () => { + const { selectedKnowledge: knowledge, setSelectedKnowledge } = + useMessageOption() + + if (!knowledge) return <> -export const SelectedKnowledge = ({ knowledge, onClose }: Props) => { return ( -
-
-
-

+
+ + {"/"} + +
+
+ + {knowledge.title} -

+
-
- {knowledge.source.map((source, index) => ( -
- - {source.filename} -
- ))} +
+
-
- -
) } diff --git a/src/components/Option/Playground/PlaygroundForm.tsx b/src/components/Option/Playground/PlaygroundForm.tsx index 4c15e6d..64c3683 100644 --- a/src/components/Option/Playground/PlaygroundForm.tsx +++ b/src/components/Option/Playground/PlaygroundForm.tsx @@ -35,8 +35,7 @@ export const PlaygroundForm = ({ dropedFile }: Props) => { selectedQuickPrompt, textareaRef, setSelectedQuickPrompt, - selectedKnowledge, - setSelectedKnowledge + selectedKnowledge } = useMessageOption() const textAreaFocus = () => { @@ -158,7 +157,6 @@ export const PlaygroundForm = ({ dropedFile }: Props) => { } return (
-