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; } export default function ListFiles( { directories, files, onClickOpenRenameDirectory, onClickOpenRenameFile, onClickOpenMoveDirectory, onClickOpenMoveFile, onClickDeleteDirectory, onClickDeleteFile, isShowingNotes, }: ListFilesProps, ) { const dateFormatOptions: Intl.DateTimeFormatOptions = { year: 'numeric', month: 'long', day: 'numeric', hour12: false, hour: '2-digit', minute: '2-digit', }; const dateFormat = new Intl.DateTimeFormat('en-GB', dateFormatOptions); const routePath = isShowingNotes ? 'notes' : 'files'; const itemSingleLabel = isShowingNotes ? 'note' : 'file'; const itemPluralLabel = routePath; return (
{isShowingNotes ? null : } {directories.map((directory) => { const fullPath = `${directory.parent_path}${directory.directory_name}/`; return ( {isShowingNotes ? null : ( )} ); })} {files.map((file) => ( {isShowingNotes ? 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 : (
)}
File {file.file_name} {dateFormat.format(new Date(file.updated_at))} {humanFileSize(file.size_in_bytes)}
{typeof onClickOpenRenameFile === 'undefined' ? null : ( )} {typeof onClickOpenMoveFile === 'undefined' ? null : ( )}
No {itemPluralLabel} to show
); }