import type { OdFolderChildren } from '../types' import Link from 'next/link' import { useState } from 'react' import { FontAwesomeIcon } from '@fortawesome/react-fontawesome' import { useClipboard } from 'use-clipboard-copy' import { useTranslation } from 'next-i18next' import { getBaseUrl } from '../utils/getBaseUrl' import { formatModifiedDateTime } from '../utils/fileDetails' import { Checkbox, ChildIcon, ChildName, Downloading } from './FileListing' import { getStoredToken } from '../utils/protectedRouteHandler' const GridItem = ({ c, path }: { c: OdFolderChildren; path: string }) => { // We use the generated medium thumbnail for rendering preview images (excluding folders) const hashedToken = getStoredToken(path) const thumbnailUrl = 'folder' in c ? null : `/api/thumbnail/?path=${path}&size=medium${hashedToken ? `&odpt=${hashedToken}` : ''}` // Some thumbnails are broken, so we check for onerror event in the image component const [brokenThumbnail, setBrokenThumbnail] = useState(false) return (
{thumbnailUrl && !brokenThumbnail ? ( // eslint-disable-next-line @next/next/no-img-element {c.name} setBrokenThumbnail(true)} /> ) : (
{c.folder?.childCount}
)}
{formatModifiedDateTime(c.lastModifiedDateTime)}
) } const FolderGridLayout = ({ 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('{{count}} item(s)', { count: folderChildren.length })}
{totalGenerating ? ( ) : ( )}
{folderChildren.map((c: OdFolderChildren) => (
{c.folder ? (
{ clipboard.copy(`${getBaseUrl()}${getItemPath(c.name)}`) toast(t('Copied folder permalink.'), { icon: '👌' }) }} > {folderGenerating[c.id] ? ( ) : ( )}
) : (
{ 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 FolderGridLayout