feat: Select derived messages from backend #2088 (#2176)

### What problem does this PR solve?

feat: Select derived messages from backend #2088

### Type of change

- [x] New Feature (non-breaking change which adds functionality)
This commit is contained in:
balibabu
2024-08-30 17:53:30 +08:00
committed by GitHub
parent 2c771fb0b4
commit 5400467da1
13 changed files with 556 additions and 220 deletions

View File

@ -4,13 +4,12 @@ import {
IDialog,
IStats,
IToken,
Message,
} from '@/interfaces/database/chat';
import { IFeedbackRequestBody } from '@/interfaces/request/chat';
import i18n from '@/locales/config';
import { IClientConversation, IMessage } from '@/pages/chat/interface';
import { IClientConversation } from '@/pages/chat/interface';
import chatService from '@/services/chat-service';
import { buildMessageUuid, isConversationIdExist } from '@/utils/chat';
import { buildMessageListWithUuid, isConversationIdExist } from '@/utils/chat';
import { useMutation, useQuery, useQueryClient } from '@tanstack/react-query';
import { message } from 'antd';
import dayjs, { Dayjs } from 'dayjs';
@ -18,15 +17,6 @@ import { set } from 'lodash';
import { useCallback, useMemo, useState } from 'react';
import { useSearchParams } from 'umi';
const buildMessageListWithUuid = (messages?: Message[]) => {
return (
messages?.map((x: Message | IMessage) => ({
...x,
id: buildMessageUuid(x),
})) ?? []
);
};
//#region logic
export const useClickDialogCard = () => {
@ -465,14 +455,11 @@ export const useCreateNextSharedConversation = () => {
return { data, loading, createSharedConversation: mutateAsync };
};
export const useFetchNextSharedConversation = () => {
const {
data,
isPending: loading,
mutateAsync,
} = useMutation({
mutationKey: ['fetchSharedConversation'],
mutationFn: async (conversationId: string) => {
export const useFetchNextSharedConversation = (conversationId: string) => {
const { data, isPending: loading } = useQuery({
queryKey: ['fetchSharedConversation'],
enabled: !!conversationId,
queryFn: async () => {
const { data } = await chatService.getExternalConversation(
null,
conversationId,
@ -486,7 +473,7 @@ export const useFetchNextSharedConversation = () => {
},
});
return { data, loading, fetchConversation: mutateAsync };
return { data, loading };
};
//#endregion