import { TableCell, TableRow } from "@/components/ui/table"; import { cn } from "@/lib/utils"; import { getRowHeightTailwindClass, type RowHeight, } from "@/components/table-row-height-switch"; import { Checkbox } from "@/components/ui/checkbox"; import FileProgress from "@/components/file-progress"; import React, { memo, type ReactNode, useState } from "react"; import { type TelegramFile } from "@/lib/types"; import SpoiledWrapper from "@/components/spoiled-wrapper"; import { Tooltip, TooltipContent, TooltipProvider, TooltipTrigger, } from "@/components/ui/tooltip"; import PhotoPreview from "@/components/photo-preview"; import prettyBytes from "pretty-bytes"; import FileStatus from "@/components/file-status"; import FileExtra from "@/components/file-extra"; import FileControl from "@/components/file-control"; import { FileAudioIcon, FileIcon, ImageIcon, VideoIcon } from "lucide-react"; import Image from "next/image"; import { type Column } from "./table-column-filter"; import { useFileSpeed } from "@/hooks/use-file-speed"; interface FileRowProps { file: TelegramFile; checked: boolean; properties: { rowHeight: RowHeight; dynamicClass: { content: string; contentCell: string; }; columns: Column[]; }; onCheckedChange: (checked: boolean) => void; } export default function FileRow({ file, checked, properties, onCheckedChange, }: FileRowProps) { const { rowHeight, dynamicClass, columns } = properties; const { downloadProgress, downloadSpeed } = useFileSpeed(file.id); const [hovered, setHovered] = useState(false); const getFileIcon = (type: TelegramFile["type"]) => { let icon; switch (type) { case "photo": icon = ; break; case "video": icon = ; break; case "audio": icon = ; break; default: icon = ; } return (
{icon}
); }; const columnRenders: Record = { content: (
{file.type === "photo" || file.type === "video" ? ( file.thumbnail ? ( ) : ( getFileIcon(file.type) ) ) : ( getFileIcon(file.type) )}
), type: (
{file.type} {process.env.NODE_ENV === "development" && ( {file.id} )}
), size: {prettyBytes(file.size)}, status: , extra: , actions: ( ), }; return ( setHovered(true)} onMouseLeave={() => setHovered(false)} > {columns.map((col) => col.isVisible ? ( {columnRenders[col.id]} ) : null, )} ); } const PhotoColumnImage = memo(function PhotoColumnImage({ thumbnail, name, wh, }: { thumbnail: string; name: string; wh: string; }) { return ( {name ); });