From 46d5bab6476a7f4b90cd0a231c798069733f3d6b Mon Sep 17 00:00:00 2001 From: Richard R Date: Wed, 27 May 2026 19:40:12 -0600 Subject: [PATCH] cleanup doclist formatting helpers and view props --- src/components/doclist/DocumentList.tsx | 22 ++-- src/components/doclist/DocumentPreview.tsx | 9 +- src/components/doclist/formatSize.ts | 9 ++ src/components/doclist/views/ColumnsView.tsx | 12 +- src/components/doclist/views/DocumentTile.tsx | 110 ++++++++---------- src/components/doclist/views/GalleryView.tsx | 12 +- src/components/doclist/views/ListView.tsx | 13 +-- src/components/documents/DocumentUploader.tsx | 6 +- 8 files changed, 84 insertions(+), 109 deletions(-) create mode 100644 src/components/doclist/formatSize.ts diff --git a/src/components/doclist/DocumentList.tsx b/src/components/doclist/DocumentList.tsx index 4fd7c2d..0ccbe9e 100644 --- a/src/components/doclist/DocumentList.tsx +++ b/src/components/doclist/DocumentList.tsx @@ -310,6 +310,10 @@ function DocumentListInner({ brand, appActions }: DocumentListInnerProps) { } }, [documentToDelete, removePDFDocument, removeEPUBDocument, removeHTMLDocument]); + const handleDeleteDoc = useCallback((doc: DocumentListDocument) => { + setDocumentToDelete({ id: doc.id, name: doc.name, type: doc.type }); + }, []); + const handleDropOnFolder = useCallback( (folderId: string, item: DocumentDragItem) => { setFolders((prev) => @@ -478,7 +482,7 @@ function DocumentListInner({ brand, appActions }: DocumentListInnerProps) { diff --git a/src/components/doclist/views/DocumentTile.tsx b/src/components/doclist/views/DocumentTile.tsx index a5d5c58..4263a86 100644 --- a/src/components/doclist/views/DocumentTile.tsx +++ b/src/components/doclist/views/DocumentTile.tsx @@ -20,8 +20,49 @@ interface DocumentTileProps { onMergeIntoFolder: (source: DocumentListDocument[], target: DocumentListDocument) => void; } -const SIZE_LABEL: Record = { sm: 'S', md: 'M', lg: 'L', xl: 'XL' }; -void SIZE_LABEL; +const NAME_SIZE_CLASSES: Record = { + sm: 'text-[10px]', + md: 'text-[11px]', + lg: 'text-[12px]', + xl: 'text-[13px]', +}; + +const BOTTOM_PADDING_CLASSES: Record = { + sm: 'px-[7px] py-[4px]', + md: 'px-[8px] py-[5px]', + lg: 'px-[9px] py-[5px]', + xl: 'px-[10px] py-[6px]', +}; + +const LINK_PADDING_CLASS = 'px-[2px] py-[2px]'; + +const GAP_CLASSES: Record = { + sm: 'gap-1', + md: 'gap-1.5', + lg: 'gap-2', + xl: 'gap-2', +}; + +const FILE_ICON_CLASSES: Record = { + sm: 'w-3 h-3', + md: 'w-3.5 h-3.5', + lg: 'w-3.5 h-3.5', + xl: 'w-4 h-4', +}; + +const TRASH_BTN_CLASSES: Record = { + sm: 'ml-0.5 h-[18px] w-[18px] rounded-sm', + md: 'ml-0.5 h-[21px] w-[21px] rounded-sm', + lg: 'ml-1 h-[23px] w-[23px] rounded', + xl: 'ml-1.5 h-[25px] w-[25px] rounded', +}; + +const TRASH_ICON_CLASSES: Record = { + sm: 'w-[10px] h-[10px]', + md: 'w-[11px] h-[11px]', + lg: 'w-[12px] h-[12px]', + xl: 'w-[13px] h-[13px]', +}; export function DocumentTile({ doc, @@ -108,55 +149,6 @@ export function DocumentTile({ return () => clearTimeout(t); }, [loading]); - const sizeClasses: Record = { - sm: 'text-[10px]', - md: 'text-[11px]', - lg: 'text-[12px]', - xl: 'text-[13px]', - }; - - const bottomPaddingClasses: Record = { - sm: 'px-[7px] py-[4px]', - md: 'px-[8px] py-[5px]', - lg: 'px-[9px] py-[5px]', - xl: 'px-[10px] py-[6px]', - }; - - const linkPaddingClasses: Record = { - sm: 'px-[2px] py-[2px]', - md: 'px-[2px] py-[2px]', - lg: 'px-[2px] py-[2px]', - xl: 'px-[2px] py-[2px]', - }; - - const gapClasses: Record = { - sm: 'gap-1', - md: 'gap-1.5', - lg: 'gap-2', - xl: 'gap-2', - }; - - const fileIconClasses: Record = { - sm: 'w-3 h-3', - md: 'w-3.5 h-3.5', - lg: 'w-3.5 h-3.5', - xl: 'w-4 h-4', - }; - - const trashBtnClasses: Record = { - sm: 'ml-0.5 h-[18px] w-[18px] rounded-sm', - md: 'ml-0.5 h-[21px] w-[21px] rounded-sm', - lg: 'ml-1 h-[23px] w-[23px] rounded', - xl: 'ml-1.5 h-[25px] w-[25px] rounded', - }; - - const trashIconClasses: Record = { - sm: 'w-[10px] h-[10px]', - md: 'w-[11px] h-[11px]', - lg: 'w-[12px] h-[12px]', - xl: 'w-[13px] h-[13px]', - }; - return (
-
+
{doc.type === 'pdf' ? ( - + ) : doc.type === 'epub' ? ( - + ) : ( - + )} onDelete(doc)} - className={`inline-flex items-center justify-center text-muted hover:text-accent hover:bg-base focus:outline-none transition-colors duration-200 ${trashBtnClasses[iconSize]}`} + className={`inline-flex items-center justify-center text-muted hover:text-accent hover:bg-base focus:outline-none transition-colors duration-200 ${TRASH_BTN_CLASSES[iconSize]}`} aria-label={`Delete ${doc.name}`} > - +

- {activeDoc.type.toUpperCase()} •{' '} - {activeDoc.size >= 1024 * 1024 * 1024 - ? `${(activeDoc.size / 1024 / 1024 / 1024).toFixed(2)} GB` - : activeDoc.size >= 1024 * 1024 - ? `${(activeDoc.size / 1024 / 1024).toFixed(2)} MB` - : `${(activeDoc.size / 1024).toFixed(1)} KB`} + {activeDoc.type.toUpperCase()} • {formatDocumentSize(activeDoc.size)}

Open diff --git a/src/components/doclist/views/ListView.tsx b/src/components/doclist/views/ListView.tsx index e6bc86a..e6bccd4 100644 --- a/src/components/doclist/views/ListView.tsx +++ b/src/components/doclist/views/ListView.tsx @@ -11,6 +11,7 @@ import type { SortDirection, } from '@/types/documents'; import { PDFIcon, EPUBIcon, FileIcon } from '@/components/icons/Icons'; +import { formatDocumentSize } from '@/components/doclist/formatSize'; import { FolderIcon } from '../window/finderIcons'; import { useDocumentSelection } from '../dnd/DocumentSelectionContext'; import { DND_DOCUMENT, type DocumentDragItem } from '../dnd/dndTypes'; @@ -34,14 +35,6 @@ function formatDate(ms: number): string { return d.toLocaleDateString(undefined, { year: 'numeric', month: 'short', day: 'numeric' }); } -function formatSize(bytes: number): string { - const mb = bytes / 1024 / 1024; - if (mb >= 1024) { - return `${(mb / 1024).toFixed(2)} GB`; - } - return mb >= 1 ? `${mb.toFixed(2)} MB` : `${(bytes / 1024).toFixed(1)} KB`; -} - function KindIcon({ doc }: { doc: DocumentListDocument }) { if (doc.type === 'pdf') return ; if (doc.type === 'epub') return ; @@ -180,7 +173,7 @@ function DocRow({ {doc.type} - {formatSize(doc.size)} + {formatDocumentSize(doc.size)} {formatDate(doc.lastModified)} @@ -259,7 +252,7 @@ function FolderRowGroup({ Folder - {formatSize(totalSize)} + {formatDocumentSize(totalSize)} {folder.documents.length} items diff --git a/src/components/documents/DocumentUploader.tsx b/src/components/documents/DocumentUploader.tsx index 2ff1766..4d2f636 100644 --- a/src/components/documents/DocumentUploader.tsx +++ b/src/components/documents/DocumentUploader.tsx @@ -7,7 +7,6 @@ import { useDocuments } from '@/contexts/DocumentContext'; import { uploadDocxAsPdf } from '@/lib/client/api/documents'; import { useFeatureFlag } from '@/contexts/RuntimeConfigContext'; - interface DocumentUploaderProps { className?: string; variant?: 'default' | 'compact' | 'overlay'; @@ -93,14 +92,13 @@ export function DocumentUploader({ className = '', variant = 'default', children : `${ isDragActive ? 'border-2 border-dashed border-accent bg-base text-foreground' - : 'border-2 border-dashed border-muted bg-transparent text-foreground hover:border-accent hover:bg-base hover:scale-[1.008]' + : 'border-2 border-dashed border-muted bg-transparent text-foreground hover:border-accent hover:bg-base hover:scale-[1.01]' }`; const paddingClass = variant === 'compact' ? 'py-1 px-2 rounded-md' : 'py-5 px-3 rounded-lg'; if (variant === 'overlay') { - // eslint-disable-next-line @typescript-eslint/no-unused-vars - const { onClick, onKeyDown, ...rootProps } = getRootProps(); + const rootProps = getRootProps(); return (