import { baseUrl } from "@/api/baseUrl"; import ExportCard from "@/components/card/ExportCard"; import { AlertDialog, AlertDialogCancel, AlertDialogContent, AlertDialogDescription, AlertDialogFooter, AlertDialogHeader, AlertDialogTitle, } from "@/components/ui/alert-dialog"; import { Button } from "@/components/ui/button"; import { Dialog, DialogContent, DialogTitle } from "@/components/ui/dialog"; import { Input } from "@/components/ui/input"; import { DeleteClipType, Export } from "@/types/export"; import axios from "axios"; import { useCallback, useEffect, useMemo, useState } from "react"; import useSWR from "swr"; function Exports() { const { data: exports, mutate } = useSWR("exports"); useEffect(() => { document.title = "Export - Frigate"; }, []); // Search const [search, setSearch] = useState(""); const filteredExports = useMemo(() => { if (!search || !exports) { return exports; } return exports.filter((exp) => exp.name .toLowerCase() .replaceAll("_", " ") .includes(search.toLowerCase()), ); }, [exports, search]); // Deleting const [deleteClip, setDeleteClip] = useState(); const onHandleDelete = useCallback(() => { if (!deleteClip) { return; } axios.delete(`export/${deleteClip.file}`).then((response) => { if (response.status == 200) { setDeleteClip(undefined); mutate(); } }); }, [deleteClip, mutate]); // Renaming const onHandleRename = useCallback( (id: string, update: string) => { axios.patch(`export/${id}/${update}`).then((response) => { if (response.status == 200) { setDeleteClip(undefined); mutate(); } }); }, [mutate], ); // Viewing const [selected, setSelected] = useState(); return (
setDeleteClip(undefined)} > Delete Export Are you sure you want to delete {deleteClip?.exportName}? Cancel { if (!open) { setSelected(undefined); } }} > {selected?.name}
setSearch(e.target.value)} />
{exports && filteredExports && (
{Object.values(exports).map((item) => ( setDeleteClip({ file, exportName }) } /> ))}
)}
); } export default Exports;