refactor
This commit is contained in:
@@ -157,7 +157,7 @@ const DocumentViewerPanel: React.FC<DocumentViewerPanelProps> = ({
|
||||
);
|
||||
|
||||
const hasOcr = useMemo(() => {
|
||||
if (!document || typeof getDocumentAsset !== 'function') {
|
||||
if (!document || !getDocumentAsset) {
|
||||
return false;
|
||||
}
|
||||
return Boolean(getDocumentAsset(document, 'ocr-text'));
|
||||
@@ -191,7 +191,7 @@ const DocumentViewerPanel: React.FC<DocumentViewerPanelProps> = ({
|
||||
);
|
||||
|
||||
const loadOcrContent = useCallback(async ({ signal }: { signal?: AbortSignal } = {}) => {
|
||||
if (!document || !hasOcr || typeof getDocumentAsset !== 'function') {
|
||||
if (!document || !hasOcr || !getDocumentAsset) {
|
||||
return '';
|
||||
}
|
||||
|
||||
@@ -204,7 +204,7 @@ const DocumentViewerPanel: React.FC<DocumentViewerPanelProps> = ({
|
||||
const asset = getDocumentAsset(document, 'ocr-text');
|
||||
let url = updateUrl();
|
||||
|
||||
if (!url && document.id && asset?.id && typeof ensureAssetUrl === 'function') {
|
||||
if (!url && document.id && asset?.id && ensureAssetUrl) {
|
||||
await ensureAssetUrl(document.id, asset, { start: 1, limit: 1 });
|
||||
if (signal?.aborted) {
|
||||
throw new DOMException('Aborted', 'AbortError');
|
||||
@@ -274,7 +274,7 @@ const DocumentViewerPanel: React.FC<DocumentViewerPanelProps> = ({
|
||||
}, [previewEntry?.url, document?.id]);
|
||||
|
||||
useEffect(() => {
|
||||
if (typeof hydrateDocument === 'function' && document?.id) {
|
||||
if (hydrateDocument && document?.id) {
|
||||
hydrateDocument(document.id);
|
||||
}
|
||||
}, [hydrateDocument, document?.id]);
|
||||
@@ -318,7 +318,7 @@ const panelRef = useRef<HTMLDivElement | HTMLFormElement | HTMLElement | null>(n
|
||||
);
|
||||
|
||||
const breadcrumbs = useMemo(() => {
|
||||
if (!document || typeof resolveFolderPath !== 'function') {
|
||||
if (!document || !resolveFolderPath) {
|
||||
return [];
|
||||
}
|
||||
const folderSegments = resolveFolderPath(document.folder_id);
|
||||
@@ -397,7 +397,7 @@ const panelRef = useRef<HTMLDivElement | HTMLFormElement | HTMLElement | null>(n
|
||||
canZoom: Boolean(zoomDisplay),
|
||||
});
|
||||
|
||||
const collapseButton = isSidebarVariant && typeof onCollapsePanel === 'function'
|
||||
const collapseButton = isSidebarVariant && onCollapsePanel
|
||||
? (
|
||||
<button
|
||||
type="button"
|
||||
@@ -411,7 +411,7 @@ const panelRef = useRef<HTMLDivElement | HTMLFormElement | HTMLElement | null>(n
|
||||
)
|
||||
: null;
|
||||
|
||||
const maximizeButton = isSidebarVariant && typeof onMaximizePanel === 'function'
|
||||
const maximizeButton = isSidebarVariant && onMaximizePanel
|
||||
? (
|
||||
<button
|
||||
type="button"
|
||||
@@ -587,9 +587,7 @@ export const createDocumentViewerSurface = ({
|
||||
return null;
|
||||
}
|
||||
|
||||
const sidebarToggle = typeof renderSidebarToggle === 'function'
|
||||
? renderSidebarToggle()
|
||||
: null;
|
||||
const sidebarToggle = renderSidebarToggle ? renderSidebarToggle() : null;
|
||||
|
||||
return {
|
||||
key: 'preview',
|
||||
|
||||
@@ -57,16 +57,6 @@ export const useViewerLayoutMode = (
|
||||
|
||||
measure();
|
||||
|
||||
if (typeof ResizeObserver === 'undefined') {
|
||||
window.addEventListener('resize', measure);
|
||||
return () => {
|
||||
if (frame) {
|
||||
cancelAnimationFrame(frame);
|
||||
}
|
||||
window.removeEventListener('resize', measure);
|
||||
};
|
||||
}
|
||||
|
||||
const observer = new ResizeObserver((entries) => {
|
||||
if (!entries.length) {
|
||||
return;
|
||||
|
||||
Reference in New Issue
Block a user