|
|
@@ -5,7 +5,7 @@ import { useTranslation } from 'react-i18next';
|
|
|
|
|
|
import InfiniteScroll from '~/client/components/InfiniteScroll';
|
|
|
import { toastError, toastSuccess } from '~/client/util/toastr';
|
|
|
-import { useSWRINFxRecentThreads } from '~/features/openai/client/stores/thread';
|
|
|
+import { useSWRMUTxThreads, useSWRINFxRecentThreads } from '~/features/openai/client/stores/thread';
|
|
|
import loggerFactory from '~/utils/logger';
|
|
|
|
|
|
import { deleteThread } from '../../../services/thread';
|
|
|
@@ -16,8 +16,9 @@ const logger = loggerFactory('growi:openai:client:components:ThreadList');
|
|
|
export const ThreadList: React.FC = () => {
|
|
|
const swrInifiniteThreads = useSWRINFxRecentThreads();
|
|
|
const { t } = useTranslation();
|
|
|
- const { data, mutate } = swrInifiniteThreads;
|
|
|
- const { openChat } = useAiAssistantSidebar();
|
|
|
+ const { data, mutate: mutateRecentThreads } = swrInifiniteThreads;
|
|
|
+ const { openChat, data: aiAssistantSidebarData, close: closeAiAssistantSidebar } = useAiAssistantSidebar();
|
|
|
+ const { trigger: mutateAssistantThreadData } = useSWRMUTxThreads(aiAssistantSidebarData?.aiAssistantData?._id);
|
|
|
|
|
|
const isEmpty = data?.[0]?.paginateResult.totalDocs === 0;
|
|
|
const isReachingEnd = isEmpty || (data != null && (data[data.length - 1].paginateResult.hasNextPage === false));
|
|
|
@@ -26,13 +27,19 @@ export const ThreadList: React.FC = () => {
|
|
|
try {
|
|
|
await deleteThread({ aiAssistantId, threadRelationId });
|
|
|
toastSuccess(t('ai_assistant_substance.toaster.thread_deleted_success'));
|
|
|
- mutate();
|
|
|
+
|
|
|
+ await Promise.all([mutateAssistantThreadData(), mutateRecentThreads()]);
|
|
|
+
|
|
|
+ // Close if the thread to be deleted is open in right sidebar
|
|
|
+ if (aiAssistantSidebarData?.isOpened && aiAssistantSidebarData?.threadData?._id === threadRelationId) {
|
|
|
+ closeAiAssistantSidebar();
|
|
|
+ }
|
|
|
}
|
|
|
catch (err) {
|
|
|
logger.error(err);
|
|
|
toastError(t('ai_assistant_substance.toaster.thread_deleted_failed'));
|
|
|
}
|
|
|
- }, [mutate, t]);
|
|
|
+ }, [aiAssistantSidebarData?.isOpened, aiAssistantSidebarData?.threadData?._id, closeAiAssistantSidebar, mutateAssistantThreadData, mutateRecentThreads, t]);
|
|
|
|
|
|
return (
|
|
|
<>
|