Compare commits
8
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
9db77ff159 | ||
|
|
80238bb7a1 | ||
|
|
dcbd46531e | ||
|
|
0864b39336 | ||
|
|
2a0c96bb4c | ||
|
|
c53213a357 | ||
|
|
dc633783e0 | ||
|
|
e33ab71fac |
Generated
+10
@@ -8,6 +8,7 @@
|
||||
"name": "papercrate-frontend",
|
||||
"version": "0.1.0",
|
||||
"dependencies": {
|
||||
"@fontsource/inter": "^5.2.8",
|
||||
"@tabler/icons-react": "3.11.0",
|
||||
"axios": "1.7.7",
|
||||
"react": "18.3.1",
|
||||
@@ -1852,6 +1853,15 @@
|
||||
"node": ">=10.0.0"
|
||||
}
|
||||
},
|
||||
"node_modules/@fontsource/inter": {
|
||||
"version": "5.2.8",
|
||||
"resolved": "https://registry.npmjs.org/@fontsource/inter/-/inter-5.2.8.tgz",
|
||||
"integrity": "sha512-P6r5WnJoKiNVV+zvW2xM13gNdFhAEpQ9dQJHt3naLvfg+LkF2ldgSLiF4T41lf1SQCM9QmkqPTn4TH568IRagg==",
|
||||
"license": "OFL-1.1",
|
||||
"funding": {
|
||||
"url": "https://github.com/sponsors/ayuhito"
|
||||
}
|
||||
},
|
||||
"node_modules/@jridgewell/gen-mapping": {
|
||||
"version": "0.3.13",
|
||||
"resolved": "https://registry.npmjs.org/@jridgewell/gen-mapping/-/gen-mapping-0.3.13.tgz",
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
"lint": "echo \"No linting configured\""
|
||||
},
|
||||
"dependencies": {
|
||||
"@fontsource/inter": "^5.2.8",
|
||||
"@tabler/icons-react": "3.11.0",
|
||||
"axios": "1.7.7",
|
||||
"react": "18.3.1",
|
||||
@@ -19,6 +20,7 @@
|
||||
"@babel/core": "7.26.0",
|
||||
"@babel/preset-env": "7.26.0",
|
||||
"@babel/preset-react": "7.26.3",
|
||||
"@svgr/webpack": "8.1.0",
|
||||
"babel-loader": "9.2.1",
|
||||
"css-loader": "7.1.2",
|
||||
"dotenv": "16.4.5",
|
||||
@@ -26,7 +28,6 @@
|
||||
"style-loader": "4.0.0",
|
||||
"webpack": "5.95.0",
|
||||
"webpack-cli": "5.1.4",
|
||||
"webpack-dev-server": "5.1.0",
|
||||
"@svgr/webpack": "8.1.0"
|
||||
"webpack-dev-server": "5.1.0"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -118,7 +118,7 @@ function CorrespondentsPanel({
|
||||
}, []);
|
||||
|
||||
return (
|
||||
<section className="correspondents-panel column">
|
||||
<section className="correspondents-panel">
|
||||
<div className="column-header">
|
||||
<div className="column-header__titles">
|
||||
<h2>Correspondents</h2>
|
||||
|
||||
@@ -1,6 +1,15 @@
|
||||
import React, { useCallback, useEffect, useMemo, useState } from 'react';
|
||||
import React, { useCallback, useEffect, useMemo, useRef, useState } from 'react';
|
||||
import { createPortal } from 'react-dom';
|
||||
import { DownloadIcon, EditIcon, ArrowLeftIcon, ArrowRightIcon } from '../ui/icons';
|
||||
import {
|
||||
DownloadIcon,
|
||||
EditIcon,
|
||||
ArrowLeftIcon,
|
||||
ArrowRightIcon,
|
||||
ChevronsRightIcon,
|
||||
AnalyzeIcon,
|
||||
WindowMaximizeIcon,
|
||||
TextScanIcon,
|
||||
} from '../ui/icons';
|
||||
import { getTagColorStyle } from '../utils/colors';
|
||||
import { formatFileSize } from '../utils/format';
|
||||
import { resolveDocumentAssetUrl, createAssetView } from '../asset_manager';
|
||||
@@ -208,6 +217,7 @@ const PreviewStack = ({
|
||||
emptyMessage = 'Preview unavailable',
|
||||
onItemActivate,
|
||||
onOpenPreview,
|
||||
onZoomPreview,
|
||||
activeItemId = null,
|
||||
}) => {
|
||||
if (!items.length) {
|
||||
@@ -240,7 +250,11 @@ const PreviewStack = ({
|
||||
zIndex: preparedItems.length - index,
|
||||
transform,
|
||||
}}
|
||||
aria-hidden={hasMultiple && !onItemActivate && !onOpenPreview ? 'true' : undefined}
|
||||
aria-hidden={
|
||||
hasMultiple && !onItemActivate && !onOpenPreview && !onZoomPreview
|
||||
? 'true'
|
||||
: undefined
|
||||
}
|
||||
>
|
||||
<img
|
||||
src={entry.url}
|
||||
@@ -248,22 +262,34 @@ const PreviewStack = ({
|
||||
className="preview-stack__image"
|
||||
onClick={(event) => {
|
||||
event.stopPropagation();
|
||||
if (isFront && onOpenPreview) {
|
||||
if (isFront) {
|
||||
if (onZoomPreview) {
|
||||
onZoomPreview(entry);
|
||||
} else if (onOpenPreview) {
|
||||
onOpenPreview(entry.id);
|
||||
} else if (onItemActivate) {
|
||||
onItemActivate(entry.id);
|
||||
}
|
||||
} else if (onItemActivate) {
|
||||
onItemActivate(entry.id);
|
||||
}
|
||||
}}
|
||||
onKeyDown={(event) => {
|
||||
if (!onItemActivate && !onOpenPreview) return;
|
||||
if (!onItemActivate && !onOpenPreview && !onZoomPreview) return;
|
||||
if (event.key === 'Enter' || event.key === ' ') {
|
||||
event.preventDefault();
|
||||
event.stopPropagation();
|
||||
if (isFront && onOpenPreview) {
|
||||
if (isFront) {
|
||||
if (onZoomPreview) {
|
||||
onZoomPreview(entry);
|
||||
} else if (onOpenPreview) {
|
||||
onOpenPreview(entry.id);
|
||||
} else {
|
||||
onItemActivate?.(entry.id);
|
||||
}
|
||||
} else {
|
||||
onItemActivate?.(entry.id);
|
||||
}
|
||||
}
|
||||
}}
|
||||
/>
|
||||
@@ -297,9 +323,24 @@ const DetailPanel = ({
|
||||
onCorrespondentAdd,
|
||||
onCorrespondentRemove,
|
||||
resolveApiPath,
|
||||
onClose = () => {},
|
||||
}) => {
|
||||
const selectedCount = selectedDocuments.length;
|
||||
const singleDoc = selectedCount === 1 ? selectedDocuments[0] : null;
|
||||
const singleDocId = singleDoc?.id || null;
|
||||
const selectionKey = useMemo(
|
||||
() => selectedDocuments.map((doc) => doc?.id ?? '').join('|'),
|
||||
[selectedDocuments],
|
||||
);
|
||||
|
||||
const singleDownloadHref = useMemo(() => {
|
||||
if (!singleDoc) return null;
|
||||
const downloadPath = singleDoc.current_version?.download_path;
|
||||
if (!downloadPath || !resolveApiPath) {
|
||||
return null;
|
||||
}
|
||||
return resolveApiPath(downloadPath);
|
||||
}, [singleDoc, resolveApiPath]);
|
||||
|
||||
const [titleEditDocId, setTitleEditDocId] = useState(null);
|
||||
const [titleDraft, setTitleDraft] = useState('');
|
||||
@@ -309,6 +350,36 @@ const DetailPanel = ({
|
||||
const [ocrUrl, setOcrUrl] = useState(null);
|
||||
const [ocrLoading, setOcrLoading] = useState(false);
|
||||
const [ocrError, setOcrError] = useState(null);
|
||||
const [zoomedPreview, setZoomedPreview] = useState(null);
|
||||
const [zoomNative, setZoomNative] = useState(false);
|
||||
const [zoomPan, setZoomPan] = useState({ x: 0, y: 0 });
|
||||
const [isZoomDragging, setIsZoomDragging] = useState(false);
|
||||
const zoomStageRef = useRef(null);
|
||||
const zoomImageMetricsRef = useRef({ naturalWidth: 0, naturalHeight: 0 });
|
||||
const zoomDragRef = useRef(null);
|
||||
const zoomSkipClickRef = useRef(false);
|
||||
|
||||
const clampPan = useCallback(
|
||||
(x, y) => {
|
||||
const stage = zoomStageRef.current;
|
||||
const { naturalWidth, naturalHeight } = zoomImageMetricsRef.current;
|
||||
if (!stage || !naturalWidth || !naturalHeight) {
|
||||
return { x: 0, y: 0 };
|
||||
}
|
||||
const stageRect = stage.getBoundingClientRect();
|
||||
if (stageRect.width <= 0 || stageRect.height <= 0) {
|
||||
return { x: 0, y: 0 };
|
||||
}
|
||||
const imageWidth = zoomNative ? naturalWidth : Math.min(naturalWidth, stageRect.width);
|
||||
const imageHeight = zoomNative ? naturalHeight : Math.min(naturalHeight, stageRect.height);
|
||||
const limitX = Math.max(0, (imageWidth - stageRect.width) / 2);
|
||||
const limitY = Math.max(0, (imageHeight - stageRect.height) / 2);
|
||||
const clampedX = Math.min(Math.max(x, -limitX), limitX);
|
||||
const clampedY = Math.min(Math.max(y, -limitY), limitY);
|
||||
return { x: clampedX, y: clampedY };
|
||||
},
|
||||
[zoomNative],
|
||||
);
|
||||
|
||||
useEffect(() => {
|
||||
if (!singleDoc) {
|
||||
@@ -338,6 +409,55 @@ const DetailPanel = ({
|
||||
setOcrUrl(null);
|
||||
}, [singleDoc?.id]);
|
||||
|
||||
useEffect(() => {
|
||||
setZoomedPreview(null);
|
||||
}, [selectionKey]);
|
||||
|
||||
useEffect(() => {
|
||||
if (!zoomedPreview) {
|
||||
setZoomNative(false);
|
||||
setZoomPan({ x: 0, y: 0 });
|
||||
setIsZoomDragging(false);
|
||||
zoomDragRef.current = null;
|
||||
zoomSkipClickRef.current = false;
|
||||
}
|
||||
}, [zoomedPreview]);
|
||||
|
||||
useEffect(() => {
|
||||
zoomSkipClickRef.current = false;
|
||||
if (zoomNative) {
|
||||
setZoomPan((current) => {
|
||||
const clamped = clampPan(current.x, current.y);
|
||||
if (clamped.x === current.x && clamped.y === current.y) {
|
||||
return current;
|
||||
}
|
||||
return clamped;
|
||||
});
|
||||
} else {
|
||||
setZoomPan({ x: 0, y: 0 });
|
||||
setIsZoomDragging(false);
|
||||
zoomDragRef.current = null;
|
||||
}
|
||||
}, [zoomNative, clampPan]);
|
||||
|
||||
useEffect(() => {
|
||||
if (!zoomNative) {
|
||||
return undefined;
|
||||
}
|
||||
const handleResize = () => {
|
||||
setZoomPan((current) => {
|
||||
const clamped = clampPan(current.x, current.y);
|
||||
if (clamped.x === current.x && clamped.y === current.y) {
|
||||
return current;
|
||||
}
|
||||
return clamped;
|
||||
});
|
||||
};
|
||||
window.addEventListener('resize', handleResize);
|
||||
handleResize();
|
||||
return () => window.removeEventListener('resize', handleResize);
|
||||
}, [zoomNative, clampPan]);
|
||||
|
||||
const startTitleEdit = useCallback(() => {
|
||||
if (!singleDoc) return;
|
||||
setTitleEditDocId(singleDoc.id);
|
||||
@@ -500,6 +620,7 @@ const DetailPanel = ({
|
||||
}, [selectedDocuments]);
|
||||
|
||||
const stackTopDocument = stackDocuments[0] || null;
|
||||
const stackTopDocId = stackTopDocument?.id || null;
|
||||
const stackPreviewNavigator = useAssetNavigator({
|
||||
document: stackTopDocument,
|
||||
assetType: 'preview',
|
||||
@@ -699,15 +820,380 @@ const DetailPanel = ({
|
||||
[bulkCorrespondents, onBulkCorrespondentRemove, onCorrespondentRemove, selectedDocuments],
|
||||
);
|
||||
|
||||
const openZoomPreview = useCallback((config) => {
|
||||
if (!config) return;
|
||||
setZoomedPreview({
|
||||
mode: config.mode,
|
||||
docId: config.docId ?? null,
|
||||
});
|
||||
setZoomNative(false);
|
||||
setZoomPan({ x: 0, y: 0 });
|
||||
setIsZoomDragging(false);
|
||||
zoomDragRef.current = null;
|
||||
zoomSkipClickRef.current = false;
|
||||
zoomImageMetricsRef.current = { naturalWidth: 0, naturalHeight: 0 };
|
||||
}, []);
|
||||
|
||||
const closeZoomPreview = useCallback(() => {
|
||||
setZoomedPreview(null);
|
||||
setZoomNative(false);
|
||||
setZoomPan({ x: 0, y: 0 });
|
||||
setIsZoomDragging(false);
|
||||
zoomDragRef.current = null;
|
||||
zoomSkipClickRef.current = false;
|
||||
zoomImageMetricsRef.current = { naturalWidth: 0, naturalHeight: 0 };
|
||||
}, []);
|
||||
|
||||
const handleSingleZoom = useCallback(
|
||||
(entry) => {
|
||||
if (!singleHasPreview) return;
|
||||
const targetId = entry?.id ?? singleDocId;
|
||||
if (!targetId) return;
|
||||
openZoomPreview({ mode: 'single', docId: targetId });
|
||||
},
|
||||
[openZoomPreview, singleHasPreview, singleDocId],
|
||||
);
|
||||
|
||||
const handleStackZoom = useCallback(
|
||||
(entry) => {
|
||||
if (!stackTopDocId || entry?.id !== stackTopDocId) return;
|
||||
if (!topHasPreview) return;
|
||||
openZoomPreview({ mode: 'stack', docId: stackTopDocId });
|
||||
},
|
||||
[openZoomPreview, stackTopDocId, topHasPreview],
|
||||
);
|
||||
|
||||
const handleZoomImageLoad = useCallback(
|
||||
(event) => {
|
||||
zoomImageMetricsRef.current = {
|
||||
naturalWidth: event.currentTarget.naturalWidth || 0,
|
||||
naturalHeight: event.currentTarget.naturalHeight || 0,
|
||||
};
|
||||
setZoomPan((current) => {
|
||||
const clamped = clampPan(current.x, current.y);
|
||||
return { x: clamped.x, y: clamped.y };
|
||||
});
|
||||
},
|
||||
[clampPan],
|
||||
);
|
||||
|
||||
const handleZoomImageClick = useCallback(
|
||||
(event) => {
|
||||
event.stopPropagation();
|
||||
if (zoomSkipClickRef.current) {
|
||||
zoomSkipClickRef.current = false;
|
||||
return;
|
||||
}
|
||||
|
||||
if (!zoomNative) {
|
||||
const stage = zoomStageRef.current;
|
||||
const { naturalWidth, naturalHeight } = zoomImageMetricsRef.current;
|
||||
if (stage && naturalWidth && naturalHeight) {
|
||||
const stageRect = stage.getBoundingClientRect();
|
||||
const imageRect = event.currentTarget.getBoundingClientRect();
|
||||
const clickX = event.clientX - imageRect.left;
|
||||
const clickY = event.clientY - imageRect.top;
|
||||
const ratioX = imageRect.width ? clickX / imageRect.width : 0.5;
|
||||
const ratioY = imageRect.height ? clickY / imageRect.height : 0.5;
|
||||
const focusX = naturalWidth * ratioX;
|
||||
const focusY = naturalHeight * ratioY;
|
||||
const halfWidth = naturalWidth / 2;
|
||||
const halfHeight = naturalHeight / 2;
|
||||
const limitX = Math.max(0, (naturalWidth - stageRect.width) / 2);
|
||||
const limitY = Math.max(0, (naturalHeight - stageRect.height) / 2);
|
||||
let targetPanX = -(focusX - halfWidth);
|
||||
let targetPanY = -(focusY - halfHeight);
|
||||
targetPanX = Math.min(Math.max(targetPanX, -limitX), limitX);
|
||||
targetPanY = Math.min(Math.max(targetPanY, -limitY), limitY);
|
||||
setZoomPan({ x: targetPanX, y: targetPanY });
|
||||
} else {
|
||||
setZoomPan({ x: 0, y: 0 });
|
||||
}
|
||||
setZoomNative(true);
|
||||
} else {
|
||||
setZoomNative(false);
|
||||
}
|
||||
},
|
||||
[zoomNative],
|
||||
);
|
||||
|
||||
const handleZoomImagePointerDown = useCallback(
|
||||
(event) => {
|
||||
if (!zoomNative || event.button !== 0) {
|
||||
return;
|
||||
}
|
||||
event.preventDefault();
|
||||
zoomSkipClickRef.current = false;
|
||||
zoomDragRef.current = {
|
||||
pointerId: event.pointerId,
|
||||
originX: zoomPan.x,
|
||||
originY: zoomPan.y,
|
||||
startX: event.clientX,
|
||||
startY: event.clientY,
|
||||
moved: false,
|
||||
};
|
||||
event.currentTarget.setPointerCapture(event.pointerId);
|
||||
},
|
||||
[zoomNative, zoomPan],
|
||||
);
|
||||
|
||||
const handleZoomImagePointerMove = useCallback(
|
||||
(event) => {
|
||||
const drag = zoomDragRef.current;
|
||||
if (!drag || drag.pointerId !== event.pointerId) {
|
||||
return;
|
||||
}
|
||||
const deltaX = event.clientX - drag.startX;
|
||||
const deltaY = event.clientY - drag.startY;
|
||||
if (!drag.moved && (Math.abs(deltaX) > 2 || Math.abs(deltaY) > 2)) {
|
||||
drag.moved = true;
|
||||
setIsZoomDragging(true);
|
||||
}
|
||||
if (drag.moved) {
|
||||
const clamped = clampPan(drag.originX + deltaX, drag.originY + deltaY);
|
||||
setZoomPan((current) =>
|
||||
current.x === clamped.x && current.y === clamped.y ? current : clamped,
|
||||
);
|
||||
}
|
||||
},
|
||||
[clampPan],
|
||||
);
|
||||
|
||||
const endZoomDrag = useCallback(() => {
|
||||
zoomDragRef.current = null;
|
||||
setIsZoomDragging(false);
|
||||
}, []);
|
||||
|
||||
const handleZoomImagePointerUp = useCallback(
|
||||
(event) => {
|
||||
const drag = zoomDragRef.current;
|
||||
if (!drag || drag.pointerId !== event.pointerId) {
|
||||
return;
|
||||
}
|
||||
event.currentTarget.releasePointerCapture(event.pointerId);
|
||||
zoomSkipClickRef.current = Boolean(drag.moved);
|
||||
endZoomDrag();
|
||||
},
|
||||
[endZoomDrag],
|
||||
);
|
||||
|
||||
const handleZoomImagePointerCancel = useCallback(
|
||||
(event) => {
|
||||
const drag = zoomDragRef.current;
|
||||
if (!drag || drag.pointerId !== event.pointerId) {
|
||||
return;
|
||||
}
|
||||
event.currentTarget.releasePointerCapture(event.pointerId);
|
||||
zoomSkipClickRef.current = true;
|
||||
endZoomDrag();
|
||||
},
|
||||
[endZoomDrag],
|
||||
);
|
||||
|
||||
const zoomDisplay = useMemo(() => {
|
||||
if (!zoomedPreview) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (
|
||||
zoomedPreview.mode === 'single' &&
|
||||
singleDocId &&
|
||||
singleDoc &&
|
||||
singleHasPreview &&
|
||||
zoomedPreview.docId === singleDocId
|
||||
) {
|
||||
return {
|
||||
url: singlePreviewNavigator.currentUrl,
|
||||
alt: singleDoc.title || singleDoc.original_name || 'Document preview',
|
||||
canGoPrev:
|
||||
singleEffectiveCardinality > 1 && Boolean(singlePreviewNavigator.canGoPrev),
|
||||
canGoNext:
|
||||
singleEffectiveCardinality > 1 && Boolean(singlePreviewNavigator.canGoNext),
|
||||
goPrev: singlePreviewNavigator.goPrev,
|
||||
goNext: singlePreviewNavigator.goNext,
|
||||
};
|
||||
}
|
||||
|
||||
if (
|
||||
zoomedPreview.mode === 'stack' &&
|
||||
stackTopDocId &&
|
||||
stackTopDocument &&
|
||||
zoomedPreview.docId === stackTopDocId &&
|
||||
topHasPreview
|
||||
) {
|
||||
return {
|
||||
url: stackPreviewNavigator.currentUrl,
|
||||
alt: stackTopDocument.title || stackTopDocument.original_name || 'Document preview',
|
||||
canGoPrev:
|
||||
topEffectiveCardinality > 1 && Boolean(stackPreviewNavigator.canGoPrev),
|
||||
canGoNext:
|
||||
topEffectiveCardinality > 1 && Boolean(stackPreviewNavigator.canGoNext),
|
||||
goPrev: stackPreviewNavigator.goPrev,
|
||||
goNext: stackPreviewNavigator.goNext,
|
||||
};
|
||||
}
|
||||
|
||||
return null;
|
||||
}, [
|
||||
zoomedPreview,
|
||||
singleDoc,
|
||||
singleDocId,
|
||||
singleHasPreview,
|
||||
singlePreviewNavigator.currentUrl,
|
||||
singlePreviewNavigator.canGoPrev,
|
||||
singlePreviewNavigator.canGoNext,
|
||||
singlePreviewNavigator.goPrev,
|
||||
singlePreviewNavigator.goNext,
|
||||
singleEffectiveCardinality,
|
||||
stackTopDocument,
|
||||
stackTopDocId,
|
||||
topHasPreview,
|
||||
stackPreviewNavigator.currentUrl,
|
||||
stackPreviewNavigator.canGoPrev,
|
||||
stackPreviewNavigator.canGoNext,
|
||||
stackPreviewNavigator.goPrev,
|
||||
stackPreviewNavigator.goNext,
|
||||
topEffectiveCardinality,
|
||||
]);
|
||||
|
||||
useEffect(() => {
|
||||
if (zoomedPreview && !zoomDisplay) {
|
||||
setZoomedPreview(null);
|
||||
}
|
||||
}, [zoomedPreview, zoomDisplay]);
|
||||
|
||||
const zoomDisplayUrl = zoomDisplay?.url;
|
||||
|
||||
useEffect(() => {
|
||||
if (!zoomDisplayUrl) {
|
||||
return;
|
||||
}
|
||||
setZoomPan((current) => {
|
||||
const clamped = clampPan(current.x, current.y);
|
||||
if (clamped.x === current.x && clamped.y === current.y) {
|
||||
return current;
|
||||
}
|
||||
return clamped;
|
||||
});
|
||||
}, [zoomDisplayUrl, clampPan]);
|
||||
|
||||
useEffect(() => {
|
||||
if (!zoomedPreview) {
|
||||
return undefined;
|
||||
}
|
||||
const handleKeyDown = (event) => {
|
||||
if (event.key === 'Escape') {
|
||||
setZoomedPreview(null);
|
||||
return;
|
||||
}
|
||||
if (event.key === 'ArrowLeft') {
|
||||
event.preventDefault();
|
||||
event.stopPropagation();
|
||||
if (zoomDisplay?.canGoPrev) {
|
||||
zoomDisplay.goPrev?.();
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (event.key === 'ArrowRight') {
|
||||
event.preventDefault();
|
||||
event.stopPropagation();
|
||||
if (zoomDisplay?.canGoNext) {
|
||||
zoomDisplay.goNext?.();
|
||||
}
|
||||
}
|
||||
};
|
||||
window.addEventListener('keydown', handleKeyDown);
|
||||
return () => window.removeEventListener('keydown', handleKeyDown);
|
||||
}, [zoomedPreview, zoomDisplay]);
|
||||
|
||||
useEffect(() => {
|
||||
if (typeof ensureAssetUrl !== 'function') {
|
||||
return;
|
||||
}
|
||||
|
||||
const warmNavigator = (navigator) => {
|
||||
const { documentId, asset, ordinal, canGoPrev, canGoNext } = navigator;
|
||||
if (!documentId || !asset || !Number.isFinite(ordinal)) {
|
||||
return;
|
||||
}
|
||||
|
||||
const requests = [];
|
||||
if (canGoPrev) {
|
||||
const prevOrdinal = Math.max(1, ordinal - 1);
|
||||
requests.push(
|
||||
ensureAssetUrl(documentId, asset, {
|
||||
start: prevOrdinal,
|
||||
limit: 1,
|
||||
}),
|
||||
);
|
||||
}
|
||||
if (canGoNext) {
|
||||
const nextOrdinal = ordinal + 1;
|
||||
requests.push(
|
||||
ensureAssetUrl(documentId, asset, {
|
||||
start: nextOrdinal,
|
||||
limit: 1,
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
||||
requests.forEach((promise) => promise?.catch?.(() => {}));
|
||||
};
|
||||
|
||||
warmNavigator(singlePreviewNavigator);
|
||||
warmNavigator(stackPreviewNavigator);
|
||||
}, [
|
||||
ensureAssetUrl,
|
||||
singlePreviewNavigator.documentId,
|
||||
singlePreviewNavigator.asset,
|
||||
singlePreviewNavigator.ordinal,
|
||||
singlePreviewNavigator.canGoPrev,
|
||||
singlePreviewNavigator.canGoNext,
|
||||
stackPreviewNavigator.documentId,
|
||||
stackPreviewNavigator.asset,
|
||||
stackPreviewNavigator.ordinal,
|
||||
stackPreviewNavigator.canGoPrev,
|
||||
stackPreviewNavigator.canGoNext,
|
||||
]);
|
||||
|
||||
const zoomImageStyle = useMemo(() => {
|
||||
if (!zoomNative) {
|
||||
return {
|
||||
cursor: 'zoom-in',
|
||||
transform: 'none',
|
||||
maxWidth: '95vw',
|
||||
maxHeight: '95vh',
|
||||
};
|
||||
}
|
||||
const { naturalWidth, naturalHeight } = zoomImageMetricsRef.current;
|
||||
return {
|
||||
cursor: isZoomDragging ? 'grabbing' : 'grab',
|
||||
width: naturalWidth ? `${naturalWidth}px` : 'auto',
|
||||
height: naturalHeight ? `${naturalHeight}px` : 'auto',
|
||||
maxWidth: 'none',
|
||||
maxHeight: 'none',
|
||||
transform: `translate3d(${zoomPan.x}px, ${zoomPan.y}px, 0)`,
|
||||
};
|
||||
}, [zoomNative, zoomPan.x, zoomPan.y, isZoomDragging]);
|
||||
|
||||
const zoomStageClassName = useMemo(
|
||||
() =>
|
||||
[
|
||||
'preview-zoom__stage',
|
||||
zoomNative ? 'preview-zoom__stage--native' : '',
|
||||
isZoomDragging ? 'preview-zoom__stage--dragging' : '',
|
||||
]
|
||||
.filter(Boolean)
|
||||
.join(' '),
|
||||
[zoomNative, isZoomDragging],
|
||||
);
|
||||
|
||||
const renderSingle = () => {
|
||||
if (!singleDoc) {
|
||||
return <p className="meta">Select a document to view metadata, tags and actions.</p>;
|
||||
}
|
||||
|
||||
const displayName = singleDoc.title || singleDoc.original_name;
|
||||
const downloadHref = singleDoc.current_version?.download_path
|
||||
? resolveApiPath?.(singleDoc.current_version.download_path)
|
||||
: null;
|
||||
const isEditingTitle = titleEditDocId === singleDoc.id;
|
||||
const sizeBytes = Number(singleDoc.current_version?.size_bytes) || 0;
|
||||
const sizeLabel = sizeBytes > 0 ? formatFileSize(sizeBytes) : '—';
|
||||
@@ -743,6 +1229,7 @@ const DetailPanel = ({
|
||||
emptyMessage="Preview loading…"
|
||||
onItemActivate={handlePreviewActivate}
|
||||
onOpenPreview={onOpenPreview}
|
||||
onZoomPreview={handleSingleZoom}
|
||||
activeItemId={activePreviewId}
|
||||
/>
|
||||
{hasPreviewImage && (effectiveCardinality > 1 || canGoPrev || canGoNext) ? (
|
||||
@@ -857,44 +1344,6 @@ const DetailPanel = ({
|
||||
{singleDoc.original_name}
|
||||
</div>
|
||||
</div>
|
||||
<div className="detail-actions">
|
||||
<a
|
||||
className="button-link with-icon"
|
||||
href={downloadHref || '#'}
|
||||
target="_blank"
|
||||
rel="noopener noreferrer"
|
||||
aria-disabled={!downloadHref}
|
||||
onClick={(event) => {
|
||||
if (!downloadHref) {
|
||||
event.preventDefault();
|
||||
}
|
||||
}}
|
||||
>
|
||||
<DownloadIcon className="icon-inline" />
|
||||
<span>Download</span>
|
||||
</a>
|
||||
<button
|
||||
type="button"
|
||||
className="secondary"
|
||||
onClick={() => onOpenPreview(singleDoc.id)}
|
||||
>
|
||||
Open preview
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
className="secondary"
|
||||
onClick={() => onRegenerateThumbnails(singleDoc.id)}
|
||||
>
|
||||
Re-run analysis
|
||||
</button>
|
||||
</div>
|
||||
{hasOcrAsset ? (
|
||||
<div className="detail-ocr-trigger">
|
||||
<button type="button" className="secondary" onClick={openOcrModal}>
|
||||
View OCR text
|
||||
</button>
|
||||
</div>
|
||||
) : null}
|
||||
<TagSection
|
||||
title="Tags"
|
||||
tags={tagsForDoc.map((tag) => ({
|
||||
@@ -1002,6 +1451,7 @@ const DetailPanel = ({
|
||||
emptyMessage="No previews available."
|
||||
onItemActivate={handlePreviewActivate}
|
||||
onOpenPreview={onOpenPreview}
|
||||
onZoomPreview={handleStackZoom}
|
||||
activeItemId={activePreviewId}
|
||||
/>
|
||||
{topDocIdLocal && topHasPreview && (topCardinalityLocal > 1 || topCanGoPrev || topCanGoNext) ? (
|
||||
@@ -1074,23 +1524,165 @@ const DetailPanel = ({
|
||||
showCount
|
||||
className="bulk-correspondents"
|
||||
/>
|
||||
<button
|
||||
type="button"
|
||||
className="secondary"
|
||||
onClick={() => onBulkReanalyze?.()}
|
||||
>
|
||||
Re-analyze selection
|
||||
</button>
|
||||
</>
|
||||
);
|
||||
};
|
||||
|
||||
const isBulkSelection = selectedCount > 1;
|
||||
const showOcrAction = Boolean(singleDoc && hasOcrAsset);
|
||||
|
||||
return (
|
||||
<aside className="detail-panel column">
|
||||
<div className="column-body scrollable">
|
||||
<>
|
||||
<aside className="detail-panel panel">
|
||||
<div className="panel-header">
|
||||
<div className="panel-actions">
|
||||
<button
|
||||
type="button"
|
||||
className="icon-button ghost"
|
||||
onClick={onClose}
|
||||
aria-label="Close detail panel"
|
||||
title="Close detail panel"
|
||||
>
|
||||
<ChevronsRightIcon />
|
||||
</button>
|
||||
<div className="spacer" />
|
||||
{isBulkSelection && onBulkReanalyze ? (
|
||||
<button
|
||||
type="button"
|
||||
className="icon-button ghost"
|
||||
onClick={(event) => {
|
||||
event.stopPropagation();
|
||||
onBulkReanalyze();
|
||||
}}
|
||||
aria-label="Re-run analysis for selection"
|
||||
title="Re-run analysis for selection"
|
||||
>
|
||||
<AnalyzeIcon />
|
||||
</button>
|
||||
) : null}
|
||||
{singleDoc && singleDownloadHref ? (
|
||||
<a
|
||||
className="icon-button"
|
||||
href={singleDownloadHref}
|
||||
target="_blank"
|
||||
rel="noopener noreferrer"
|
||||
aria-label="Download document"
|
||||
title="Download document"
|
||||
onClick={(event) => event.stopPropagation()}
|
||||
>
|
||||
<DownloadIcon />
|
||||
</a>
|
||||
) : null}
|
||||
{singleDoc ? (
|
||||
<button
|
||||
type="button"
|
||||
className="icon-button ghost"
|
||||
onClick={(event) => {
|
||||
event.stopPropagation();
|
||||
onOpenPreview(singleDoc.id);
|
||||
}}
|
||||
aria-label="Open preview"
|
||||
title="Open preview"
|
||||
disabled={!singleHasPreview}
|
||||
>
|
||||
<WindowMaximizeIcon />
|
||||
</button>
|
||||
) : null}
|
||||
{showOcrAction ? (
|
||||
<button
|
||||
type="button"
|
||||
className="icon-button ghost"
|
||||
onClick={(event) => {
|
||||
event.stopPropagation();
|
||||
openOcrModal();
|
||||
}}
|
||||
aria-label="View OCR text"
|
||||
title="View OCR text"
|
||||
>
|
||||
<TextScanIcon />
|
||||
</button>
|
||||
) : null}
|
||||
{singleDoc ? (
|
||||
<button
|
||||
type="button"
|
||||
className="icon-button ghost"
|
||||
onClick={(event) => {
|
||||
event.stopPropagation();
|
||||
onRegenerateThumbnails(singleDoc.id);
|
||||
}}
|
||||
aria-label="Re-run analysis"
|
||||
title="Re-run analysis"
|
||||
>
|
||||
<AnalyzeIcon />
|
||||
</button>
|
||||
) : null}
|
||||
</div>
|
||||
</div>
|
||||
<div className="panel-body">
|
||||
{selectedCount <= 1 ? renderSingle() : renderBulk()}
|
||||
</div>
|
||||
</aside>
|
||||
{zoomDisplay?.url
|
||||
? createPortal(
|
||||
<div
|
||||
className="preview-zoom-backdrop"
|
||||
role="dialog"
|
||||
aria-modal="true"
|
||||
aria-label="Enlarged document preview"
|
||||
onClick={closeZoomPreview}
|
||||
>
|
||||
<div ref={zoomStageRef} className={zoomStageClassName}>
|
||||
<img
|
||||
src={zoomDisplay.url}
|
||||
alt={zoomDisplay.alt}
|
||||
className="preview-zoom__image"
|
||||
style={zoomImageStyle}
|
||||
onLoad={handleZoomImageLoad}
|
||||
onClick={handleZoomImageClick}
|
||||
onPointerDown={handleZoomImagePointerDown}
|
||||
onPointerMove={handleZoomImagePointerMove}
|
||||
onPointerUp={handleZoomImagePointerUp}
|
||||
onPointerCancel={handleZoomImagePointerCancel}
|
||||
draggable={false}
|
||||
/>
|
||||
{zoomDisplay.canGoPrev || zoomDisplay.canGoNext ? (
|
||||
<div className="preview-zoom__nav">
|
||||
<button
|
||||
type="button"
|
||||
className="preview-zoom__nav-button"
|
||||
onClick={(event) => {
|
||||
event.stopPropagation();
|
||||
if (zoomDisplay.canGoPrev) {
|
||||
zoomDisplay.goPrev?.();
|
||||
}
|
||||
}}
|
||||
aria-label="Previous preview"
|
||||
disabled={!zoomDisplay.canGoPrev}
|
||||
>
|
||||
<ArrowLeftIcon />
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
className="preview-zoom__nav-button"
|
||||
onClick={(event) => {
|
||||
event.stopPropagation();
|
||||
if (zoomDisplay.canGoNext) {
|
||||
zoomDisplay.goNext?.();
|
||||
}
|
||||
}}
|
||||
aria-label="Next preview"
|
||||
disabled={!zoomDisplay.canGoNext}
|
||||
>
|
||||
<ArrowRightIcon />
|
||||
</button>
|
||||
</div>
|
||||
) : null}
|
||||
</div>
|
||||
</div>,
|
||||
document.body,
|
||||
)
|
||||
: null}
|
||||
</>
|
||||
);
|
||||
};
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import React, { useCallback, useEffect, useMemo, useRef } from 'react';
|
||||
import { getAssetFromVersion, resolveDocumentAssetUrl, createAssetView } from '../asset_manager';
|
||||
import { getTagColorStyle } from '../utils/colors';
|
||||
import { DownloadIcon, EditIcon, ViewListIcon, ViewGridIcon, FolderIcon } from '../ui/icons';
|
||||
import { DownloadIcon, EditIcon, ViewListIcon, ViewGridIcon, FolderIcon, TrashIcon } from '../ui/icons';
|
||||
|
||||
const TAG_MIME_TYPES = ['application/x-papercrate-tag', 'text/papercrate-tag'];
|
||||
const DEFAULT_GRID_ICON_SIZE = 96;
|
||||
@@ -263,16 +263,6 @@ const DocumentsTable = ({
|
||||
[isTagDragEvent, onDocumentTagDrop],
|
||||
);
|
||||
|
||||
const handleGridBackgroundClick = useCallback(
|
||||
(event) => {
|
||||
if (event.target !== event.currentTarget) {
|
||||
return;
|
||||
}
|
||||
onClearSelection?.();
|
||||
},
|
||||
[onClearSelection],
|
||||
);
|
||||
|
||||
const showDefaultEmptyState = !showingSearchResults && !subfolders.length && rows.length === 0;
|
||||
const showListSearchEmptyState =
|
||||
showingSearchResults && rows.length === 0 && !isGridView && !isSearchLoading;
|
||||
@@ -286,29 +276,7 @@ const DocumentsTable = ({
|
||||
>
|
||||
<div className="column-header">
|
||||
<div className="column-header__titles">
|
||||
<nav className="breadcrumb" aria-label="Folder breadcrumbs">
|
||||
{breadcrumbs.map((crumb, index) => {
|
||||
const isLast = index === breadcrumbs.length - 1;
|
||||
return (
|
||||
<span key={crumb.id} className="breadcrumb-item">
|
||||
{isLast ? (
|
||||
<span className="breadcrumb-current">{crumb.name}</span>
|
||||
) : (
|
||||
<a
|
||||
href="#"
|
||||
onClick={(event) => {
|
||||
event.preventDefault();
|
||||
onFolderSelect(crumb.id);
|
||||
}}
|
||||
>
|
||||
{crumb.name}
|
||||
</a>
|
||||
)}
|
||||
{!isLast && <span className="breadcrumb-separator">›</span>}
|
||||
</span>
|
||||
);
|
||||
})}
|
||||
</nav>
|
||||
<h2>{currentFolderName}</h2>
|
||||
{showingSearchResults && (
|
||||
<div className="column-subtitle">Search results</div>
|
||||
)}
|
||||
@@ -376,13 +344,22 @@ const DocumentsTable = ({
|
||||
onDocumentListKeyDown(event);
|
||||
}
|
||||
}}
|
||||
onClick={(event) => {
|
||||
if (event.target === event.currentTarget) {
|
||||
onClearSelection?.();
|
||||
}
|
||||
}}
|
||||
aria-activedescendant={isGridView ? undefined : activeDescendantId}
|
||||
>
|
||||
{showDefaultEmptyState ? null : isGridView ? (
|
||||
<div
|
||||
className="documents-grid"
|
||||
role="list"
|
||||
onClick={handleGridBackgroundClick}
|
||||
onClick={(event) => {
|
||||
if (event.target === event.currentTarget) {
|
||||
onClearSelection?.();
|
||||
}
|
||||
}}
|
||||
style={{ '--documents-grid-icon-size': `${gridIconSize}px` }}
|
||||
>
|
||||
{!showingSearchResults &&
|
||||
@@ -619,13 +596,20 @@ const DocumentsTable = ({
|
||||
<td className="doc-list__name">
|
||||
<div className="doc-list__name-content">
|
||||
<span>{folder.name}</span>
|
||||
{folder.id !== 'root' && (
|
||||
</div>
|
||||
</td>
|
||||
<td>Folder</td>
|
||||
<td>—</td>
|
||||
<td className="actions">
|
||||
<div className="action-buttons">
|
||||
{folder.id !== 'root' && onFolderRename && (
|
||||
<button
|
||||
type="button"
|
||||
className="icon-button ghost doc-list__icon-button"
|
||||
className="icon-button ghost"
|
||||
title="Rename"
|
||||
aria-label={`Rename folder ${folder.name}`}
|
||||
onClick={(event) => {
|
||||
event.stopPropagation();
|
||||
if (!onFolderRename) return;
|
||||
const nextName = window.prompt('Rename folder', folder.name || '');
|
||||
if (!nextName) {
|
||||
return;
|
||||
@@ -636,27 +620,23 @@ const DocumentsTable = ({
|
||||
}
|
||||
onFolderRename(folder.id, trimmed);
|
||||
}}
|
||||
title="Rename folder"
|
||||
aria-label={`Rename folder ${folder.name}`}
|
||||
>
|
||||
<EditIcon className="doc-list__icon" size={16} />
|
||||
<EditIcon className="icon-inline" />
|
||||
</button>
|
||||
)}
|
||||
</div>
|
||||
</td>
|
||||
<td>Folder</td>
|
||||
<td>—</td>
|
||||
<td className="actions">
|
||||
<button
|
||||
type="button"
|
||||
className="icon-button danger"
|
||||
title="Delete"
|
||||
aria-label={`Delete folder ${folder.name}`}
|
||||
onClick={(event) => {
|
||||
event.stopPropagation();
|
||||
onFolderDelete(folder.id);
|
||||
}}
|
||||
>
|
||||
Delete
|
||||
<TrashIcon className="icon-inline" />
|
||||
</button>
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
);
|
||||
@@ -696,30 +676,6 @@ const DocumentsTable = ({
|
||||
<div className="doc-name">
|
||||
<div className="doc-list__name-content">
|
||||
<span className="doc-name__title">{doc.title || doc.original_name}</span>
|
||||
<button
|
||||
type="button"
|
||||
className="icon-button ghost doc-list__icon-button"
|
||||
onClick={(event) => {
|
||||
event.stopPropagation();
|
||||
if (!onDocumentRename) return;
|
||||
const nextName = window.prompt(
|
||||
'Rename document',
|
||||
doc.title || doc.original_name || '',
|
||||
);
|
||||
if (!nextName) {
|
||||
return;
|
||||
}
|
||||
const trimmed = nextName.trim();
|
||||
if (!trimmed || trimmed === (doc.title || doc.original_name)) {
|
||||
return;
|
||||
}
|
||||
onDocumentRename(doc.id, trimmed);
|
||||
}}
|
||||
title="Rename document"
|
||||
aria-label={`Rename document ${doc.title || doc.original_name}`}
|
||||
>
|
||||
<EditIcon className="doc-list__icon" size={16} />
|
||||
</button>
|
||||
</div>
|
||||
{(doc.tags || []).length > 0 && (
|
||||
<div className="doc-name__tags">
|
||||
@@ -788,31 +744,59 @@ const DocumentsTable = ({
|
||||
</td>
|
||||
<td className="actions">
|
||||
<div className="action-buttons">
|
||||
{onDocumentRename && (
|
||||
<button
|
||||
type="button"
|
||||
className="icon-button ghost"
|
||||
title="Rename"
|
||||
aria-label={`Rename document ${doc.title || doc.original_name}`}
|
||||
onClick={(event) => {
|
||||
event.stopPropagation();
|
||||
const nextName = window.prompt(
|
||||
'Rename document',
|
||||
doc.title || doc.original_name || '',
|
||||
);
|
||||
if (!nextName) {
|
||||
return;
|
||||
}
|
||||
const trimmed = nextName.trim();
|
||||
if (!trimmed || trimmed === (doc.title || doc.original_name)) {
|
||||
return;
|
||||
}
|
||||
onDocumentRename(doc.id, trimmed);
|
||||
}}
|
||||
>
|
||||
<EditIcon className="icon-inline" />
|
||||
</button>
|
||||
)}
|
||||
{downloadHref ? (
|
||||
<a
|
||||
className="button-link with-icon"
|
||||
className="icon-button"
|
||||
href={downloadHref}
|
||||
target="_blank"
|
||||
rel="noopener noreferrer"
|
||||
title="Download"
|
||||
aria-label="Download document"
|
||||
onClick={(event) => event.stopPropagation()}
|
||||
onAuxClick={(event) => event.stopPropagation()}
|
||||
onContextMenu={(event) => event.stopPropagation()}
|
||||
>
|
||||
<DownloadIcon className="icon-inline" />
|
||||
<span>Download</span>
|
||||
</a>
|
||||
) : (
|
||||
<span className="meta">No download</span>
|
||||
)}
|
||||
<button
|
||||
type="button"
|
||||
className="danger"
|
||||
className="icon-button danger"
|
||||
title="Delete"
|
||||
aria-label="Delete document"
|
||||
onClick={(event) => {
|
||||
event.stopPropagation();
|
||||
onDocumentDelete?.(doc.id);
|
||||
}}
|
||||
>
|
||||
Delete
|
||||
<TrashIcon className="icon-inline" />
|
||||
</button>
|
||||
</div>
|
||||
</td>
|
||||
|
||||
+160
-146
@@ -1,3 +1,5 @@
|
||||
import '@fontsource/inter/400.css';
|
||||
|
||||
import React, {
|
||||
useCallback,
|
||||
useContext,
|
||||
@@ -345,6 +347,8 @@ const AppLayout = () => {
|
||||
);
|
||||
const [loading, setLoading] = useState(false);
|
||||
const [isCreateFolderModalOpen, setCreateFolderModalOpen] = useState(false);
|
||||
const [isTagsModalOpen, setTagsModalOpen] = useState(false);
|
||||
const [isCorrespondentsModalOpen, setCorrespondentsModalOpen] = useState(false);
|
||||
const [newFolderName, setNewFolderName] = useState('');
|
||||
const [createFolderError, setCreateFolderError] = useState('');
|
||||
const [creatingFolder, setCreatingFolder] = useState(false);
|
||||
@@ -366,15 +370,11 @@ const AppLayout = () => {
|
||||
const stored = window.localStorage.getItem('papercrate_view_mode');
|
||||
return stored === 'grid' ? 'grid' : 'list';
|
||||
});
|
||||
const initialRowSelection = routeDocumentId
|
||||
? [resolveDocumentRowKey(routeDocumentId)]
|
||||
: [];
|
||||
const initialRowSelection = [];
|
||||
const [selectedRowKeys, setSelectedRowKeys] = useState(initialRowSelection);
|
||||
const [selectionOrder, setSelectionOrder] = useState(initialRowSelection);
|
||||
const [focusedDocumentId, setFocusedDocumentId] = useState(routeDocumentId);
|
||||
const [focusedRowKey, setFocusedRowKey] = useState(() =>
|
||||
routeDocumentId ? resolveDocumentRowKey(routeDocumentId) : null,
|
||||
);
|
||||
const [focusedDocumentId, setFocusedDocumentId] = useState(null);
|
||||
const [focusedRowKey, setFocusedRowKey] = useState(null);
|
||||
const tokenRef = useRef(token);
|
||||
const refreshPromiseRef = useRef(null);
|
||||
const breadcrumbFetchRef = useRef(new Set());
|
||||
@@ -423,13 +423,9 @@ const AppLayout = () => {
|
||||
const documentsRouteMatch = useMatch('/documents');
|
||||
const documentsFolderRouteMatch = useMatch('/documents/folder/:folderId');
|
||||
const documentsDetailRouteMatch = useMatch('/documents/:documentId');
|
||||
const tagsRouteMatch = useMatch('/tags');
|
||||
const correspondentsRouteMatch = useMatch('/correspondents');
|
||||
const isDocumentsRoute = Boolean(
|
||||
documentsRouteMatch || documentsFolderRouteMatch || documentsDetailRouteMatch,
|
||||
);
|
||||
const isTagsRoute = Boolean(tagsRouteMatch);
|
||||
const isCorrespondentsRoute = Boolean(correspondentsRouteMatch);
|
||||
const toggleTagFilter = useCallback((tagId) => {
|
||||
if (!tagId) return;
|
||||
setActiveTagFilters((previous) =>
|
||||
@@ -455,6 +451,10 @@ const AppLayout = () => {
|
||||
setSearchLoading(false);
|
||||
}, []);
|
||||
|
||||
const handleSearchChange = useCallback((value) => {
|
||||
setSearchQuery(value);
|
||||
}, []);
|
||||
|
||||
const handleSearchSubmit = useCallback(() => {
|
||||
if (!navigate) return;
|
||||
const targetFolder = selectedFolder && selectedFolder !== 'root' ? selectedFolder : 'root';
|
||||
@@ -814,14 +814,7 @@ const AppLayout = () => {
|
||||
if (selectionInitializedRef.current) {
|
||||
nextDocKeys = previousDocKeys.filter((key) => availableDocKeySet.has(key));
|
||||
} else {
|
||||
const filtered = previousDocKeys.filter((key) => availableDocKeySet.has(key));
|
||||
if (filtered.length) {
|
||||
nextDocKeys = filtered;
|
||||
} else if (availableDocKeys.length) {
|
||||
nextDocKeys = [availableDocKeys[0]];
|
||||
} else {
|
||||
nextDocKeys = [];
|
||||
}
|
||||
nextDocKeys = previousDocKeys.filter((key) => availableDocKeySet.has(key));
|
||||
}
|
||||
|
||||
mergedSelection = [...previousFolderKeys, ...nextDocKeys];
|
||||
@@ -3682,6 +3675,24 @@ const AppLayout = () => {
|
||||
setCreateFolderError('');
|
||||
}, [creatingFolder]);
|
||||
|
||||
const openTagsModal = useCallback(() => {
|
||||
setCorrespondentsModalOpen(false);
|
||||
setTagsModalOpen(true);
|
||||
}, []);
|
||||
|
||||
const closeTagsModal = useCallback(() => {
|
||||
setTagsModalOpen(false);
|
||||
}, []);
|
||||
|
||||
const openCorrespondentsModal = useCallback(() => {
|
||||
setTagsModalOpen(false);
|
||||
setCorrespondentsModalOpen(true);
|
||||
}, []);
|
||||
|
||||
const closeCorrespondentsModal = useCallback(() => {
|
||||
setCorrespondentsModalOpen(false);
|
||||
}, []);
|
||||
|
||||
const handleCreateFolderSubmit = useCallback(
|
||||
async (event) => {
|
||||
event.preventDefault();
|
||||
@@ -3742,6 +3753,31 @@ const AppLayout = () => {
|
||||
};
|
||||
}, [isCreateFolderModalOpen, closeCreateFolderModal]);
|
||||
|
||||
useEffect(() => {
|
||||
setTagsModalOpen(false);
|
||||
setCorrespondentsModalOpen(false);
|
||||
}, [location.pathname]);
|
||||
|
||||
useEffect(() => {
|
||||
if (!isTagsModalOpen && !isCorrespondentsModalOpen) {
|
||||
return;
|
||||
}
|
||||
const handleKeyDown = (event) => {
|
||||
if (event.key === 'Escape') {
|
||||
event.preventDefault();
|
||||
if (isTagsModalOpen) {
|
||||
closeTagsModal();
|
||||
} else if (isCorrespondentsModalOpen) {
|
||||
closeCorrespondentsModal();
|
||||
}
|
||||
}
|
||||
};
|
||||
window.addEventListener('keydown', handleKeyDown);
|
||||
return () => {
|
||||
window.removeEventListener('keydown', handleKeyDown);
|
||||
};
|
||||
}, [isTagsModalOpen, isCorrespondentsModalOpen, closeTagsModal, closeCorrespondentsModal]);
|
||||
|
||||
useEffect(() => {
|
||||
if (!token) return undefined;
|
||||
|
||||
@@ -4442,6 +4478,16 @@ const AppLayout = () => {
|
||||
correspondents,
|
||||
activeCorrespondentIds: activeCorrespondentFilters,
|
||||
onToggleCorrespondentFilter: toggleCorrespondentFilter,
|
||||
appStatus,
|
||||
loading,
|
||||
previewActive,
|
||||
searchQuery,
|
||||
onSearchChange: handleSearchChange,
|
||||
onSearchSubmit: handleSearchSubmit,
|
||||
onSearchClear: clearFilters,
|
||||
isFilterActive,
|
||||
onLogout: handleLogout,
|
||||
status,
|
||||
};
|
||||
|
||||
const resolveThumbnailUrlForDoc = useCallback(
|
||||
@@ -4538,6 +4584,7 @@ const AppLayout = () => {
|
||||
onCorrespondentAdd: handleCorrespondentAdd,
|
||||
onCorrespondentRemove: handleCorrespondentRemove,
|
||||
resolveApiPath,
|
||||
onClose: clearDocumentSelection,
|
||||
};
|
||||
|
||||
const skeuoWorkspaceProps = useMemo(
|
||||
@@ -4585,7 +4632,6 @@ const AppLayout = () => {
|
||||
tags,
|
||||
refreshTags,
|
||||
handleTagUpdate,
|
||||
handleTagCreate,
|
||||
handleTagDelete,
|
||||
handleDocumentTagAttach,
|
||||
correspondents,
|
||||
@@ -4610,6 +4656,8 @@ const AppLayout = () => {
|
||||
ensurePreviewData,
|
||||
notifyApiError,
|
||||
resolveApiPath,
|
||||
openTagsModal,
|
||||
openCorrespondentsModal,
|
||||
}),
|
||||
[
|
||||
token,
|
||||
@@ -4622,7 +4670,6 @@ const AppLayout = () => {
|
||||
tags,
|
||||
refreshTags,
|
||||
handleTagUpdate,
|
||||
handleTagCreate,
|
||||
handleTagDelete,
|
||||
handleDocumentTagAttach,
|
||||
correspondents,
|
||||
@@ -4647,6 +4694,8 @@ const AppLayout = () => {
|
||||
ensurePreviewData,
|
||||
notifyApiError,
|
||||
resolveApiPath,
|
||||
openTagsModal,
|
||||
openCorrespondentsModal,
|
||||
],
|
||||
);
|
||||
|
||||
@@ -4667,81 +4716,6 @@ const AppLayout = () => {
|
||||
active={dropOverlayState.active}
|
||||
folderName={dropOverlayState.folderName}
|
||||
/>
|
||||
<header className="app-bar">
|
||||
<div className="app-bar__main">
|
||||
<div className="app-bar__meta">
|
||||
<h1>Papercrate</h1>
|
||||
<span className="app-bar__hint">
|
||||
{appStatus === 'bootstrapping' && loading
|
||||
? 'Loading your library…'
|
||||
: previewActive
|
||||
? 'Viewing document preview. Press ← Back to return to the library.'
|
||||
: 'Drag files here to upload.'}
|
||||
</span>
|
||||
</div>
|
||||
<div className="app-bar__search">
|
||||
<input
|
||||
type="search"
|
||||
value={searchQuery}
|
||||
onChange={(event) => setSearchQuery(event.target.value)}
|
||||
placeholder="Search documents"
|
||||
aria-label="Search documents"
|
||||
onKeyDown={(event) => {
|
||||
if (event.key === 'Enter') {
|
||||
event.preventDefault();
|
||||
handleSearchSubmit();
|
||||
}
|
||||
}}
|
||||
/>
|
||||
{isFilterActive && (
|
||||
<button
|
||||
type="button"
|
||||
className="app-bar__search-clear"
|
||||
onClick={clearFilters}
|
||||
>
|
||||
Clear
|
||||
</button>
|
||||
)}
|
||||
</div>
|
||||
<div className="app-bar__right">
|
||||
<div className="app-bar__links">
|
||||
<button
|
||||
type="button"
|
||||
className={`app-bar__link${isDocumentsRoute ? ' active' : ''}`}
|
||||
onClick={() => navigate('/documents')}
|
||||
>
|
||||
Documents
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
className={`app-bar__link${isTagsRoute ? ' active' : ''}`}
|
||||
onClick={() => navigate('/tags')}
|
||||
>
|
||||
Tags
|
||||
<span className="app-bar__link-count">{tags.length}</span>
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
className={`app-bar__link${isCorrespondentsRoute ? ' active' : ''}`}
|
||||
onClick={() => navigate('/correspondents')}
|
||||
>
|
||||
Correspondents
|
||||
<span className="app-bar__link-count">{correspondents.length}</span>
|
||||
</button>
|
||||
</div>
|
||||
{status && (
|
||||
<div className="app-bar__status">
|
||||
<StatusBanner status={status} />
|
||||
</div>
|
||||
)}
|
||||
<div className="app-bar__actions">
|
||||
<button className="secondary" onClick={handleLogout}>
|
||||
Log out
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</header>
|
||||
<Outlet />
|
||||
{isCreateFolderModalOpen && (
|
||||
<div
|
||||
@@ -4791,6 +4765,74 @@ const AppLayout = () => {
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
{isTagsModalOpen && (
|
||||
<div
|
||||
className="modal-backdrop"
|
||||
role="presentation"
|
||||
onClick={closeTagsModal}
|
||||
>
|
||||
<div
|
||||
className="modal modal--panel"
|
||||
role="dialog"
|
||||
aria-modal="true"
|
||||
aria-labelledby="tags-modal-title"
|
||||
onClick={(event) => event.stopPropagation()}
|
||||
>
|
||||
<div className="panel-modal__header">
|
||||
<h3 id="tags-modal-title">Manage Tags</h3>
|
||||
<button type="button" className="secondary" onClick={closeTagsModal}>
|
||||
Close
|
||||
</button>
|
||||
</div>
|
||||
<div className="panel-modal__body">
|
||||
<TagsPanel
|
||||
tags={tags}
|
||||
onRefresh={refreshTags}
|
||||
onCreateTag={handleTagCreate}
|
||||
onUpdateTag={handleTagUpdate}
|
||||
onDeleteTag={handleTagDelete}
|
||||
onNotify={setStatusMessage}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
{isCorrespondentsModalOpen && (
|
||||
<div
|
||||
className="modal-backdrop"
|
||||
role="presentation"
|
||||
onClick={closeCorrespondentsModal}
|
||||
>
|
||||
<div
|
||||
className="modal modal--panel"
|
||||
role="dialog"
|
||||
aria-modal="true"
|
||||
aria-labelledby="correspondents-modal-title"
|
||||
onClick={(event) => event.stopPropagation()}
|
||||
>
|
||||
<div className="panel-modal__header">
|
||||
<h3 id="correspondents-modal-title">Manage Correspondents</h3>
|
||||
<button
|
||||
type="button"
|
||||
className="secondary"
|
||||
onClick={closeCorrespondentsModal}
|
||||
>
|
||||
Close
|
||||
</button>
|
||||
</div>
|
||||
<div className="panel-modal__body">
|
||||
<CorrespondentsPanel
|
||||
correspondents={correspondents}
|
||||
onRefresh={refreshCorrespondents}
|
||||
onCreate={handleCorrespondentCreate}
|
||||
onUpdate={handleCorrespondentUpdate}
|
||||
onDelete={handleCorrespondentDelete}
|
||||
onNotify={setStatusMessage}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</AppShellContext.Provider>
|
||||
);
|
||||
@@ -4803,20 +4845,39 @@ const DocumentsRoute = () => {
|
||||
detailPanelProps,
|
||||
workspaceMode,
|
||||
skeuoWorkspaceProps,
|
||||
openTagsModal,
|
||||
openCorrespondentsModal,
|
||||
} = useAppShell();
|
||||
|
||||
const sidebarPropsWithActions = useMemo(
|
||||
() => ({
|
||||
...sidebarProps,
|
||||
onManageTags: openTagsModal,
|
||||
onManageCorrespondents: openCorrespondentsModal,
|
||||
}),
|
||||
[sidebarProps, openTagsModal, openCorrespondentsModal],
|
||||
);
|
||||
|
||||
if (workspaceMode === 'skeuo') {
|
||||
return (
|
||||
<DocumentsLayout sidebarProps={sidebarProps}>
|
||||
<DocumentsLayout sidebarProps={sidebarPropsWithActions}>
|
||||
<div className="main-content">
|
||||
<SkeuomorphicWorkspace {...skeuoWorkspaceProps} />
|
||||
</div>
|
||||
</DocumentsLayout>
|
||||
);
|
||||
}
|
||||
|
||||
const detailHasContent = detailPanelProps.selectedDocuments?.length > 0;
|
||||
|
||||
return (
|
||||
<DocumentsLayout sidebarProps={sidebarProps}>
|
||||
<DocumentsLayout sidebarProps={sidebarPropsWithActions}>
|
||||
<div
|
||||
className={`main-content main-content--documents${detailHasContent ? ' main-content--has-detail' : ''}`}
|
||||
>
|
||||
<DocumentsTable {...documentsTableProps} />
|
||||
<DetailPanel {...detailPanelProps} />
|
||||
{detailHasContent ? <DetailPanel {...detailPanelProps} /> : null}
|
||||
</div>
|
||||
</DocumentsLayout>
|
||||
);
|
||||
};
|
||||
@@ -4951,51 +5012,6 @@ const LoginRoute = () => {
|
||||
);
|
||||
};
|
||||
|
||||
function TagsRoute() {
|
||||
const {
|
||||
tags,
|
||||
refreshTags,
|
||||
handleTagUpdate,
|
||||
handleTagDelete,
|
||||
setStatusMessage,
|
||||
} = useAppShell();
|
||||
return (
|
||||
<main className="panels-main">
|
||||
<TagsPanel
|
||||
tags={tags}
|
||||
onRefresh={refreshTags}
|
||||
onUpdateTag={handleTagUpdate}
|
||||
onDeleteTag={handleTagDelete}
|
||||
onNotify={setStatusMessage}
|
||||
/>
|
||||
</main>
|
||||
);
|
||||
}
|
||||
|
||||
function CorrespondentsRoute() {
|
||||
const {
|
||||
correspondents,
|
||||
refreshCorrespondents,
|
||||
handleCorrespondentCreate,
|
||||
handleCorrespondentUpdate,
|
||||
handleCorrespondentDelete,
|
||||
setStatusMessage,
|
||||
} = useAppShell();
|
||||
|
||||
return (
|
||||
<main className="panels-main">
|
||||
<CorrespondentsPanel
|
||||
correspondents={correspondents}
|
||||
onRefresh={refreshCorrespondents}
|
||||
onCreate={handleCorrespondentCreate}
|
||||
onUpdate={handleCorrespondentUpdate}
|
||||
onDelete={handleCorrespondentDelete}
|
||||
onNotify={setStatusMessage}
|
||||
/>
|
||||
</main>
|
||||
);
|
||||
}
|
||||
|
||||
const AppRouter = () => (
|
||||
<Routes>
|
||||
<Route path="/account/login" element={<LoginRoute />} />
|
||||
@@ -5004,8 +5020,6 @@ const AppRouter = () => (
|
||||
<Route path="/documents" element={<DocumentsRoute />} />
|
||||
<Route path="/documents/folder/:folderId" element={<DocumentsRoute />} />
|
||||
<Route path="/documents/:documentId" element={<DocumentViewerRoute />} />
|
||||
<Route path="/tags" element={<TagsRoute />} />
|
||||
<Route path="/correspondents" element={<CorrespondentsRoute />} />
|
||||
<Route path="*" element={<Navigate to="/documents" replace />} />
|
||||
</Route>
|
||||
</Routes>
|
||||
|
||||
@@ -136,6 +136,18 @@ const Sidebar = ({
|
||||
correspondents = [],
|
||||
activeCorrespondentIds = [],
|
||||
onToggleCorrespondentFilter,
|
||||
onManageTags,
|
||||
onManageCorrespondents,
|
||||
searchQuery = '',
|
||||
onSearchChange,
|
||||
onSearchSubmit,
|
||||
onSearchClear,
|
||||
isFilterActive,
|
||||
appStatus,
|
||||
loading,
|
||||
previewActive,
|
||||
onLogout,
|
||||
status,
|
||||
}) => {
|
||||
const sortedCorrespondents = useMemo(
|
||||
() =>
|
||||
@@ -150,6 +162,27 @@ const Sidebar = ({
|
||||
);
|
||||
const handleToggleTag = onToggleTagFilter || (() => {});
|
||||
const activeTagSet = new Set(activeTagIds);
|
||||
const handleManageTags = onManageTags || (() => {});
|
||||
const handleManageCorrespondents = onManageCorrespondents || (() => {});
|
||||
const handleSearchInputChange = useCallback(
|
||||
(event) => {
|
||||
onSearchChange?.(event.target.value);
|
||||
},
|
||||
[onSearchChange],
|
||||
);
|
||||
const handleSearchFormSubmit = useCallback(
|
||||
(event) => {
|
||||
event.preventDefault();
|
||||
onSearchSubmit?.();
|
||||
},
|
||||
[onSearchSubmit],
|
||||
);
|
||||
const handleSearchClear = useCallback(() => {
|
||||
onSearchClear?.();
|
||||
}, [onSearchClear]);
|
||||
const handleLogoutClick = useCallback(() => {
|
||||
onLogout?.();
|
||||
}, [onLogout]);
|
||||
|
||||
const renderNodes = useCallback(
|
||||
(ids, depth) =>
|
||||
@@ -193,9 +226,39 @@ const Sidebar = ({
|
||||
);
|
||||
|
||||
const rootNode = folderNodes.get('root');
|
||||
const hintText = appStatus === 'bootstrapping' && loading
|
||||
? 'Loading your library…'
|
||||
: previewActive
|
||||
? 'Viewing document preview. Press ← Back to return to the library.'
|
||||
: 'Drag files here to upload.';
|
||||
|
||||
return (
|
||||
<aside className="sidebar column">
|
||||
<aside className="sidebar">
|
||||
<div className="sidebar__meta">
|
||||
<h1 className="sidebar__title">Papercrate</h1>
|
||||
<span className="sidebar__hint">{hintText}</span>
|
||||
{onSearchChange && (
|
||||
<form className="sidebar__search" onSubmit={handleSearchFormSubmit}>
|
||||
<input
|
||||
type="search"
|
||||
value={searchQuery}
|
||||
onChange={handleSearchInputChange}
|
||||
placeholder="Search documents"
|
||||
aria-label="Search documents"
|
||||
/>
|
||||
{isFilterActive && (
|
||||
<button type="button" onClick={handleSearchClear}>
|
||||
Clear
|
||||
</button>
|
||||
)}
|
||||
</form>
|
||||
)}
|
||||
{status && (
|
||||
<div className="sidebar__status">
|
||||
<div className={`status-banner ${status.variant}`}>{status.message}</div>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
<div className="sidebar-section sidebar-section--folders">
|
||||
<div className="sidebar-section__header">
|
||||
<h3>Folders</h3>
|
||||
@@ -206,8 +269,14 @@ const Sidebar = ({
|
||||
</div>
|
||||
<div className="sidebar-section">
|
||||
<div className="sidebar-section__header">
|
||||
<button
|
||||
type="button"
|
||||
className="sidebar-section__title"
|
||||
onClick={handleManageTags}
|
||||
>
|
||||
<h3>Tags</h3>
|
||||
<span className="meta">{tags.length}</span>
|
||||
</button>
|
||||
</div>
|
||||
<div
|
||||
className={`sidebar-tag-cloud${
|
||||
@@ -215,8 +284,7 @@ const Sidebar = ({
|
||||
}`}
|
||||
role="list"
|
||||
>
|
||||
{tags.length ? (
|
||||
tags.map((tag) => {
|
||||
{tags.map((tag) => {
|
||||
const isActive = activeTagSet.has(tag.id);
|
||||
const style = getTagColorStyle(tag.color);
|
||||
const className = `sidebar-tag-pill${isActive ? ' active' : ''}`;
|
||||
@@ -249,20 +317,22 @@ const Sidebar = ({
|
||||
{tag.label}
|
||||
</button>
|
||||
);
|
||||
})
|
||||
) : (
|
||||
<span className="meta">No tags yet</span>
|
||||
)}
|
||||
})}
|
||||
</div>
|
||||
</div>
|
||||
<div className="sidebar-section">
|
||||
<div className="sidebar-section__header">
|
||||
<button
|
||||
type="button"
|
||||
className="sidebar-section__title"
|
||||
onClick={handleManageCorrespondents}
|
||||
>
|
||||
<h3>Correspondents</h3>
|
||||
<span className="meta">{correspondents.length}</span>
|
||||
</button>
|
||||
</div>
|
||||
<ul className="sidebar-correspondent-list">
|
||||
{sortedCorrespondents.length ? (
|
||||
sortedCorrespondents.map((correspondent) => {
|
||||
{sortedCorrespondents.map((correspondent) => {
|
||||
const isActive = activeCorrespondentSet.has(correspondent.id);
|
||||
const className = `sidebar-correspondent-item${isActive ? ' active' : ''}`;
|
||||
const label = correspondent.name || 'Unnamed';
|
||||
@@ -287,12 +357,14 @@ const Sidebar = ({
|
||||
</span>
|
||||
</li>
|
||||
);
|
||||
})
|
||||
) : (
|
||||
<li className="meta">No correspondents yet</li>
|
||||
)}
|
||||
})}
|
||||
</ul>
|
||||
</div>
|
||||
<div className="sidebar__footer">
|
||||
<button className="secondary" type="button" onClick={handleLogoutClick}>
|
||||
Log out
|
||||
</button>
|
||||
</div>
|
||||
</aside>
|
||||
);
|
||||
};
|
||||
|
||||
@@ -13,7 +13,6 @@
|
||||
grid-column: 2 / -1;
|
||||
min-height: 0;
|
||||
position: relative;
|
||||
background-color: var(--surface-subtle);
|
||||
}
|
||||
|
||||
.skeuo-header {
|
||||
@@ -22,7 +21,6 @@
|
||||
justify-content: space-between;
|
||||
gap: 1rem;
|
||||
padding: 0.75rem 1rem 0.5rem;
|
||||
background-color: var(--surface-subtle);
|
||||
}
|
||||
|
||||
.skeuo-header__meta {
|
||||
|
||||
@@ -1489,29 +1489,11 @@ const SkeuomorphicWorkspace = ({
|
||||
[queueFocusCanvas, handleTagDragEnd, onRemoveTagFromDocument, updateRemovalCursor],
|
||||
);
|
||||
|
||||
const renderBreadcrumbs = () => {
|
||||
if (!breadcrumbs.length) return null;
|
||||
return (
|
||||
<nav className="skeuo-breadcrumbs" aria-label="Folder breadcrumbs">
|
||||
{breadcrumbs.map((crumb, index) => {
|
||||
const isLast = index === breadcrumbs.length - 1;
|
||||
return (
|
||||
<span key={crumb.id} className={`skeuo-crumb${isLast ? ' is-current' : ''}`}>
|
||||
{crumb.name}
|
||||
{!isLast && <span className="skeuo-crumb-separator">›</span>}
|
||||
</span>
|
||||
);
|
||||
})}
|
||||
</nav>
|
||||
);
|
||||
};
|
||||
|
||||
return (
|
||||
<div className="skeuo-shell">
|
||||
<header className="skeuo-header">
|
||||
<div className="skeuo-header__meta">
|
||||
<h2>{currentFolderName}</h2>
|
||||
{renderBreadcrumbs()}
|
||||
{showingSearchResults && <span className="meta">Showing search results</span>}
|
||||
</div>
|
||||
<div className="skeuo-header__actions">
|
||||
|
||||
+475
-321
File diff suppressed because it is too large
Load Diff
@@ -1,12 +1,22 @@
|
||||
import React, { useCallback, useMemo, useState } from 'react';
|
||||
import { getTagColorStyle, HEX_COLOR_PATTERN } from '../utils/colors';
|
||||
|
||||
function TagsPanel({ tags, onRefresh, onUpdateTag, onDeleteTag, onNotify }) {
|
||||
function TagsPanel({
|
||||
tags,
|
||||
onRefresh,
|
||||
onCreateTag,
|
||||
onUpdateTag,
|
||||
onDeleteTag,
|
||||
onNotify,
|
||||
}) {
|
||||
const [editingId, setEditingId] = useState(null);
|
||||
const [draftLabel, setDraftLabel] = useState('');
|
||||
const [draftColor, setDraftColor] = useState('');
|
||||
const [saving, setSaving] = useState(false);
|
||||
const [deletingId, setDeletingId] = useState(null);
|
||||
const [createLabel, setCreateLabel] = useState('');
|
||||
const [createColor, setCreateColor] = useState('');
|
||||
const [creating, setCreating] = useState(false);
|
||||
|
||||
const startEdit = useCallback((tag) => {
|
||||
setEditingId(tag.id);
|
||||
@@ -98,19 +108,87 @@ function TagsPanel({ tags, onRefresh, onUpdateTag, onDeleteTag, onNotify }) {
|
||||
[onDeleteTag, editingId, cancelEdit, onNotify],
|
||||
);
|
||||
|
||||
const handleCreate = useCallback(
|
||||
async (event) => {
|
||||
event.preventDefault();
|
||||
if (typeof onCreateTag !== 'function') {
|
||||
return;
|
||||
}
|
||||
|
||||
const trimmedLabel = createLabel.trim();
|
||||
if (!trimmedLabel) {
|
||||
onNotify?.('Tag label cannot be empty.', 'error');
|
||||
return;
|
||||
}
|
||||
|
||||
const trimmedColor = createColor.trim();
|
||||
const colorPattern = /^#([0-9a-fA-F]{6})$/;
|
||||
if (trimmedColor && !colorPattern.test(trimmedColor)) {
|
||||
onNotify?.('Colors must use the #RRGGBB format.', 'error');
|
||||
return;
|
||||
}
|
||||
|
||||
setCreating(true);
|
||||
try {
|
||||
await onCreateTag({
|
||||
label: trimmedLabel,
|
||||
color: trimmedColor ? trimmedColor : null,
|
||||
});
|
||||
setCreateLabel('');
|
||||
setCreateColor('');
|
||||
} catch (createError) {
|
||||
const message = createError?.message || 'Failed to create tag.';
|
||||
onNotify?.(message, 'error');
|
||||
} finally {
|
||||
setCreating(false);
|
||||
}
|
||||
},
|
||||
[createLabel, createColor, onCreateTag, onNotify],
|
||||
);
|
||||
|
||||
return (
|
||||
<section className="tags-panel column">
|
||||
<section className="tags-panel">
|
||||
<div className="column-header">
|
||||
<div className="column-header__titles">
|
||||
<h2>Tags</h2>
|
||||
<div className="column-subtitle">{tags.length} total</div>
|
||||
</div>
|
||||
<div className="header-actions">
|
||||
<div className="header-actions tags-actions">
|
||||
<form className="tags-actions__form" onSubmit={handleCreate}>
|
||||
<input
|
||||
type="text"
|
||||
placeholder="New tag label"
|
||||
value={createLabel}
|
||||
onChange={(event) => setCreateLabel(event.target.value)}
|
||||
disabled={creating}
|
||||
/>
|
||||
<input
|
||||
type="color"
|
||||
className="tags-table__color-picker"
|
||||
value={createColor || '#3366ff'}
|
||||
onChange={(event) => setCreateColor(event.target.value)}
|
||||
disabled={creating}
|
||||
aria-label="Tag color (optional)"
|
||||
/>
|
||||
{createColor && (
|
||||
<button
|
||||
type="button"
|
||||
className="secondary"
|
||||
onClick={() => setCreateColor('')}
|
||||
disabled={creating}
|
||||
>
|
||||
Clear
|
||||
</button>
|
||||
)}
|
||||
<button type="submit" disabled={creating || !createLabel.trim()}>
|
||||
{creating ? 'Creating…' : 'Create'}
|
||||
</button>
|
||||
</form>
|
||||
<button
|
||||
className="secondary"
|
||||
type="button"
|
||||
onClick={onRefresh}
|
||||
disabled={saving || Boolean(deletingId)}
|
||||
disabled={saving || creating || Boolean(deletingId)}
|
||||
>
|
||||
Refresh
|
||||
</button>
|
||||
|
||||
@@ -9,6 +9,10 @@ import {
|
||||
IconLayoutGrid,
|
||||
IconArrowLeft,
|
||||
IconArrowRight,
|
||||
IconChevronsRight,
|
||||
IconAnalyze,
|
||||
IconWindowMaximize,
|
||||
IconTextScan2,
|
||||
} from '@tabler/icons-react';
|
||||
import FolderSvg from '../assets/folder.svg';
|
||||
|
||||
@@ -120,6 +124,33 @@ export const ArrowRightIcon = ({ className, size = '1em', stroke = 1.6, ...rest
|
||||
/>
|
||||
);
|
||||
|
||||
export const ChevronsRightIcon = ({ className, size = '1em', stroke = 1.6, ...rest }) => (
|
||||
<IconChevronsRight
|
||||
className={composeClassName('icon', className)}
|
||||
size={size}
|
||||
stroke={stroke}
|
||||
{...rest}
|
||||
/>
|
||||
);
|
||||
|
||||
export const AnalyzeIcon = ({ className, size = '1em', stroke = 1.6, ...rest }) => (
|
||||
<IconAnalyze
|
||||
className={composeClassName('icon', className)}
|
||||
size={size}
|
||||
stroke={stroke}
|
||||
{...rest}
|
||||
/>
|
||||
);
|
||||
|
||||
export const WindowMaximizeIcon = ({ className, size = '1em', stroke = 1.6, ...rest }) => (
|
||||
<IconWindowMaximize
|
||||
className={composeClassName('icon', className)}
|
||||
size={size}
|
||||
stroke={stroke}
|
||||
{...rest}
|
||||
/>
|
||||
);
|
||||
|
||||
export default {
|
||||
ChevronIcon,
|
||||
TrashIcon,
|
||||
@@ -130,4 +161,16 @@ export default {
|
||||
DownloadIcon,
|
||||
ViewListIcon,
|
||||
ViewGridIcon,
|
||||
ChevronsRightIcon,
|
||||
AnalyzeIcon,
|
||||
WindowMaximizeIcon,
|
||||
};
|
||||
|
||||
export const TextScanIcon = ({ className, size = '1em', stroke = 1.6, ...rest }) => (
|
||||
<IconTextScan2
|
||||
className={composeClassName('icon', className)}
|
||||
size={size}
|
||||
stroke={stroke}
|
||||
{...rest}
|
||||
/>
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user