2024-03-03 19:32:47 +03:00
|
|
|
import ActivityIndicator from "../indicators/activity-indicator";
|
2024-04-20 01:11:41 +03:00
|
|
|
import { LuTrash } from "react-icons/lu";
|
2023-12-13 02:21:42 +03:00
|
|
|
import { Button } from "../ui/button";
|
2024-07-17 16:39:37 +03:00
|
|
|
import { useCallback, useState } from "react";
|
2024-09-13 06:07:35 +03:00
|
|
|
import { isDesktop, isMobile } from "react-device-detect";
|
2024-09-12 17:46:29 +03:00
|
|
|
import { FaDownload, FaPlay, FaShareAlt } from "react-icons/fa";
|
2024-03-10 16:25:16 +03:00
|
|
|
import Chip from "../indicators/Chip";
|
2024-03-15 14:59:03 +03:00
|
|
|
import { Skeleton } from "../ui/skeleton";
|
2024-04-20 16:44:59 +03:00
|
|
|
import {
|
|
|
|
|
Dialog,
|
|
|
|
|
DialogContent,
|
|
|
|
|
DialogDescription,
|
|
|
|
|
DialogFooter,
|
|
|
|
|
DialogTitle,
|
|
|
|
|
} from "../ui/dialog";
|
2024-04-03 17:02:07 +03:00
|
|
|
import { Input } from "../ui/input";
|
|
|
|
|
import useKeyboardListener from "@/hooks/use-keyboard-listener";
|
2024-04-20 16:44:59 +03:00
|
|
|
import { DeleteClipType, Export } from "@/types/export";
|
2024-04-20 01:11:41 +03:00
|
|
|
import { MdEditSquare } from "react-icons/md";
|
|
|
|
|
import { baseUrl } from "@/api/baseUrl";
|
2024-05-07 17:00:25 +03:00
|
|
|
import { cn } from "@/lib/utils";
|
2024-09-12 17:46:29 +03:00
|
|
|
import { shareOrCopy } from "@/utils/browserUtil";
|
2025-03-16 18:36:20 +03:00
|
|
|
import { useTranslation } from "react-i18next";
|
2025-10-22 16:36:09 +03:00
|
|
|
import { ImageShadowOverlay } from "../overlay/ImageShadowOverlay";
|
2023-12-13 02:21:42 +03:00
|
|
|
|
|
|
|
|
type ExportProps = {
|
2024-04-07 23:35:45 +03:00
|
|
|
className: string;
|
2024-04-20 01:11:41 +03:00
|
|
|
exportedRecording: Export;
|
|
|
|
|
onSelect: (selected: Export) => void;
|
2024-04-03 17:02:07 +03:00
|
|
|
onRename: (original: string, update: string) => void;
|
2024-04-20 16:44:59 +03:00
|
|
|
onDelete: ({ file, exportName }: DeleteClipType) => void;
|
2023-12-13 02:21:42 +03:00
|
|
|
};
|
|
|
|
|
|
2024-04-07 23:35:45 +03:00
|
|
|
export default function ExportCard({
|
|
|
|
|
className,
|
2024-04-20 01:11:41 +03:00
|
|
|
exportedRecording,
|
|
|
|
|
onSelect,
|
2024-04-07 23:35:45 +03:00
|
|
|
onRename,
|
|
|
|
|
onDelete,
|
|
|
|
|
}: ExportProps) {
|
2025-03-16 18:36:20 +03:00
|
|
|
const { t } = useTranslation(["views/exports"]);
|
2024-03-10 16:25:16 +03:00
|
|
|
const [hovered, setHovered] = useState(false);
|
2024-04-20 01:11:41 +03:00
|
|
|
const [loading, setLoading] = useState(
|
|
|
|
|
exportedRecording.thumb_path.length > 0,
|
2024-03-10 16:25:16 +03:00
|
|
|
);
|
|
|
|
|
|
2024-04-03 17:02:07 +03:00
|
|
|
// editing name
|
|
|
|
|
|
|
|
|
|
const [editName, setEditName] = useState<{
|
|
|
|
|
original: string;
|
2024-08-13 18:12:06 +03:00
|
|
|
update?: string;
|
2024-04-03 17:02:07 +03:00
|
|
|
}>();
|
|
|
|
|
|
2024-07-17 16:39:37 +03:00
|
|
|
const submitRename = useCallback(() => {
|
|
|
|
|
if (editName == undefined) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2024-08-13 18:12:06 +03:00
|
|
|
onRename(exportedRecording.id, editName.update ?? "");
|
2024-07-17 16:39:37 +03:00
|
|
|
setEditName(undefined);
|
|
|
|
|
}, [editName, exportedRecording, onRename, setEditName]);
|
|
|
|
|
|
2024-04-03 17:02:07 +03:00
|
|
|
useKeyboardListener(
|
|
|
|
|
editName != undefined ? ["Enter"] : [],
|
2024-06-18 17:32:17 +03:00
|
|
|
(key, modifiers) => {
|
|
|
|
|
if (
|
|
|
|
|
key == "Enter" &&
|
|
|
|
|
modifiers.down &&
|
|
|
|
|
!modifiers.repeat &&
|
|
|
|
|
editName &&
|
2024-08-13 18:12:06 +03:00
|
|
|
(editName.update?.length ?? 0) > 0
|
2024-06-18 17:32:17 +03:00
|
|
|
) {
|
2024-07-17 16:39:37 +03:00
|
|
|
submitRename();
|
2025-10-02 16:21:37 +03:00
|
|
|
return true;
|
2024-03-10 16:25:16 +03:00
|
|
|
}
|
2025-10-02 16:21:37 +03:00
|
|
|
|
|
|
|
|
return false;
|
2024-04-03 17:02:07 +03:00
|
|
|
},
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<>
|
|
|
|
|
<Dialog
|
|
|
|
|
open={editName != undefined}
|
|
|
|
|
onOpenChange={(open) => {
|
|
|
|
|
if (!open) {
|
|
|
|
|
setEditName(undefined);
|
|
|
|
|
}
|
|
|
|
|
}}
|
|
|
|
|
>
|
2024-09-13 06:07:35 +03:00
|
|
|
<DialogContent
|
|
|
|
|
onOpenAutoFocus={(e) => {
|
|
|
|
|
if (isMobile) {
|
|
|
|
|
e.preventDefault();
|
|
|
|
|
}
|
|
|
|
|
}}
|
|
|
|
|
>
|
2025-03-16 18:36:20 +03:00
|
|
|
<DialogTitle>{t("editExport.title")}</DialogTitle>
|
|
|
|
|
<DialogDescription>{t("editExport.desc")}</DialogDescription>
|
2024-04-03 17:02:07 +03:00
|
|
|
{editName && (
|
|
|
|
|
<>
|
|
|
|
|
<Input
|
2024-09-13 06:07:35 +03:00
|
|
|
className="text-md mt-3"
|
2024-04-03 17:02:07 +03:00
|
|
|
type="search"
|
|
|
|
|
placeholder={editName?.original}
|
2024-08-13 18:12:06 +03:00
|
|
|
value={
|
|
|
|
|
editName?.update == undefined
|
|
|
|
|
? editName?.original
|
|
|
|
|
: editName?.update
|
|
|
|
|
}
|
2024-04-03 17:02:07 +03:00
|
|
|
onChange={(e) =>
|
|
|
|
|
setEditName({
|
|
|
|
|
original: editName.original ?? "",
|
|
|
|
|
update: e.target.value,
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
/>
|
|
|
|
|
<DialogFooter>
|
|
|
|
|
<Button
|
2025-03-16 18:36:20 +03:00
|
|
|
aria-label={t("editExport.saveExport")}
|
2024-04-03 17:02:07 +03:00
|
|
|
size="sm"
|
|
|
|
|
variant="select"
|
|
|
|
|
disabled={(editName?.update?.length ?? 0) == 0}
|
2024-07-17 16:39:37 +03:00
|
|
|
onClick={() => submitRename()}
|
2024-04-03 17:02:07 +03:00
|
|
|
>
|
2025-03-16 18:36:20 +03:00
|
|
|
{t("button.save", { ns: "common" })}
|
2024-04-03 17:02:07 +03:00
|
|
|
</Button>
|
|
|
|
|
</DialogFooter>
|
|
|
|
|
</>
|
|
|
|
|
)}
|
|
|
|
|
</DialogContent>
|
|
|
|
|
</Dialog>
|
|
|
|
|
|
|
|
|
|
<div
|
2024-05-07 17:00:25 +03:00
|
|
|
className={cn(
|
2024-05-14 18:06:44 +03:00
|
|
|
"relative flex aspect-video items-center justify-center rounded-lg bg-black md:rounded-2xl",
|
2024-05-07 17:00:25 +03:00
|
|
|
className,
|
|
|
|
|
)}
|
2024-06-04 18:10:19 +03:00
|
|
|
onMouseEnter={isDesktop ? () => setHovered(true) : undefined}
|
|
|
|
|
onMouseLeave={isDesktop ? () => setHovered(false) : undefined}
|
|
|
|
|
onClick={isDesktop ? undefined : () => setHovered(!hovered)}
|
2024-04-03 17:02:07 +03:00
|
|
|
>
|
2024-08-05 16:20:21 +03:00
|
|
|
{exportedRecording.in_progress ? (
|
|
|
|
|
<ActivityIndicator />
|
|
|
|
|
) : (
|
2024-04-03 17:02:07 +03:00
|
|
|
<>
|
2024-08-05 16:20:21 +03:00
|
|
|
{exportedRecording.thumb_path.length > 0 ? (
|
|
|
|
|
<img
|
2025-10-22 16:36:09 +03:00
|
|
|
className="absolute inset-0 aspect-video size-full rounded-lg object-cover md:rounded-2xl"
|
2024-08-05 16:20:21 +03:00
|
|
|
src={`${baseUrl}${exportedRecording.thumb_path.replace("/media/frigate/", "")}`}
|
|
|
|
|
onLoad={() => setLoading(false)}
|
|
|
|
|
/>
|
|
|
|
|
) : (
|
|
|
|
|
<div className="absolute inset-0 rounded-lg bg-secondary md:rounded-2xl" />
|
|
|
|
|
)}
|
|
|
|
|
</>
|
|
|
|
|
)}
|
|
|
|
|
{hovered && (
|
|
|
|
|
<div>
|
|
|
|
|
<div className="absolute inset-0 rounded-lg bg-black bg-opacity-60 md:rounded-2xl" />
|
2024-05-14 18:06:44 +03:00
|
|
|
<div className="absolute right-1 top-1 flex items-center gap-2">
|
2024-09-12 17:46:29 +03:00
|
|
|
{!exportedRecording.in_progress && (
|
|
|
|
|
<Chip
|
|
|
|
|
className="cursor-pointer rounded-md bg-gray-500 bg-gradient-to-br from-gray-400 to-gray-500"
|
|
|
|
|
onClick={() =>
|
|
|
|
|
shareOrCopy(
|
2024-09-13 16:25:29 +03:00
|
|
|
`${baseUrl}export?id=${exportedRecording.id}`,
|
2024-09-12 17:46:29 +03:00
|
|
|
exportedRecording.name.replaceAll("_", " "),
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
>
|
|
|
|
|
<FaShareAlt className="size-4 text-white" />
|
|
|
|
|
</Chip>
|
|
|
|
|
)}
|
2024-06-04 18:10:19 +03:00
|
|
|
{!exportedRecording.in_progress && (
|
|
|
|
|
<a
|
|
|
|
|
download
|
|
|
|
|
href={`${baseUrl}${exportedRecording.video_path.replace("/media/frigate/", "")}`}
|
|
|
|
|
>
|
|
|
|
|
<Chip className="cursor-pointer rounded-md bg-gray-500 bg-gradient-to-br from-gray-400 to-gray-500">
|
|
|
|
|
<FaDownload className="size-4 text-white" />
|
|
|
|
|
</Chip>
|
|
|
|
|
</a>
|
|
|
|
|
)}
|
|
|
|
|
{!exportedRecording.in_progress && (
|
|
|
|
|
<Chip
|
|
|
|
|
className="cursor-pointer rounded-md bg-gray-500 bg-gradient-to-br from-gray-400 to-gray-500"
|
|
|
|
|
onClick={() =>
|
|
|
|
|
setEditName({
|
|
|
|
|
original: exportedRecording.name,
|
2024-08-13 18:12:06 +03:00
|
|
|
update: undefined,
|
2024-06-04 18:10:19 +03:00
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
>
|
|
|
|
|
<MdEditSquare className="size-4 text-white" />
|
2024-04-20 01:11:41 +03:00
|
|
|
</Chip>
|
2024-06-04 18:10:19 +03:00
|
|
|
)}
|
2024-04-03 17:02:07 +03:00
|
|
|
<Chip
|
2024-05-14 18:06:44 +03:00
|
|
|
className="cursor-pointer rounded-md bg-gray-500 bg-gradient-to-br from-gray-400 to-gray-500"
|
2024-04-20 16:44:59 +03:00
|
|
|
onClick={() =>
|
|
|
|
|
onDelete({
|
|
|
|
|
file: exportedRecording.id,
|
|
|
|
|
exportName: exportedRecording.name,
|
|
|
|
|
})
|
|
|
|
|
}
|
2024-04-03 17:02:07 +03:00
|
|
|
>
|
2024-05-14 18:06:44 +03:00
|
|
|
<LuTrash className="size-4 fill-destructive text-destructive" />
|
2024-04-03 17:02:07 +03:00
|
|
|
</Chip>
|
|
|
|
|
</div>
|
2024-04-20 01:11:41 +03:00
|
|
|
|
2024-06-04 18:10:19 +03:00
|
|
|
{!exportedRecording.in_progress && (
|
|
|
|
|
<Button
|
2024-08-05 16:20:21 +03:00
|
|
|
className="absolute left-1/2 top-1/2 h-20 w-20 -translate-x-1/2 -translate-y-1/2 cursor-pointer text-white hover:bg-transparent hover:text-white"
|
2025-03-16 18:36:20 +03:00
|
|
|
aria-label={t("button.play", { ns: "common" })}
|
2024-06-04 18:10:19 +03:00
|
|
|
variant="ghost"
|
|
|
|
|
onClick={() => {
|
|
|
|
|
onSelect(exportedRecording);
|
|
|
|
|
}}
|
|
|
|
|
>
|
|
|
|
|
<FaPlay />
|
|
|
|
|
</Button>
|
|
|
|
|
)}
|
2024-08-05 16:20:21 +03:00
|
|
|
</div>
|
2024-04-03 17:02:07 +03:00
|
|
|
)}
|
|
|
|
|
{loading && (
|
2024-04-22 18:12:45 +03:00
|
|
|
<Skeleton className="absolute inset-0 aspect-video rounded-lg md:rounded-2xl" />
|
2024-04-03 17:02:07 +03:00
|
|
|
)}
|
2025-10-22 16:36:09 +03:00
|
|
|
<ImageShadowOverlay />
|
|
|
|
|
<div className="absolute bottom-2 left-3 flex h-full items-end justify-between text-white smart-capitalize">
|
|
|
|
|
{exportedRecording.name.replaceAll("_", " ")}
|
2024-04-20 01:11:41 +03:00
|
|
|
</div>
|
2024-04-03 17:02:07 +03:00
|
|
|
</div>
|
|
|
|
|
</>
|
2024-03-10 16:25:16 +03:00
|
|
|
);
|
|
|
|
|
}
|