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";
|
2024-04-20 00:11:41 +02:00
|
|
|
import { Dialog, DialogContent, DialogTitle } from "@/components/ui/dialog";
|
2024-04-07 22:35:45 +02:00
|
|
|
import { Input } from "@/components/ui/input";
|
2024-07-17 15:39:37 +02:00
|
|
|
import { Toaster } from "@/components/ui/sonner";
|
2024-08-02 15:06:15 +02:00
|
|
|
import { cn } from "@/lib/utils";
|
2024-04-20 15:44:59 +02:00
|
|
|
import { DeleteClipType, Export } from "@/types/export";
|
2023-12-13 00:21:42 +01:00
|
|
|
import axios from "axios";
|
2024-04-12 14:31:30 +02:00
|
|
|
import { useCallback, useEffect, useMemo, useState } from "react";
|
2024-08-02 15:06:15 +02:00
|
|
|
import { isMobile } from "react-device-detect";
|
2024-07-03 15:44:25 +02:00
|
|
|
import { LuFolderX } from "react-icons/lu";
|
2024-07-17 15:39:37 +02:00
|
|
|
import { toast } from "sonner";
|
2023-12-13 00:21:42 +01:00
|
|
|
import useSWR from "swr";
|
|
|
|
|
2024-04-20 00:11:41 +02:00
|
|
|
function Exports() {
|
|
|
|
const { data: exports, mutate } = useSWR<Export[]>("exports");
|
2023-12-13 00:21:42 +01:00
|
|
|
|
2024-04-12 14:31:30 +02:00
|
|
|
useEffect(() => {
|
|
|
|
document.title = "Export - Frigate";
|
|
|
|
}, []);
|
|
|
|
|
2024-04-07 22:35:45 +02:00
|
|
|
// Search
|
2023-12-13 00:21:42 +01:00
|
|
|
|
2024-04-07 22:35:45 +02:00
|
|
|
const [search, setSearch] = useState("");
|
|
|
|
|
2024-04-20 00:11:41 +02:00
|
|
|
const filteredExports = useMemo(() => {
|
|
|
|
if (!search || !exports) {
|
|
|
|
return exports;
|
2024-04-07 22:35:45 +02:00
|
|
|
}
|
|
|
|
|
2024-04-20 00:11:41 +02:00
|
|
|
return exports.filter((exp) =>
|
2024-04-07 22:35:45 +02:00
|
|
|
exp.name
|
|
|
|
.toLowerCase()
|
2024-04-20 00:11:41 +02:00
|
|
|
.replaceAll("_", " ")
|
|
|
|
.includes(search.toLowerCase()),
|
2024-04-07 22:35:45 +02:00
|
|
|
);
|
2024-04-20 00:11:41 +02:00
|
|
|
}, [exports, search]);
|
2024-04-07 22:35:45 +02:00
|
|
|
|
|
|
|
// Deleting
|
|
|
|
|
2024-04-20 15:44:59 +02:00
|
|
|
const [deleteClip, setDeleteClip] = useState<DeleteClipType | undefined>();
|
2024-04-03 16:02:07 +02:00
|
|
|
|
2023-12-13 00:21:42 +01:00
|
|
|
const onHandleDelete = useCallback(() => {
|
|
|
|
if (!deleteClip) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2024-04-20 15:44:59 +02:00
|
|
|
axios.delete(`export/${deleteClip.file}`).then((response) => {
|
2023-12-13 00:21:42 +01:00
|
|
|
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
|
|
|
|
2024-04-07 22:35:45 +02:00
|
|
|
// Renaming
|
|
|
|
|
|
|
|
const onHandleRename = useCallback(
|
2024-04-20 00:11:41 +02:00
|
|
|
(id: string, update: string) => {
|
2024-07-17 15:39:37 +02:00
|
|
|
axios
|
|
|
|
.patch(`export/${id}/${encodeURIComponent(update)}`)
|
|
|
|
.then((response) => {
|
|
|
|
if (response.status == 200) {
|
|
|
|
setDeleteClip(undefined);
|
|
|
|
mutate();
|
|
|
|
}
|
|
|
|
})
|
|
|
|
.catch((error) => {
|
|
|
|
if (error.response?.data?.message) {
|
|
|
|
toast.error(
|
|
|
|
`Failed to rename export: ${error.response.data.message}`,
|
|
|
|
{ position: "top-center" },
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
toast.error(`Failed to rename export: ${error.message}`, {
|
|
|
|
position: "top-center",
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
2024-04-07 22:35:45 +02:00
|
|
|
},
|
|
|
|
[mutate],
|
|
|
|
);
|
|
|
|
|
2024-04-20 00:11:41 +02:00
|
|
|
// Viewing
|
|
|
|
|
|
|
|
const [selected, setSelected] = useState<Export>();
|
2024-08-02 15:06:15 +02:00
|
|
|
const [selectedAspect, setSelectedAspect] = useState(0.0);
|
2024-04-20 00:11:41 +02:00
|
|
|
|
2023-12-08 14:33:22 +01:00
|
|
|
return (
|
2024-05-16 18:51:57 +02:00
|
|
|
<div className="flex size-full flex-col gap-2 overflow-hidden px-1 pt-2 md:p-2">
|
2024-07-17 15:39:37 +02:00
|
|
|
<Toaster closeButton={true} />
|
|
|
|
|
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>
|
2024-04-20 15:44:59 +02:00
|
|
|
Are you sure you want to delete {deleteClip?.exportName}?
|
2023-12-13 00:21:42 +01:00
|
|
|
</AlertDialogDescription>
|
|
|
|
</AlertDialogHeader>
|
|
|
|
<AlertDialogFooter>
|
|
|
|
<AlertDialogCancel>Cancel</AlertDialogCancel>
|
2024-04-20 00:11:41 +02:00
|
|
|
<Button
|
|
|
|
className="text-white"
|
|
|
|
variant="destructive"
|
|
|
|
onClick={() => onHandleDelete()}
|
|
|
|
>
|
2023-12-13 00:21:42 +01:00
|
|
|
Delete
|
|
|
|
</Button>
|
|
|
|
</AlertDialogFooter>
|
|
|
|
</AlertDialogContent>
|
|
|
|
</AlertDialog>
|
|
|
|
|
2024-04-20 00:11:41 +02:00
|
|
|
<Dialog
|
|
|
|
open={selected != undefined}
|
|
|
|
onOpenChange={(open) => {
|
|
|
|
if (!open) {
|
|
|
|
setSelected(undefined);
|
|
|
|
}
|
|
|
|
}}
|
|
|
|
>
|
2024-08-02 15:06:15 +02:00
|
|
|
<DialogContent
|
|
|
|
className={cn("max-w-[80%]", isMobile && "landscape:max-w-[60%]")}
|
|
|
|
>
|
|
|
|
<DialogTitle className="capitalize">
|
|
|
|
{selected?.name?.replaceAll("_", " ")}
|
|
|
|
</DialogTitle>
|
2024-04-20 00:11:41 +02:00
|
|
|
<video
|
2024-08-02 15:06:15 +02:00
|
|
|
className={cn(
|
|
|
|
"size-full rounded-lg md:rounded-2xl",
|
|
|
|
selectedAspect < 1.5 && "aspect-video h-full",
|
|
|
|
)}
|
2024-04-20 00:11:41 +02:00
|
|
|
playsInline
|
|
|
|
preload="auto"
|
|
|
|
autoPlay
|
|
|
|
controls
|
|
|
|
muted
|
2024-08-02 15:06:15 +02:00
|
|
|
onLoadedData={(e) =>
|
|
|
|
setSelectedAspect(
|
|
|
|
e.currentTarget.videoWidth / e.currentTarget.videoHeight,
|
|
|
|
)
|
|
|
|
}
|
2024-04-20 00:11:41 +02:00
|
|
|
>
|
|
|
|
<source
|
|
|
|
src={`${baseUrl}${selected?.video_path?.replace("/media/frigate/", "")}`}
|
|
|
|
type="video/mp4"
|
|
|
|
/>
|
|
|
|
</video>
|
|
|
|
</DialogContent>
|
|
|
|
</Dialog>
|
|
|
|
|
2024-07-03 15:44:25 +02:00
|
|
|
{exports && (
|
|
|
|
<div className="flex w-full items-center justify-center p-2">
|
|
|
|
<Input
|
|
|
|
className="w-full bg-muted md:w-1/3"
|
|
|
|
placeholder="Search"
|
|
|
|
value={search}
|
|
|
|
onChange={(e) => setSearch(e.target.value)}
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
)}
|
2024-04-07 22:35:45 +02:00
|
|
|
|
2024-04-03 16:02:07 +02:00
|
|
|
<div className="w-full overflow-hidden">
|
2024-07-03 15:44:25 +02:00
|
|
|
{exports && filteredExports && filteredExports.length > 0 ? (
|
2024-06-03 20:43:30 +02:00
|
|
|
<div className="scrollbar-container grid size-full gap-2 overflow-y-auto sm:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4">
|
2024-04-20 00:11:41 +02:00
|
|
|
{Object.values(exports).map((item) => (
|
2023-12-13 00:21:42 +01:00
|
|
|
<ExportCard
|
|
|
|
key={item.name}
|
2024-04-07 22:35:45 +02:00
|
|
|
className={
|
2024-04-20 00:11:41 +02:00
|
|
|
search == "" || filteredExports.includes(item) ? "" : "hidden"
|
2024-04-07 22:35:45 +02:00
|
|
|
}
|
2024-04-20 00:11:41 +02:00
|
|
|
exportedRecording={item}
|
|
|
|
onSelect={setSelected}
|
2024-04-03 16:02:07 +02:00
|
|
|
onRename={onHandleRename}
|
2024-04-20 15:44:59 +02:00
|
|
|
onDelete={({ file, exportName }) =>
|
|
|
|
setDeleteClip({ file, exportName })
|
|
|
|
}
|
2023-12-13 00:21:42 +01:00
|
|
|
/>
|
|
|
|
))}
|
2024-03-10 14:25:16 +01:00
|
|
|
</div>
|
2024-07-03 15:44:25 +02:00
|
|
|
) : (
|
|
|
|
<div className="absolute left-1/2 top-1/2 flex -translate-x-1/2 -translate-y-1/2 flex-col items-center justify-center text-center">
|
|
|
|
<LuFolderX className="size-16" />
|
|
|
|
No exports found
|
|
|
|
</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
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2024-04-20 00:11:41 +02:00
|
|
|
export default Exports;
|