import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'; import { faFileAlt, faFileArchive, faFileImport, faFolder } from '@fortawesome/free-solid-svg-icons'; import { differenceInHours, format, formatDistanceToNow } from 'date-fns'; import type { ReactNode } from 'react'; import { memo } from 'react'; import isEqual from 'react-fast-compare'; import { NavLink } from 'react-router-dom'; import tw from 'twin.macro'; import { join } from 'pathe'; import type { FileObject } from '@/api/server/files/loadDirectory'; import FileDropdownMenu from '@/components/server/files/FileDropdownMenu'; import SelectFileCheckbox from '@/components/server/files/SelectFileCheckbox'; import { encodePathSegments } from '@/helpers'; import { bytesToString } from '@/lib/formatters'; import { usePermissions } from '@/plugins/usePermissions'; import { ServerContext } from '@/state/server'; import styles from './style.module.css'; function Clickable({ file, children }: { file: FileObject; children: ReactNode }) { const [canReadContents] = usePermissions(['file.read-content']); const id = ServerContext.useStoreState(state => state.server.data!.id); const directory = ServerContext.useStoreState(state => state.files.directory); return !canReadContents || (file.isFile && !file.isEditable()) ? (
{children}
) : ( {children} ); } const MemoizedClickable = memo(Clickable, isEqual); function FileObjectRow({ file }: { file: FileObject }) { return (
{ e.preventDefault(); window.dispatchEvent(new CustomEvent(`pterodactyl:files:ctx:${file.key}`, { detail: e.clientX })); }} >
{file.isFile ? ( ) : ( )}
{file.name}
{file.isFile && }
); } export default memo(FileObjectRow, (prevProps, nextProps) => { /* eslint-disable @typescript-eslint/no-unused-vars */ const { isArchiveType, isEditable, ...prevFile } = prevProps.file; const { isArchiveType: nextIsArchiveType, isEditable: nextIsEditable, ...nextFile } = nextProps.file; /* eslint-enable @typescript-eslint/no-unused-vars */ return isEqual(prevFile, nextFile); });