mirror of
https://git.mirrors.martin98.com/https://github.com/infiniflow/ragflow.git
synced 2025-08-03 14:30:40 +08:00

### What problem does this PR solve? fix: Set the default value of Self RAG to false #1220 fix: Change all tool file names to kebab format ### Type of change - [x] Bug Fix (non-breaking change which fixes an issue)
78 lines
2.3 KiB
TypeScript
78 lines
2.3 KiB
TypeScript
import { useOneNamespaceEffectsLoading } from '@/hooks/store-hooks';
|
|
import { IChunk, IKnowledgeFile } from '@/interfaces/database/knowledge';
|
|
import { buildChunkHighlights } from '@/utils/document-util';
|
|
import { useCallback, useMemo, useState } from 'react';
|
|
import { IHighlight } from 'react-pdf-highlighter';
|
|
import { useSelector } from 'umi';
|
|
import { ChunkTextMode } from './constant';
|
|
|
|
export const useSelectDocumentInfo = () => {
|
|
const documentInfo: IKnowledgeFile = useSelector(
|
|
(state: any) => state.chunkModel.documentInfo,
|
|
);
|
|
return documentInfo;
|
|
};
|
|
|
|
export const useSelectChunkList = () => {
|
|
const chunkList: IChunk[] = useSelector(
|
|
(state: any) => state.chunkModel.data,
|
|
);
|
|
return chunkList;
|
|
};
|
|
|
|
export const useHandleChunkCardClick = () => {
|
|
const [selectedChunkId, setSelectedChunkId] = useState<string>('');
|
|
|
|
const handleChunkCardClick = useCallback((chunkId: string) => {
|
|
setSelectedChunkId(chunkId);
|
|
}, []);
|
|
|
|
return { handleChunkCardClick, selectedChunkId };
|
|
};
|
|
|
|
export const useGetSelectedChunk = (selectedChunkId: string) => {
|
|
const chunkList: IChunk[] = useSelectChunkList();
|
|
return (
|
|
chunkList.find((x) => x.chunk_id === selectedChunkId) ?? ({} as IChunk)
|
|
);
|
|
};
|
|
|
|
export const useGetChunkHighlights = (selectedChunkId: string) => {
|
|
const [size, setSize] = useState({ width: 849, height: 1200 });
|
|
const selectedChunk: IChunk = useGetSelectedChunk(selectedChunkId);
|
|
|
|
const highlights: IHighlight[] = useMemo(() => {
|
|
return buildChunkHighlights(selectedChunk, size);
|
|
}, [selectedChunk, size]);
|
|
|
|
const setWidthAndHeight = (width: number, height: number) => {
|
|
setSize((pre) => {
|
|
if (pre.height !== height || pre.width !== width) {
|
|
return { height, width };
|
|
}
|
|
return pre;
|
|
});
|
|
};
|
|
|
|
return { highlights, setWidthAndHeight };
|
|
};
|
|
|
|
export const useSelectChunkListLoading = () => {
|
|
return useOneNamespaceEffectsLoading('chunkModel', [
|
|
'create_hunk',
|
|
'chunk_list',
|
|
'switch_chunk',
|
|
]);
|
|
};
|
|
|
|
// Switch chunk text to be fully displayed or ellipse
|
|
export const useChangeChunkTextMode = () => {
|
|
const [textMode, setTextMode] = useState<ChunkTextMode>(ChunkTextMode.Full);
|
|
|
|
const changeChunkTextMode = useCallback((mode: ChunkTextMode) => {
|
|
setTextMode(mode);
|
|
}, []);
|
|
|
|
return { textMode, changeChunkTextMode };
|
|
};
|