Skip to content

Commit

Permalink
🚑 fix: use the same logic to get export data as useChatHelper
Browse files Browse the repository at this point in the history
  • Loading branch information
ohneda committed May 18, 2024
1 parent 2916688 commit d7e0b1f
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions client/src/hooks/Conversations/useExportConversation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import type {
import useBuildMessageTree from '~/hooks/Messages/useBuildMessageTree';
import { useScreenshot } from '~/hooks/ScreenshotContext';
import { cleanupPreset, buildTree } from '~/utils';
import { useParams } from 'react-router-dom';

export default function useExportConversation({
conversation,
Expand All @@ -34,15 +35,16 @@ export default function useExportConversation({
}) {
const { captureScreenshot } = useScreenshot();
const buildMessageTree = useBuildMessageTree();
const { data: messagesTree = null } = useGetMessagesByConvoId(
conversation?.conversationId ?? '',
{
select: (data) => {
const dataTree = buildTree({ messages: data });
return dataTree?.length === 0 ? null : dataTree ?? null;
},

const { conversationId: paramId } = useParams();
const queryParam = paramId === 'new' ? paramId : conversation?.conversationId ?? paramId ?? '';

const { data: messagesTree = null } = useGetMessagesByConvoId(queryParam, {
select: (data) => {
const dataTree = buildTree({ messages: data });
return dataTree?.length === 0 ? null : dataTree ?? null;
},
);
});

const getMessageText = (message: TMessage, format = 'text') => {
if (!message) {
Expand Down

0 comments on commit d7e0b1f

Please sign in to comment.