import { ActionIcon, Group, LoadingOverlay, Modal, Select, SimpleGrid, Stack, Title, Tooltip, } from '@mantine/core'; import { useClipboard } from '@mantine/hooks'; import { showNotification } from '@mantine/notifications'; import useFetch from 'hooks/useFetch'; import { useFileDelete, useFileFavorite } from 'lib/queries/files'; import { useFolders } from 'lib/queries/folders'; import { bytesToHuman } from 'lib/utils/bytes'; import { relativeTime } from 'lib/utils/client'; import { useState } from 'react'; import { FileMeta } from '.'; import { CalendarIcon, ClockIcon, CopyIcon, CrossIcon, DeleteIcon, DownloadIcon, ExternalLinkIcon, EyeIcon, FileIcon, FolderMinusIcon, FolderPlusIcon, HardDriveIcon, HashIcon, ImageIcon, InfoIcon, StarIcon, } from '../icons'; import Type from '../Type'; export default function FileModal({ open, setOpen, file, loading, refresh, reducedActions = false, exifEnabled, }: { open: boolean; setOpen: (open: boolean) => void; file: any; loading: boolean; refresh: () => void; reducedActions?: boolean; exifEnabled?: boolean; }) { const deleteFile = useFileDelete(); const favoriteFile = useFileFavorite(); const folders = useFolders(); const [overrideRender, setOverrideRender] = useState(false); const clipboard = useClipboard(); const handleDelete = async () => { deleteFile.mutate(file.id, { onSuccess: () => { showNotification({ title: 'File Deleted', message: '', color: 'green', icon: , }); }, onError: (res: any) => { showNotification({ title: 'Failed to delete file', message: res.error, color: 'red', icon: , }); }, onSettled: () => { setOpen(false); }, }); }; const handleCopy = () => { clipboard.copy(`${window.location.protocol}//${window.location.host}${file.url}`); setOpen(false); if (!navigator.clipboard) showNotification({ title: 'Unable to copy to clipboard', message: 'Zipline is unable to copy to clipboard due to security reasons.', color: 'red', }); else showNotification({ title: 'Copied to clipboard', message: '', icon: , }); }; const handleFavorite = async () => { favoriteFile.mutate( { id: file.id, favorite: !file.favorite }, { onSuccess: () => { showNotification({ title: 'The file is now ' + (!file.favorite ? 'favorited' : 'unfavorited'), message: '', icon: , }); }, onError: (res: any) => { showNotification({ title: 'Failed to favorite file', message: res.error, color: 'red', icon: , }); }, } ); }; const inFolder = file.folderId; const removeFromFolder = async () => { const res = await useFetch('/api/user/folders/' + file.folderId, 'DELETE', { file: Number(file.id), }); refresh(); if (!res.error) { showNotification({ title: 'Removed from folder', message: res.name, color: 'green', icon: , }); } else { showNotification({ title: 'Failed to remove from folder', message: res.error, color: 'red', icon: , }); } }; const addToFolder = async (t) => { const res = await useFetch('/api/user/folders/' + t, 'POST', { file: Number(file.id), }); refresh(); if (!res.error) { showNotification({ title: 'Added to folder', message: res.name, color: 'green', icon: , }); } else { showNotification({ title: 'Failed to add to folder', message: res.error, color: 'red', icon: , }); } }; const createFolder = (t) => { useFetch('/api/user/folders', 'POST', { name: t, add: [Number(file.id)], }).then((res) => { refresh(); if (!res.error) { showNotification({ title: 'Created & added to folder', message: res.name, color: 'green', icon: , }); } else { showNotification({ title: 'Failed to create folder', message: res.error, color: 'red', icon: , }); } }); return { value: t, label: t }; }; return ( setOpen(false)} title={{file.name}} size='xl'> {file.maxViews && ( )} {file.expiresAt && !reducedActions && ( )} {exifEnabled && !reducedActions && ( window.open(`/dashboard/metadata/${file.id}`, '_blank')} > )} {reducedActions ? null : inFolder && !folders.isLoading ? ( f.id === file.folderId)?.name ?? ''}"`} > ) : (