satof3 6 месяцев назад
Родитель
Сommit
9839d3de1a

+ 2 - 20
apps/app/src/features/openai/client/components/AiAssistant/AiAssistantSidebar/AiAssistantSidebar.tsx

@@ -68,7 +68,6 @@ const AiAssistantSidebarSubstance: React.FC<AiAssistantSidebarSubstanceProps> =
   // Hooks
   const { t } = useTranslation();
   const { data: growiCloudUri } = useGrowiCloudUri();
-  const { refreshThreadData } = useAiAssistantSidebar();
 
   const {
     createThread: createThreadForKnowledgeAssistant,
@@ -76,6 +75,7 @@ const AiAssistantSidebarSubstance: React.FC<AiAssistantSidebarSubstanceProps> =
     processMessage: processMessageForKnowledgeAssistant,
     form: formForKnowledgeAssistant,
     resetForm: resetFormForKnowledgeAssistant,
+    threadTitleView: threadTitleViewForKnowledgeAssistant,
 
     // Views
     initialView: initialViewForKnowledgeAssistant,
@@ -105,11 +105,6 @@ const AiAssistantSidebarSubstance: React.FC<AiAssistantSidebarSubstanceProps> =
 
   const form = isEditorAssistant ? formForEditorAssistant : formForKnowledgeAssistant;
 
-  const handleBackToInitialView = useCallback(() => {
-    refreshThreadData(undefined);
-    setMessageLogs([]);
-  }, [refreshThreadData]);
-
   // Effects
   useFetchAndSetMessageDataEffect(setMessageLogs, threadData?.threadId);
 
@@ -438,20 +433,7 @@ const AiAssistantSidebarSubstance: React.FC<AiAssistantSidebarSubstanceProps> =
             className="h-100"
             autoHide
           >
-            {!isEditorAssistant && threadData?.title && (
-              <div className="thread-title-sticky position-sticky top-0 py-2 px-3">
-                <div className="d-flex align-items-center gap-2">
-                  <button
-                    type="button"
-                    className="btn btn-sm btn-link p-0 text-secondary"
-                    onClick={handleBackToInitialView}
-                  >
-                    <span className="material-symbols-outlined">chevron_left</span>
-                  </button>
-                  <span className="text-truncate small">{threadData.title}</span>
-                </div>
-              </div>
-            )}
+            {!isEditorAssistant && threadTitleViewForKnowledgeAssistant}
             <div className="p-4">
               <div className="d-flex flex-column gap-4 flex-grow-1">
                 { threadData != null

+ 31 - 1
apps/app/src/features/openai/client/services/knowledge-assistant.tsx

@@ -61,6 +61,8 @@ type UseKnowledgeAssistant = () => {
   processMessage: ProcessMessage
   form: UseFormReturn<FormData>
   resetForm: () => void
+  handleBackToInitialView: () => void;
+  threadTitleView: JSX.Element | null;
 
   // Views
   initialView: JSX.Element
@@ -72,7 +74,7 @@ type UseKnowledgeAssistant = () => {
 
 export const useKnowledgeAssistant: UseKnowledgeAssistant = () => {
   // Hooks
-  const { data: aiAssistantSidebarData } = useAiAssistantSidebar();
+  const { data: aiAssistantSidebarData, refreshThreadData } = useAiAssistantSidebar();
   const { aiAssistantData } = aiAssistantSidebarData ?? {};
   const { mutate: mutateRecentThreads } = useSWRINFxRecentThreads();
   const { trigger: mutateThreadData } = useSWRMUTxThreads(aiAssistantData?._id);
@@ -85,6 +87,9 @@ export const useKnowledgeAssistant: UseKnowledgeAssistant = () => {
       extendedThinkingMode: false,
     },
   });
+  const handleBackToInitialView = useCallback(() => {
+    refreshThreadData(undefined);
+  }, [refreshThreadData]);
 
   // Functions
   const resetForm = useCallback(() => {
@@ -231,12 +236,37 @@ export const useKnowledgeAssistant: UseKnowledgeAssistant = () => {
     );
   }, [dropdownOpen, toggleDropdown, form, t]);
 
+  const threadTitleView = useMemo(() => {
+    const { threadData } = aiAssistantSidebarData ?? {};
+
+    if (threadData?.title == null) {
+      return null;
+    }
+
+    return (
+      <div className="thread-title-sticky position-sticky top-0 py-2 px-3">
+        <div className="d-flex align-items-center gap-2">
+          <button
+            type="button"
+            className="btn btn-sm btn-link p-0 text-secondary"
+            onClick={handleBackToInitialView}
+          >
+            <span className="material-symbols-outlined">chevron_left</span>
+          </button>
+          <span className="text-truncate small">{threadData.title}</span>
+        </div>
+      </div>
+    );
+  }, [aiAssistantSidebarData, handleBackToInitialView]);
+
   return {
     createThread,
     postMessage,
     processMessage,
     form,
     resetForm,
+    handleBackToInitialView,
+    threadTitleView,
 
     // Views
     initialView,