import { join } from 'std/path/join.ts'; import { Directory, DirectoryFile } from '/lib/types.ts'; import { humanFileSize, TRASH_PATH } from '/lib/utils/files.ts'; interface ListFilesProps { directories: Directory[]; files: DirectoryFile[]; chosenDirectories?: Pick[]; chosenFiles?: Pick[]; onClickChooseFile?: (parentPath: string, name: string) => void; onClickChooseDirectory?: (parentPath: string, name: string) => void; 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; onClickCreateShare?: (filePath: string) => void; onClickOpenManageShare?: (fileShareId: string) => void; isShowingNotes?: boolean; isShowingPhotos?: boolean; fileShareId?: string; } export default function ListFiles( { directories, files, chosenDirectories = [], chosenFiles = [], onClickChooseFile, onClickChooseDirectory, onClickOpenRenameDirectory, onClickOpenRenameFile, onClickOpenMoveDirectory, onClickOpenMoveFile, onClickDeleteDirectory, onClickDeleteFile, onClickCreateShare, onClickOpenManageShare, isShowingNotes, isShowingPhotos, fileShareId, }: 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); let routePath = fileShareId ? `file-share/${fileShareId}` : '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; } const isAnyItemChosen = chosenDirectories.length > 0 || chosenFiles.length > 0; function chooseAllItems() { if (typeof onClickChooseFile !== 'undefined') { files.forEach((files) => onClickChooseFile(files.parent_path, files.file_name)); } if (typeof onClickChooseDirectory !== 'undefined') { directories.forEach((directory) => onClickChooseDirectory(directory.parent_path, directory.directory_name)); } } return (
{(directories.length === 0 && files.length === 0) || (typeof onClickChooseFile === 'undefined' && typeof onClickChooseDirectory === 'undefined') || fileShareId ? null : ( )} {isShowingNotes || isShowingPhotos ? null : } {isShowingPhotos || fileShareId ? null : } {directories.map((directory) => { const fullPath = `${directory.parent_path}${directory.directory_name}/`; return ( {typeof onClickChooseDirectory === 'undefined' || fileShareId ? null : ( )} {isShowingNotes || isShowingPhotos ? null : ( )} {isShowingPhotos || fileShareId ? null : ( )} ); })} {files.map((file) => ( {typeof onClickChooseFile === 'undefined' || fileShareId ? null : ( )} {isShowingNotes ? null : ( )} {isShowingPhotos || fileShareId ? null : ( )} ))} {directories.length === 0 && files.length === 0 ? ( ) : null}
chooseAllItems()} checked={isAnyItemChosen} /> Name Last updateSize
{fullPath === TRASH_PATH ? null : ( onClickChooseDirectory(directory.parent_path, directory.directory_name)} checked={Boolean(chosenDirectories.find((_directory) => _directory.parent_path === directory.parent_path && _directory.directory_name === directory.directory_name ))} /> )} 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 : ( )} {typeof onClickCreateShare === 'undefined' || directory.file_share_id ? null : ( )} {typeof onClickOpenManageShare === 'undefined' || !directory.file_share_id ? null : ( )}
)}
onClickChooseFile(file.parent_path, file.file_name)} checked={Boolean( chosenFiles.find((_file) => _file.parent_path === file.parent_path && _file.file_name === file.file_name ), )} /> 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 : ( )} {typeof onClickCreateShare === 'undefined' || file.file_share_id ? null : ( )} {typeof onClickOpenManageShare === 'undefined' || !file.file_share_id ? null : ( )}
No {itemPluralLabel} to show
); }