import { baseUrl } from "@/api/baseUrl"; import ActivityIndicator from "../indicators/activity-indicator"; import { LuPencil, LuTrash } from "react-icons/lu"; import { Button } from "../ui/button"; import { useMemo, useRef, useState } from "react"; import { isDesktop } from "react-device-detect"; import { FaPlay } from "react-icons/fa"; import Chip from "../indicators/Chip"; import { Skeleton } from "../ui/skeleton"; import { Dialog, DialogContent, DialogFooter, DialogTitle } from "../ui/dialog"; import { Input } from "../ui/input"; import useKeyboardListener from "@/hooks/use-keyboard-listener"; type ExportProps = { className: string; file: { name: string; }; onRename: (original: string, update: string) => void; onDelete: (file: string) => void; }; export default function ExportCard({ className, file, onRename, onDelete, }: ExportProps) { const videoRef = useRef(null); const [hovered, setHovered] = useState(false); const [playing, setPlaying] = useState(false); const [loading, setLoading] = useState(true); const inProgress = useMemo( () => file.name.startsWith("in_progress"), [file.name], ); // editing name const [editName, setEditName] = useState<{ original: string; update: string; }>(); useKeyboardListener( editName != undefined ? ["Enter"] : [], (_, down, repeat) => { if (down && !repeat && editName && editName.update.length > 0) { onRename(editName.original, editName.update.replaceAll(" ", "_")); setEditName(undefined); } }, ); return ( <> { if (!open) { setEditName(undefined); } }} > Rename Export {editName && ( <> setEditName({ original: editName.original ?? "", update: e.target.value, }) } /> )}
setHovered(true) : undefined } onMouseLeave={ isDesktop && !inProgress ? () => setHovered(false) : undefined } onClick={ isDesktop || inProgress ? undefined : () => setHovered(!hovered) } > {hovered && ( <> {!playing && (
)}
setEditName({ original: file.name, update: "" })} > onDelete(file.name)} >
{!playing && ( )} )} {inProgress ? ( ) : ( )} {loading && ( )} {!playing && (
{file.name .substring(0, file.name.length - 4) .replaceAll("_", " ")}
)}
); }