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 { Input } from "@/components/ui/input"; import axios from "axios"; import { useCallback, useMemo, useState } from "react"; import useSWR from "swr"; type ExportItem = { name: string; }; function Export() { const { data: allExports, mutate } = useSWR( "exports/", (url: string) => axios({ baseURL: baseUrl, url }).then((res) => res.data), ); // Search const [search, setSearch] = useState(""); const exports = useMemo(() => { if (!search || !allExports) { return allExports; } return allExports.filter((exp) => exp.name .toLowerCase() .includes(search.toLowerCase().replaceAll(" ", "_")), ); }, [allExports, search]); // Deleting const [deleteClip, setDeleteClip] = useState(); const onHandleDelete = useCallback(() => { if (!deleteClip) { return; } axios.delete(`export/${deleteClip}`).then((response) => { if (response.status == 200) { setDeleteClip(undefined); mutate(); } }); }, [deleteClip, mutate]); // Renaming const onHandleRename = useCallback( (original: string, update: string) => { axios.patch(`export/${original}/${update}`).then((response) => { if (response.status == 200) { setDeleteClip(undefined); mutate(); } }); }, [mutate], ); return (
setDeleteClip(undefined)} > Delete Export Confirm deletion of {deleteClip}. Cancel
setSearch(e.target.value)} />
{allExports && exports && (
{Object.values(allExports).map((item) => ( setDeleteClip(file)} /> ))}
)}
); } export default Export;