import { convertBytes } from '@/app/lib/convertBytes'; import { toast } from 'sonner'; import { useState, ReactNode } from 'react'; import { useTranslations } from 'next-intl'; import ModalWindow from '@/app/components/modalWindow'; import { IconEye, IconDownload } from '@/app/ui/icons/icons'; export function SearchedUserFilesList({ list }: { list: any }) { const [isFileLoading, setIsFileLoading] = useState(false); const [openWindow, setOpenWindow] = useState(false); const [openWindowChildren, setOpenWindowChildren] = useState(null); const t = useTranslations('Global'); const handlerDownload = async (fileId: string, fileName: string) => { setIsFileLoading(true); try { const response = await fetch(`/api/download/${fileId}`); if (!response.ok) { throw new Error(`error: ${response.status}`); } const blob = await response.blob(); const url = window.URL.createObjectURL(blob); const a = document.createElement('a'); a.href = url; a.download = fileName || `file-${fileId}`; document.body.appendChild(a); a.click(); window.URL.revokeObjectURL(url); document.body.removeChild(a); toast.success(`${t('file-is-downloading')} - ${fileName}`); } catch (error) { toast.error(t('failed-to-download-file')) } finally { setIsFileLoading(false); } }; const handlerViewfile = async (e: any) => { setOpenWindowChildren(() => { return (
{e.originalFileName}
img

Информация о файле

ID в системе: {e.supportId ? e.supportId : '#'}
Дата загрузки: {e.uploadDate ? e.uploadDate : '#'}
Размер файла: {convertBytes(e.fileSize)}
Статус защиты: {e.status ? e.status : '#'}
) }) setOpenWindow(true); }; return ( <>
Результаты поиска
Найдено файлов: {list.length}
{list.map((e: any, index: number) => { console.log(e); console.log(e.similarityLevel); if (e.similarityLevel !== 'DIFFERENT') { return (
{e.url ? ( Preview ) : (
📄
)}
{e.originalFileName}
Загружен: {e.uploadDate ? e.uploadDate : '#'} • Размер: {convertBytes(e.fileSize)}
{e.similarityLevel}
{e.status}
) } })}
) }