|
@@ -45,8 +45,6 @@ type AiAssistantSidebarSubstanceProps = {
|
|
|
aiAssistantData?: AiAssistantHasId;
|
|
aiAssistantData?: AiAssistantHasId;
|
|
|
threadData?: IThreadRelationHasId;
|
|
threadData?: IThreadRelationHasId;
|
|
|
onCloseButtonClicked?: () => void;
|
|
onCloseButtonClicked?: () => void;
|
|
|
- onNewThreadCreated?: (thread: IThreadRelationHasId) => void;
|
|
|
|
|
- onMessageReceived?: () => void;
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
const AiAssistantSidebarSubstance: React.FC<AiAssistantSidebarSubstanceProps> = (props: AiAssistantSidebarSubstanceProps) => {
|
|
const AiAssistantSidebarSubstance: React.FC<AiAssistantSidebarSubstanceProps> = (props: AiAssistantSidebarSubstanceProps) => {
|
|
@@ -55,8 +53,6 @@ const AiAssistantSidebarSubstance: React.FC<AiAssistantSidebarSubstanceProps> =
|
|
|
aiAssistantData,
|
|
aiAssistantData,
|
|
|
threadData,
|
|
threadData,
|
|
|
onCloseButtonClicked,
|
|
onCloseButtonClicked,
|
|
|
- onNewThreadCreated,
|
|
|
|
|
- onMessageReceived,
|
|
|
|
|
} = props;
|
|
} = props;
|
|
|
|
|
|
|
|
// States
|
|
// States
|
|
@@ -69,6 +65,26 @@ const AiAssistantSidebarSubstance: React.FC<AiAssistantSidebarSubstanceProps> =
|
|
|
const { t } = useTranslation();
|
|
const { t } = useTranslation();
|
|
|
const growiCloudUri = useGrowiCloudUri();
|
|
const growiCloudUri = useGrowiCloudUri();
|
|
|
|
|
|
|
|
|
|
+ // useSWRxThreads is executed only when Substance is rendered
|
|
|
|
|
+ const { data: threads, mutate: mutateThreads } = useSWRxThreads(aiAssistantData?._id);
|
|
|
|
|
+ const { refreshThreadData } = useAiAssistantSidebarActions();
|
|
|
|
|
+
|
|
|
|
|
+ // refresh thread data when the data is changed
|
|
|
|
|
+ useEffect(() => {
|
|
|
|
|
+ if (threads == null) {
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ const currentThread = threads.find(t => t.threadId === threadData?.threadId);
|
|
|
|
|
+ if (currentThread != null) {
|
|
|
|
|
+ refreshThreadData(currentThread);
|
|
|
|
|
+ }
|
|
|
|
|
+ }, [threads, refreshThreadData, threadData?.threadId]);
|
|
|
|
|
+
|
|
|
|
|
+ const newThreadCreatedHandler = useCallback((thread: IThreadRelationHasId): void => {
|
|
|
|
|
+ refreshThreadData(thread);
|
|
|
|
|
+ }, [refreshThreadData]);
|
|
|
|
|
+
|
|
|
const {
|
|
const {
|
|
|
createThread: createThreadForKnowledgeAssistant,
|
|
createThread: createThreadForKnowledgeAssistant,
|
|
|
postMessage: postMessageForKnowledgeAssistant,
|
|
postMessage: postMessageForKnowledgeAssistant,
|
|
@@ -192,7 +208,7 @@ const AiAssistantSidebarSubstance: React.FC<AiAssistantSidebarSubstanceProps> =
|
|
|
|
|
|
|
|
threadId = newThread.threadId;
|
|
threadId = newThread.threadId;
|
|
|
|
|
|
|
|
- onNewThreadCreated?.(newThread);
|
|
|
|
|
|
|
+ newThreadCreatedHandler(newThread);
|
|
|
}
|
|
}
|
|
|
catch (err) {
|
|
catch (err) {
|
|
|
logger.error(err.toString());
|
|
logger.error(err.toString());
|
|
@@ -244,7 +260,7 @@ const AiAssistantSidebarSubstance: React.FC<AiAssistantSidebarSubstanceProps> =
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
// refresh thread data
|
|
// refresh thread data
|
|
|
- onMessageReceived?.();
|
|
|
|
|
|
|
+ mutateThreads();
|
|
|
return;
|
|
return;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -331,7 +347,7 @@ const AiAssistantSidebarSubstance: React.FC<AiAssistantSidebarSubstanceProps> =
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// eslint-disable-next-line max-len
|
|
// eslint-disable-next-line max-len
|
|
|
- }, [isGenerating, messageLogs, resetForm, threadData?.threadId, createThread, onNewThreadCreated, t, postMessage, form, onMessageReceived, processMessageForKnowledgeAssistant, processMessageForEditorAssistant, growiCloudUri]);
|
|
|
|
|
|
|
+ }, [isGenerating, messageLogs, resetForm, threadData?.threadId, createThread, newThreadCreatedHandler, t, postMessage, form, mutateThreads, processMessageForKnowledgeAssistant, processMessageForEditorAssistant, growiCloudUri]);
|
|
|
|
|
|
|
|
const submit = useCallback((data: FormData) => {
|
|
const submit = useCallback((data: FormData) => {
|
|
|
if (isEditorAssistant) {
|
|
if (isEditorAssistant) {
|
|
@@ -546,7 +562,7 @@ const AiAssistantSidebarSubstance: React.FC<AiAssistantSidebarSubstanceProps> =
|
|
|
|
|
|
|
|
export const AiAssistantSidebar: FC = memo((): JSX.Element => {
|
|
export const AiAssistantSidebar: FC = memo((): JSX.Element => {
|
|
|
const aiAssistantSidebarData = useAiAssistantSidebarStatus();
|
|
const aiAssistantSidebarData = useAiAssistantSidebarStatus();
|
|
|
- const { close: closeAiAssistantSidebar, refreshThreadData } = useAiAssistantSidebarActions();
|
|
|
|
|
|
|
+ const { close: closeAiAssistantSidebar } = useAiAssistantSidebarActions();
|
|
|
const { disable: disableUnifiedMergeView } = useUnifiedMergeViewActions();
|
|
const { disable: disableUnifiedMergeView } = useUnifiedMergeViewActions();
|
|
|
|
|
|
|
|
const aiAssistantData = aiAssistantSidebarData?.aiAssistantData;
|
|
const aiAssistantData = aiAssistantSidebarData?.aiAssistantData;
|
|
@@ -554,31 +570,14 @@ export const AiAssistantSidebar: FC = memo((): JSX.Element => {
|
|
|
const isOpened = aiAssistantSidebarData?.isOpened;
|
|
const isOpened = aiAssistantSidebarData?.isOpened;
|
|
|
const isEditorAssistant = aiAssistantSidebarData?.isEditorAssistant ?? false;
|
|
const isEditorAssistant = aiAssistantSidebarData?.isEditorAssistant ?? false;
|
|
|
|
|
|
|
|
- const { data: threads, mutate: mutateThreads } = useSWRxThreads(aiAssistantData?._id);
|
|
|
|
|
-
|
|
|
|
|
- const newThreadCreatedHandler = useCallback((thread: IThreadRelationHasId): void => {
|
|
|
|
|
- refreshThreadData(thread);
|
|
|
|
|
- }, [refreshThreadData]);
|
|
|
|
|
-
|
|
|
|
|
useEffect(() => {
|
|
useEffect(() => {
|
|
|
if (!aiAssistantSidebarData?.isOpened) {
|
|
if (!aiAssistantSidebarData?.isOpened) {
|
|
|
disableUnifiedMergeView();
|
|
disableUnifiedMergeView();
|
|
|
}
|
|
}
|
|
|
}, [aiAssistantSidebarData?.isOpened, disableUnifiedMergeView]);
|
|
}, [aiAssistantSidebarData?.isOpened, disableUnifiedMergeView]);
|
|
|
|
|
|
|
|
- // refresh thread data when the data is changed
|
|
|
|
|
- useEffect(() => {
|
|
|
|
|
- if (threads == null) {
|
|
|
|
|
- return;
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- const currentThread = threads.find(t => t.threadId === threadData?.threadId);
|
|
|
|
|
- if (currentThread != null) {
|
|
|
|
|
- refreshThreadData(currentThread);
|
|
|
|
|
- }
|
|
|
|
|
- }, [threads, refreshThreadData, threadData?.threadId]);
|
|
|
|
|
-
|
|
|
|
|
if (!isOpened) {
|
|
if (!isOpened) {
|
|
|
|
|
+ // biome-ignore lint/complexity/noUselessFragments: ignore
|
|
|
return <></>;
|
|
return <></>;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -591,8 +590,6 @@ export const AiAssistantSidebar: FC = memo((): JSX.Element => {
|
|
|
isEditorAssistant={isEditorAssistant}
|
|
isEditorAssistant={isEditorAssistant}
|
|
|
threadData={threadData}
|
|
threadData={threadData}
|
|
|
aiAssistantData={aiAssistantData}
|
|
aiAssistantData={aiAssistantData}
|
|
|
- onMessageReceived={mutateThreads}
|
|
|
|
|
- onNewThreadCreated={newThreadCreatedHandler}
|
|
|
|
|
onCloseButtonClicked={closeAiAssistantSidebar}
|
|
onCloseButtonClicked={closeAiAssistantSidebar}
|
|
|
/>
|
|
/>
|
|
|
</div>
|
|
</div>
|