mirror of
https://github.com/infiniflow/ragflow.git
synced 2026-02-05 18:15:06 +08:00
### What problem does this PR solve? Fix: Optimize list display and rename functionality #3221 - Updated the homepage search list display style and added rename functionality - Used the RenameDialog component for rename searches - Optimized list height calculation - Updated the style and layout of related pages - fix issue #9779 ### Type of change - [x] Bug Fix (non-breaking change which fixes an issue)
This commit is contained in:
@ -1,6 +1,8 @@
|
||||
// src/pages/next-searches/hooks.ts
|
||||
|
||||
import message from '@/components/ui/message';
|
||||
import { useSetModalState } from '@/hooks/common-hooks';
|
||||
import { useNavigatePage } from '@/hooks/logic-hooks/navigate-hooks';
|
||||
import searchService from '@/services/search-service';
|
||||
import { useMutation, useQuery, useQueryClient } from '@tanstack/react-query';
|
||||
import { useCallback, useState } from 'react';
|
||||
@ -296,3 +298,72 @@ export const useUpdateSearch = () => {
|
||||
|
||||
return { data, isError, updateSearch };
|
||||
};
|
||||
|
||||
export const useRenameSearch = () => {
|
||||
const [search, setSearch] = useState<ISearchAppProps>({} as ISearchAppProps);
|
||||
const { navigateToSearch } = useNavigatePage();
|
||||
const {
|
||||
visible: openCreateModal,
|
||||
hideModal: hideChatRenameModal,
|
||||
showModal: showChatRenameModal,
|
||||
} = useSetModalState();
|
||||
const { updateSearch } = useUpdateSearch();
|
||||
const { createSearch } = useCreateSearch();
|
||||
const [loading, setLoading] = useState(false);
|
||||
|
||||
const handleShowChatRenameModal = useCallback(
|
||||
(record?: ISearchAppProps) => {
|
||||
if (record) {
|
||||
setSearch(record);
|
||||
}
|
||||
showChatRenameModal();
|
||||
},
|
||||
[showChatRenameModal],
|
||||
);
|
||||
|
||||
const handleHideModal = useCallback(() => {
|
||||
hideChatRenameModal();
|
||||
setSearch({} as ISearchAppProps);
|
||||
}, [hideChatRenameModal]);
|
||||
|
||||
const onSearchRenameOk = useCallback(
|
||||
async (name: string, callBack?: () => void) => {
|
||||
let res;
|
||||
setLoading(true);
|
||||
if (search?.id) {
|
||||
try {
|
||||
const reponse = await searchService.getSearchDetail({
|
||||
search_id: search?.id,
|
||||
});
|
||||
const detail = reponse.data?.data;
|
||||
console.log('detail-->', detail);
|
||||
const { id, created_by, update_time, ...searchDataTemp } = detail;
|
||||
res = await updateSearch({
|
||||
...searchDataTemp,
|
||||
name: name,
|
||||
search_id: search?.id,
|
||||
} as unknown as IUpdateSearchProps);
|
||||
} catch (e) {
|
||||
console.error('error', e);
|
||||
}
|
||||
} else {
|
||||
res = await createSearch({ name: name });
|
||||
}
|
||||
if (res && !search?.id) {
|
||||
navigateToSearch(res?.search_id)();
|
||||
}
|
||||
callBack?.();
|
||||
setLoading(false);
|
||||
handleHideModal();
|
||||
},
|
||||
[search, createSearch, handleHideModal, navigateToSearch, updateSearch],
|
||||
);
|
||||
return {
|
||||
searchRenameLoading: loading,
|
||||
initialSearchName: search?.name,
|
||||
onSearchRenameOk,
|
||||
openCreateModal,
|
||||
hideSearchRenameModal: handleHideModal,
|
||||
showSearchRenameModal: handleShowChatRenameModal,
|
||||
};
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user