fix: by obtaining the width and height of the pdf and passing it to b… (#151)

* fix: by obtaining the width and height of the pdf and passing it to boundingRect, the problem of inaccurate positioning of file highlighting is fixed

* feat: remove actualPositions from buildChunkHighlights
This commit is contained in:
balibabu
2024-03-26 14:51:34 +08:00
committed by GitHub
parent 0dd5b58d03
commit 75f7c6da2f
6 changed files with 167 additions and 129 deletions

View File

@ -2,7 +2,7 @@ import { IChunk, IKnowledgeFile } from '@/interfaces/database/knowledge';
import { IChangeParserConfigRequestBody } from '@/interfaces/request/document';
import { api_host } from '@/utils/api';
import { buildChunkHighlights } from '@/utils/documentUtils';
import { useCallback, useMemo } from 'react';
import { useCallback, useMemo, useState } from 'react';
import { IHighlight } from 'react-pdf-highlighter';
import { useDispatch, useSelector } from 'umi';
import { useGetKnowledgeSearchParams } from './routeHook';
@ -15,12 +15,23 @@ export const useGetDocumentUrl = (documentId: string) => {
return url;
};
export const useGetChunkHighlights = (selectedChunk: IChunk): IHighlight[] => {
const highlights: IHighlight[] = useMemo(() => {
return buildChunkHighlights(selectedChunk);
}, [selectedChunk]);
export const useGetChunkHighlights = (selectedChunk: IChunk) => {
const [size, setSize] = useState({ width: 849, height: 1200 });
return highlights;
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 useFetchDocumentList = () => {