2023-12-13 00:21:42 +01:00
|
|
|
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 axios from "axios";
|
2024-03-26 22:03:58 +01:00
|
|
|
import { useCallback, useState } from "react";
|
2023-12-13 00:21:42 +01:00
|
|
|
import useSWR from "swr";
|
|
|
|
|
|
|
|
type ExportItem = {
|
|
|
|
name: string;
|
|
|
|
};
|
2023-12-08 14:33:22 +01:00
|
|
|
|
|
|
|
function Export() {
|
2023-12-13 00:21:42 +01:00
|
|
|
const { data: exports, mutate } = useSWR<ExportItem[]>(
|
|
|
|
"exports/",
|
2024-02-28 23:23:56 +01:00
|
|
|
(url: string) => axios({ baseURL: baseUrl, url }).then((res) => res.data),
|
2023-12-13 00:21:42 +01:00
|
|
|
);
|
|
|
|
|
|
|
|
const [deleteClip, setDeleteClip] = useState<string | undefined>();
|
|
|
|
|
|
|
|
const onHandleDelete = useCallback(() => {
|
|
|
|
if (!deleteClip) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
axios.delete(`export/${deleteClip}`).then((response) => {
|
|
|
|
if (response.status == 200) {
|
|
|
|
setDeleteClip(undefined);
|
|
|
|
mutate();
|
|
|
|
}
|
|
|
|
});
|
2024-02-28 23:23:56 +01:00
|
|
|
}, [deleteClip, mutate]);
|
2023-12-13 00:21:42 +01:00
|
|
|
|
2023-12-08 14:33:22 +01:00
|
|
|
return (
|
2024-03-10 14:25:16 +01:00
|
|
|
<div className="size-full p-2 overflow-hidden flex flex-col">
|
2023-12-13 00:21:42 +01:00
|
|
|
<AlertDialog
|
|
|
|
open={deleteClip != undefined}
|
2024-02-28 23:23:56 +01:00
|
|
|
onOpenChange={() => setDeleteClip(undefined)}
|
2023-12-13 00:21:42 +01:00
|
|
|
>
|
|
|
|
<AlertDialogContent>
|
|
|
|
<AlertDialogHeader>
|
|
|
|
<AlertDialogTitle>Delete Export</AlertDialogTitle>
|
|
|
|
<AlertDialogDescription>
|
|
|
|
Confirm deletion of {deleteClip}.
|
|
|
|
</AlertDialogDescription>
|
|
|
|
</AlertDialogHeader>
|
|
|
|
<AlertDialogFooter>
|
|
|
|
<AlertDialogCancel>Cancel</AlertDialogCancel>
|
|
|
|
<Button variant="destructive" onClick={() => onHandleDelete()}>
|
|
|
|
Delete
|
|
|
|
</Button>
|
|
|
|
</AlertDialogFooter>
|
|
|
|
</AlertDialogContent>
|
|
|
|
</AlertDialog>
|
|
|
|
|
2024-03-10 14:25:16 +01:00
|
|
|
<div className="size-full overflow-hidden">
|
2023-12-13 00:21:42 +01:00
|
|
|
{exports && (
|
2024-03-10 14:25:16 +01:00
|
|
|
<div className="size-full grid gap-2 sm:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4 overflow-y-auto">
|
2023-12-13 00:21:42 +01:00
|
|
|
{Object.values(exports).map((item) => (
|
|
|
|
<ExportCard
|
|
|
|
key={item.name}
|
|
|
|
file={item}
|
|
|
|
onDelete={(file) => setDeleteClip(file)}
|
|
|
|
/>
|
|
|
|
))}
|
2024-03-10 14:25:16 +01:00
|
|
|
</div>
|
2023-12-13 00:21:42 +01:00
|
|
|
)}
|
|
|
|
</div>
|
2024-02-24 01:26:26 +01:00
|
|
|
</div>
|
2023-12-08 14:33:22 +01:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
export default Export;
|