Browse Source

feat: The same query conditions on the search page should not request the interface every time the mind map drawer is opened. #2759 (#2760)

### What problem does this PR solve?

feat: The same query conditions on the search page should not request
the interface every time the mind map drawer is opened. #2759

### Type of change

- [ ] Bug Fix (non-breaking change which fixes an issue)
- [x] New Feature (non-breaking change which adds functionality)
- [ ] Documentation Update
- [ ] Refactoring
- [ ] Performance Improvement
- [ ] Other (please describe):
tags/v0.13.0
balibabu 1 year ago
parent
commit
511d272d0d
No account linked to committer's email address
1 changed files with 10 additions and 2 deletions
  1. 10
    2
      web/src/pages/search/hooks.ts

+ 10
- 2
web/src/pages/search/hooks.ts View File

} from '@/hooks/logic-hooks'; } from '@/hooks/logic-hooks';
import { IAnswer } from '@/interfaces/database/chat'; import { IAnswer } from '@/interfaces/database/chat';
import api from '@/utils/api'; import api from '@/utils/api';
import { get, isEmpty, trim } from 'lodash';
import { get, isEmpty, isEqual, trim } from 'lodash';
import { import {
ChangeEventHandler, ChangeEventHandler,
useCallback, useCallback,


export const useShowMindMapDrawer = (kbIds: string[], question: string) => { export const useShowMindMapDrawer = (kbIds: string[], question: string) => {
const { visible, showModal, hideModal } = useSetModalState(); const { visible, showModal, hideModal } = useSetModalState();
const ref = useRef<any>();


const { const {
fetchMindMap, fetchMindMap,
} = useFetchMindMap(); } = useFetchMindMap();


const handleShowModal = useCallback(() => { const handleShowModal = useCallback(() => {
fetchMindMap({ question: trim(question), kb_ids: kbIds });
const searchParams = { question: trim(question), kb_ids: kbIds };
if (
!isEmpty(searchParams.question) &&
!isEqual(searchParams, ref.current)
) {
ref.current = searchParams;
fetchMindMap(searchParams);
}
showModal(); showModal();
}, [fetchMindMap, showModal, question, kbIds]); }, [fetchMindMap, showModal, question, kbIds]);



Loading…
Cancel
Save