import { Directory, DirectoryFile } from '/lib/types.ts'; import { humanFileSize, TRASH_PATH } from '/lib/utils/files.ts'; interface ListFilesProps { directories: Directory[]; files: DirectoryFile[]; onClickOpenRenameDirectory?: (parentPath: string, name: string) => void; onClickOpenRenameFile?: (parentPath: string, name: string) => void; onClickOpenMoveDirectory?: (parentPath: string, name: string) => void; onClickOpenMoveFile?: (parentPath: string, name: string) => void; onClickDeleteDirectory?: (parentPath: string, name: string) => Promise; onClickDeleteFile?: (parentPath: string, name: string) => Promise; isShowingNotes?: boolean; isShowingPhotos?: boolean; } export default function ListFiles( { directories, files, onClickOpenRenameDirectory, onClickOpenRenameFile, onClickOpenMoveDirectory, onClickOpenMoveFile, onClickDeleteDirectory, onClickDeleteFile, isShowingNotes, isShowingPhotos, }: ListFilesProps, ) { const dateFormat = new Intl.DateTimeFormat('en-GB', { year: 'numeric', month: 'long', day: 'numeric', hour12: false, hour: '2-digit', minute: '2-digit', }); let routePath = 'files'; let itemSingleLabel = 'file'; let itemPluralLabel = 'files'; if (isShowingNotes) { routePath = 'notes'; itemSingleLabel = 'note'; itemPluralLabel = 'notes'; } else if (isShowingPhotos) { routePath = 'photos'; itemSingleLabel = 'photo'; itemPluralLabel = 'photos'; } if (isShowingPhotos && directories.length === 0) { return null; } return (
{isShowingNotes || isShowingPhotos ? null : } {isShowingPhotos ? null : } {directories.map((directory) => { const fullPath = `${directory.parent_path}${directory.directory_name}/`; return ( {isShowingNotes || isShowingPhotos ? null : ( )} {isShowingPhotos ? null : ( )} ); })} {files.map((file) => ( {isShowingNotes ? null : ( )} {isShowingPhotos ? null : ( )} ))} {directories.length === 0 && files.length === 0 ? ( ) : null}
Name Last updateSize
Directory {directory.directory_name} {dateFormat.format(new Date(directory.updated_at))} - {(fullPath === TRASH_PATH || typeof onClickOpenRenameDirectory === 'undefined' || typeof onClickOpenMoveDirectory === 'undefined') ? null : (
{typeof onClickDeleteDirectory === 'undefined' ? null : ( )}
)}
File {file.file_name} {dateFormat.format(new Date(file.updated_at))} {humanFileSize(file.size_in_bytes)}
{typeof onClickOpenRenameFile === 'undefined' ? null : ( )} {typeof onClickOpenMoveFile === 'undefined' ? null : ( )} {typeof onClickDeleteFile === 'undefined' ? null : ( )}
No {itemPluralLabel} to show
); }