mirror of
https://github.com/infiniflow/ragflow.git
synced 2026-01-31 15:45:08 +08:00
Fix: Fixed the issue of empty memory parameters (#11988)
### What problem does this PR solve? Fix: Fixed the issue of empty memory parameters ### Type of change - [x] Bug Fix (non-breaking change which fixes an issue)
This commit is contained in:
@ -3,7 +3,6 @@
|
||||
import message from '@/components/ui/message';
|
||||
import { useSetModalState } from '@/hooks/common-hooks';
|
||||
import { useHandleSearchChange } from '@/hooks/logic-hooks';
|
||||
import { useNavigatePage } from '@/hooks/logic-hooks/navigate-hooks';
|
||||
import memoryService, { updateMemoryById } from '@/services/memory-service';
|
||||
import { useMutation, useQuery, useQueryClient } from '@tanstack/react-query';
|
||||
import { useDebounce } from 'ahooks';
|
||||
@ -25,35 +24,21 @@ import {
|
||||
export const useCreateMemory = () => {
|
||||
const { t } = useTranslation();
|
||||
|
||||
const {
|
||||
data,
|
||||
isError,
|
||||
mutateAsync: createMemoryMutation,
|
||||
} = useMutation<CreateMemoryResponse, Error, ICreateMemoryProps>({
|
||||
mutationKey: ['createMemory'],
|
||||
mutationFn: async (props) => {
|
||||
const createMemory = useCallback(
|
||||
async (props: ICreateMemoryProps): Promise<CreateMemoryResponse> => {
|
||||
const { data: response } = await memoryService.createMemory(props);
|
||||
if (response.code !== 0) {
|
||||
throw new Error(response.message || 'Failed to create memory');
|
||||
}
|
||||
if (response.code === 0) {
|
||||
message.success(t('message.created'));
|
||||
}
|
||||
return response.data;
|
||||
},
|
||||
onSuccess: () => {
|
||||
message.success(t('message.created'));
|
||||
},
|
||||
onError: (error) => {
|
||||
message.error(t('message.error', { error: error.message }));
|
||||
},
|
||||
});
|
||||
|
||||
const createMemory = useCallback(
|
||||
(props: ICreateMemoryProps) => {
|
||||
return createMemoryMutation(props);
|
||||
},
|
||||
[createMemoryMutation],
|
||||
[t],
|
||||
);
|
||||
|
||||
return { data, isError, createMemory };
|
||||
return { createMemory };
|
||||
};
|
||||
|
||||
export const useFetchMemoryList = () => {
|
||||
@ -223,7 +208,6 @@ export const useUpdateMemory = () => {
|
||||
|
||||
export const useRenameMemory = () => {
|
||||
const [memory, setMemory] = useState<IMemory>({} as IMemory);
|
||||
const { navigateToMemory } = useNavigatePage();
|
||||
const {
|
||||
visible: openCreateModal,
|
||||
hideModal: hideChatRenameModal,
|
||||
@ -250,19 +234,11 @@ export const useRenameMemory = () => {
|
||||
|
||||
const onMemoryRenameOk = useCallback(
|
||||
async (data: ICreateMemoryProps, callBack?: () => void) => {
|
||||
let res;
|
||||
// let res;
|
||||
setLoading(true);
|
||||
if (memory?.id) {
|
||||
try {
|
||||
// const reponse = await memoryService.getMemoryDetail({
|
||||
// id: memory?.id,
|
||||
// });
|
||||
// const detail = reponse.data?.data;
|
||||
// console.log('detail-->', detail);
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
// const { id, created_by, update_time, ...memoryDataTemp } = detail;
|
||||
res = await updateMemory({
|
||||
await updateMemory({
|
||||
// ...memoryDataTemp,
|
||||
name: data.name,
|
||||
id: memory?.id,
|
||||
@ -271,7 +247,7 @@ export const useRenameMemory = () => {
|
||||
console.error('error', e);
|
||||
}
|
||||
} else {
|
||||
res = await createMemory(data);
|
||||
await createMemory(data);
|
||||
}
|
||||
// if (res && !memory?.id) {
|
||||
// navigateToMemory(res?.id)();
|
||||
@ -280,7 +256,7 @@ export const useRenameMemory = () => {
|
||||
setLoading(false);
|
||||
handleHideModal();
|
||||
},
|
||||
[memory, createMemory, handleHideModal, navigateToMemory, updateMemory],
|
||||
[memory, createMemory, handleHideModal, updateMemory],
|
||||
);
|
||||
return {
|
||||
memoryRenameLoading: loading,
|
||||
|
||||
Reference in New Issue
Block a user