import type { OdFolderChildren } from '../types' import Link from 'next/link' import { FC } from 'react' import { useClipboard } from 'use-clipboard-copy' import { FontAwesomeIcon } from '@fortawesome/react-fontawesome' import { useTranslation } from 'next-i18next' import { getBaseUrl } from '../utils/getBaseUrl' import { humanFileSize, formatModifiedDateTime } from '../utils/fileDetails' import { Downloading, Checkbox, ChildIcon, ChildName } from './FileListing' import { getStoredToken } from '../utils/protectedRouteHandler' const FileListItem: FC<{ fileContent: OdFolderChildren }> = ({ fileContent: c }) => { return (
{formatModifiedDateTime(c.lastModifiedDateTime)}
{humanFileSize(c.size)}
) } const FolderListLayout = ({ path, folderChildren, selected, toggleItemSelected, totalSelected, toggleTotalSelected, totalGenerating, handleSelectedDownload, folderGenerating, handleSelectedPermalink, handleFolderDownload, toast, }) => { const clipboard = useClipboard() const hashedToken = getStoredToken(path) const { t } = useTranslation() // Get item path from item name const getItemPath = (name: string) => `${path === '/' ? '' : path}/${encodeURIComponent(name)}` return (
{t('Name')}
{t('Last Modified')}
{t('Size')}
{t('Actions')}
{totalGenerating ? ( ) : ( )}
{folderChildren.map((c: OdFolderChildren) => (
{c.folder ? (
{ clipboard.copy(`${getBaseUrl()}${`${path === '/' ? '' : path}/${encodeURIComponent(c.name)}`}`) toast(t('Copied folder permalink.'), { icon: '👌' }) }} > {folderGenerating[c.id] ? ( ) : ( { const p = `${path === '/' ? '' : path}/${encodeURIComponent(c.name)}` handleFolderDownload(p, c.id, c.name)() }} > )}
) : (
{ clipboard.copy( `${getBaseUrl()}/api/raw/?path=${getItemPath(c.name)}${hashedToken ? `&odpt=${hashedToken}` : ''}` ) toast.success(t('Copied raw file permalink.')) }} >
)}
{!c.folder && !(c.name === '.password') && ( toggleItemSelected(c.id)} title={t('Select file')} /> )}
))}
) } export default FolderListLayout