mirror of
https://github.com/blakeblackshear/frigate.git
synced 2024-11-21 19:07:46 +01:00
Redesign exports page (#10359)
* Redesign exports page * Cleanup * fix overhange
This commit is contained in:
parent
70825bc938
commit
ee239744d8
@ -1,32 +1,87 @@
|
|||||||
import { baseUrl } from "@/api/baseUrl";
|
import { baseUrl } from "@/api/baseUrl";
|
||||||
import ActivityIndicator from "../indicators/activity-indicator";
|
import ActivityIndicator from "../indicators/activity-indicator";
|
||||||
import { Card } from "../ui/card";
|
import { LuTrash } from "react-icons/lu";
|
||||||
import { LuPlay, LuTrash } from "react-icons/lu";
|
|
||||||
import { Button } from "../ui/button";
|
import { Button } from "../ui/button";
|
||||||
|
import { useMemo, useRef, useState } from "react";
|
||||||
|
import { isDesktop } from "react-device-detect";
|
||||||
|
import { FaPlay } from "react-icons/fa";
|
||||||
|
import Chip from "../indicators/Chip";
|
||||||
|
|
||||||
type ExportProps = {
|
type ExportProps = {
|
||||||
file: {
|
file: {
|
||||||
name: string;
|
name: string;
|
||||||
};
|
};
|
||||||
onSelect: (file: string) => void;
|
|
||||||
onDelete: (file: string) => void;
|
onDelete: (file: string) => void;
|
||||||
};
|
};
|
||||||
|
|
||||||
export default function ExportCard({ file, onSelect, onDelete }: ExportProps) {
|
export default function ExportCard({ file, onDelete }: ExportProps) {
|
||||||
|
const videoRef = useRef<HTMLVideoElement | null>(null);
|
||||||
|
const [hovered, setHovered] = useState(false);
|
||||||
|
const [playing, setPlaying] = useState(false);
|
||||||
|
const inProgress = useMemo(
|
||||||
|
() => file.name.startsWith("in_progress"),
|
||||||
|
[file.name],
|
||||||
|
);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Card className="my-4 p-4 bg-secondary flex justify-start text-center items-center">
|
<div
|
||||||
{file.name.startsWith("in_progress") ? (
|
className="relative aspect-video bg-black rounded-2xl flex justify-center items-center"
|
||||||
|
onMouseEnter={
|
||||||
|
isDesktop && !inProgress ? () => setHovered(true) : undefined
|
||||||
|
}
|
||||||
|
onMouseLeave={
|
||||||
|
isDesktop && !inProgress ? () => setHovered(false) : undefined
|
||||||
|
}
|
||||||
|
onClick={isDesktop || inProgress ? undefined : () => setHovered(!hovered)}
|
||||||
|
>
|
||||||
|
{!playing && hovered && (
|
||||||
<>
|
<>
|
||||||
<div className="p-2">
|
<div className="absolute inset-0 z-10 bg-black bg-opacity-60 rounded-2xl" />
|
||||||
<ActivityIndicator size={16} />
|
<Chip
|
||||||
</div>
|
className="absolute top-2 right-2 bg-gradient-to-br from-gray-400 to-gray-500 bg-gray-500 rounded-md cursor-pointer"
|
||||||
<div className="px-2">
|
onClick={() => onDelete(file.name)}
|
||||||
{file.name.substring(12, file.name.length - 4)}
|
>
|
||||||
</div>
|
<LuTrash className="w-4 h-4 text-destructive fill-destructive" />
|
||||||
|
</Chip>
|
||||||
|
<Button
|
||||||
|
className="absolute left-1/2 -translate-x-1/2 top-1/2 -translate-y-1/2 w-20 h-20 z-20 text-white hover:text-white hover:bg-transparent"
|
||||||
|
variant="ghost"
|
||||||
|
onClick={() => {
|
||||||
|
setPlaying(true);
|
||||||
|
videoRef.current?.play();
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<FaPlay />
|
||||||
|
</Button>
|
||||||
</>
|
</>
|
||||||
|
)}
|
||||||
|
{inProgress ? (
|
||||||
|
<ActivityIndicator />
|
||||||
) : (
|
) : (
|
||||||
<>
|
<video
|
||||||
<Button variant="secondary" onClick={() => onSelect(file.name)}>
|
ref={videoRef}
|
||||||
|
className="absolute inset-0 aspect-video rounded-2xl"
|
||||||
|
playsInline
|
||||||
|
preload="auto"
|
||||||
|
muted
|
||||||
|
controls={playing}
|
||||||
|
>
|
||||||
|
<source src={`${baseUrl}exports/${file.name}`} type="video/mp4" />
|
||||||
|
</video>
|
||||||
|
)}
|
||||||
|
{!playing && (
|
||||||
|
<div className="absolute bottom-0 inset-x-0 rounded-b-l z-10 h-[20%] bg-gradient-to-t from-black/60 to-transparent pointer-events-none rounded-2xl">
|
||||||
|
<div className="flex h-full justify-between items-end mx-3 pb-1 text-white text-sm capitalize">
|
||||||
|
{file.name.substring(0, file.name.length - 4).replaceAll("_", " ")}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <Button variant="secondary" onClick={() => onSelect(file.name)}>
|
||||||
<LuPlay className="h-4 w-4 text-green-600" />
|
<LuPlay className="h-4 w-4 text-green-600" />
|
||||||
</Button>
|
</Button>
|
||||||
<a
|
<a
|
||||||
@ -43,8 +98,4 @@ export default function ExportCard({ file, onSelect, onDelete }: ExportProps) {
|
|||||||
>
|
>
|
||||||
<LuTrash className="h-4 w-4" stroke="#f87171" />
|
<LuTrash className="h-4 w-4" stroke="#f87171" />
|
||||||
</Button>
|
</Button>
|
||||||
</>
|
*/
|
||||||
)}
|
|
||||||
</Card>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
@ -3,14 +3,16 @@ import { CSSTransition } from "react-transition-group";
|
|||||||
|
|
||||||
type ChipProps = {
|
type ChipProps = {
|
||||||
className?: string;
|
className?: string;
|
||||||
children?: ReactNode[];
|
children?: ReactNode | ReactNode[];
|
||||||
in?: boolean;
|
in?: boolean;
|
||||||
|
onClick?: () => void;
|
||||||
};
|
};
|
||||||
|
|
||||||
export default function Chip({
|
export default function Chip({
|
||||||
className,
|
className,
|
||||||
children,
|
children,
|
||||||
in: inProp = true,
|
in: inProp = true,
|
||||||
|
onClick,
|
||||||
}: ChipProps) {
|
}: ChipProps) {
|
||||||
const nodeRef = useRef(null);
|
const nodeRef = useRef(null);
|
||||||
|
|
||||||
@ -30,6 +32,7 @@ export default function Chip({
|
|||||||
<div
|
<div
|
||||||
ref={nodeRef}
|
ref={nodeRef}
|
||||||
className={`flex px-2 py-1.5 rounded-2xl items-center z-10 ${className}`}
|
className={`flex px-2 py-1.5 rounded-2xl items-center z-10 ${className}`}
|
||||||
|
onClick={onClick}
|
||||||
>
|
>
|
||||||
{children}
|
{children}
|
||||||
</div>
|
</div>
|
||||||
|
@ -217,7 +217,7 @@ export default function PreviewThumbnailPlayer({
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div className="absolute bottom-0 inset-x-0 rounded-b-l z-10 w-full h-[20%] bg-gradient-to-t from-black/60 to-transparent pointer-events-none">
|
<div className="absolute bottom-0 inset-x-0 rounded-b-l z-10 w-full h-[20%] bg-gradient-to-t from-black/60 to-transparent pointer-events-none">
|
||||||
<div className="flex h-full justify-between items-end mx-3 pb-1 text-white text-sm ">
|
<div className="flex h-full justify-between items-end mx-3 pb-1 text-white text-sm">
|
||||||
<TimeAgo time={review.start_time * 1000} dense />
|
<TimeAgo time={review.start_time * 1000} dense />
|
||||||
{formattedDate}
|
{formattedDate}
|
||||||
</div>
|
</div>
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
import { baseUrl } from "@/api/baseUrl";
|
import { baseUrl } from "@/api/baseUrl";
|
||||||
import ExportCard from "@/components/card/ExportCard";
|
import ExportCard from "@/components/card/ExportCard";
|
||||||
import VideoPlayer from "@/components/player/VideoPlayer";
|
|
||||||
import {
|
import {
|
||||||
AlertDialog,
|
AlertDialog,
|
||||||
AlertDialogCancel,
|
AlertDialogCancel,
|
||||||
@ -12,13 +11,8 @@ import {
|
|||||||
} from "@/components/ui/alert-dialog";
|
} from "@/components/ui/alert-dialog";
|
||||||
import { Button } from "@/components/ui/button";
|
import { Button } from "@/components/ui/button";
|
||||||
import { Calendar } from "@/components/ui/calendar";
|
import { Calendar } from "@/components/ui/calendar";
|
||||||
import { Card } from "@/components/ui/card";
|
import { Dialog, DialogContent, DialogTrigger } from "@/components/ui/dialog";
|
||||||
import {
|
import { Drawer, DrawerContent, DrawerTrigger } from "@/components/ui/drawer";
|
||||||
Dialog,
|
|
||||||
DialogContent,
|
|
||||||
DialogHeader,
|
|
||||||
DialogTitle,
|
|
||||||
} from "@/components/ui/dialog";
|
|
||||||
import {
|
import {
|
||||||
DropdownMenuRadioGroup,
|
DropdownMenuRadioGroup,
|
||||||
DropdownMenuTrigger,
|
DropdownMenuTrigger,
|
||||||
@ -28,18 +22,13 @@ import {
|
|||||||
DropdownMenuSeparator,
|
DropdownMenuSeparator,
|
||||||
DropdownMenuRadioItem,
|
DropdownMenuRadioItem,
|
||||||
} from "@/components/ui/dropdown-menu";
|
} from "@/components/ui/dropdown-menu";
|
||||||
import Heading from "@/components/ui/heading";
|
|
||||||
import {
|
|
||||||
Popover,
|
|
||||||
PopoverContent,
|
|
||||||
PopoverTrigger,
|
|
||||||
} from "@/components/ui/popover";
|
|
||||||
import { Toaster } from "@/components/ui/sonner";
|
import { Toaster } from "@/components/ui/sonner";
|
||||||
import { FrigateConfig } from "@/types/frigateConfig";
|
import { FrigateConfig } from "@/types/frigateConfig";
|
||||||
import axios from "axios";
|
import axios from "axios";
|
||||||
import { format } from "date-fns";
|
import { format } from "date-fns";
|
||||||
import { useCallback, useState } from "react";
|
import { useCallback, useState } from "react";
|
||||||
import { DateRange } from "react-day-picker";
|
import { DateRange } from "react-day-picker";
|
||||||
|
import { isDesktop } from "react-device-detect";
|
||||||
import { toast } from "sonner";
|
import { toast } from "sonner";
|
||||||
import useSWR from "swr";
|
import useSWR from "swr";
|
||||||
|
|
||||||
@ -67,7 +56,6 @@ function Export() {
|
|||||||
const [startTime, setStartTime] = useState("00:00:00");
|
const [startTime, setStartTime] = useState("00:00:00");
|
||||||
const [endTime, setEndTime] = useState("23:59:59");
|
const [endTime, setEndTime] = useState("23:59:59");
|
||||||
|
|
||||||
const [selectedClip, setSelectedClip] = useState<string | undefined>();
|
|
||||||
const [deleteClip, setDeleteClip] = useState<string | undefined>();
|
const [deleteClip, setDeleteClip] = useState<string | undefined>();
|
||||||
|
|
||||||
const onHandleExport = () => {
|
const onHandleExport = () => {
|
||||||
@ -150,8 +138,12 @@ function Export() {
|
|||||||
});
|
});
|
||||||
}, [deleteClip, mutate]);
|
}, [deleteClip, mutate]);
|
||||||
|
|
||||||
|
const Create = isDesktop ? Dialog : Drawer;
|
||||||
|
const Trigger = isDesktop ? DialogTrigger : DrawerTrigger;
|
||||||
|
const Content = isDesktop ? DialogContent : DrawerContent;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="w-full h-full overflow-hidden">
|
<div className="size-full p-2 overflow-hidden flex flex-col">
|
||||||
<Toaster />
|
<Toaster />
|
||||||
|
|
||||||
<AlertDialog
|
<AlertDialog
|
||||||
@ -174,67 +166,48 @@ function Export() {
|
|||||||
</AlertDialogContent>
|
</AlertDialogContent>
|
||||||
</AlertDialog>
|
</AlertDialog>
|
||||||
|
|
||||||
<Dialog
|
<div className="w-full h-14">
|
||||||
open={selectedClip != undefined}
|
<Create>
|
||||||
onOpenChange={() => setSelectedClip(undefined)}
|
<Trigger>
|
||||||
>
|
<Button variant="select">New Export</Button>
|
||||||
<DialogContent>
|
</Trigger>
|
||||||
<DialogHeader>
|
<Content className="flex flex-col justify-center items-center">
|
||||||
<DialogTitle>Playback</DialogTitle>
|
<div className="w-full flex justify-evenly items-center">
|
||||||
</DialogHeader>
|
|
||||||
<VideoPlayer
|
|
||||||
options={{
|
|
||||||
preload: "auto",
|
|
||||||
autoplay: true,
|
|
||||||
sources: [
|
|
||||||
{
|
|
||||||
src: `${baseUrl}exports/${selectedClip}`,
|
|
||||||
type: "video/mp4",
|
|
||||||
},
|
|
||||||
],
|
|
||||||
}}
|
|
||||||
seekOptions={{ forward: 10, backward: 5 }}
|
|
||||||
/>
|
|
||||||
</DialogContent>
|
|
||||||
</Dialog>
|
|
||||||
|
|
||||||
<div className="w-full h-full xl:flex justify-between overflow-hidden">
|
|
||||||
<div>
|
|
||||||
<div className="my-2 flex">
|
|
||||||
<DropdownMenu>
|
|
||||||
<DropdownMenuTrigger asChild>
|
|
||||||
<Button className="capitalize" variant="outline">
|
|
||||||
{camera?.replaceAll("_", " ") || "Select A Camera"}
|
|
||||||
</Button>
|
|
||||||
</DropdownMenuTrigger>
|
|
||||||
<DropdownMenuContent>
|
|
||||||
<DropdownMenuLabel>Select A Camera</DropdownMenuLabel>
|
|
||||||
<DropdownMenuSeparator />
|
|
||||||
<DropdownMenuRadioGroup
|
|
||||||
value={camera}
|
|
||||||
onValueChange={setCamera}
|
|
||||||
>
|
|
||||||
{Object.keys(config?.cameras || {}).map((item) => (
|
|
||||||
<DropdownMenuRadioItem
|
|
||||||
className="capitalize"
|
|
||||||
key={item}
|
|
||||||
value={item}
|
|
||||||
>
|
|
||||||
{item.replaceAll("_", " ")}
|
|
||||||
</DropdownMenuRadioItem>
|
|
||||||
))}
|
|
||||||
</DropdownMenuRadioGroup>
|
|
||||||
</DropdownMenuContent>
|
|
||||||
</DropdownMenu>
|
|
||||||
<div className="mx-2">
|
|
||||||
<DropdownMenu>
|
<DropdownMenu>
|
||||||
<DropdownMenuTrigger asChild>
|
<DropdownMenuTrigger asChild>
|
||||||
<Button className="capitalize" variant="outline">
|
<Button className="capitalize" variant="secondary">
|
||||||
|
{camera?.replaceAll("_", " ") || "Select A Camera"}
|
||||||
|
</Button>
|
||||||
|
</DropdownMenuTrigger>
|
||||||
|
<DropdownMenuContent>
|
||||||
|
<DropdownMenuLabel className="flex justify-center items-center">
|
||||||
|
Select A Camera
|
||||||
|
</DropdownMenuLabel>
|
||||||
|
<DropdownMenuSeparator />
|
||||||
|
<DropdownMenuRadioGroup
|
||||||
|
value={camera}
|
||||||
|
onValueChange={setCamera}
|
||||||
|
>
|
||||||
|
{Object.keys(config?.cameras || {}).map((item) => (
|
||||||
|
<DropdownMenuRadioItem
|
||||||
|
className="capitalize"
|
||||||
|
key={item}
|
||||||
|
value={item}
|
||||||
|
>
|
||||||
|
{item.replaceAll("_", " ")}
|
||||||
|
</DropdownMenuRadioItem>
|
||||||
|
))}
|
||||||
|
</DropdownMenuRadioGroup>
|
||||||
|
</DropdownMenuContent>
|
||||||
|
</DropdownMenu>
|
||||||
|
<DropdownMenu>
|
||||||
|
<DropdownMenuTrigger asChild>
|
||||||
|
<Button className="capitalize" variant="secondary">
|
||||||
{playback?.split("_")[0] || "Select A Playback Factor"}
|
{playback?.split("_")[0] || "Select A Playback Factor"}
|
||||||
</Button>
|
</Button>
|
||||||
</DropdownMenuTrigger>
|
</DropdownMenuTrigger>
|
||||||
<DropdownMenuContent>
|
<DropdownMenuContent>
|
||||||
<DropdownMenuLabel>
|
<DropdownMenuLabel className="flex justify-center items-center">
|
||||||
Select A Playback Factor
|
Select A Playback Factor
|
||||||
</DropdownMenuLabel>
|
</DropdownMenuLabel>
|
||||||
<DropdownMenuSeparator />
|
<DropdownMenuSeparator />
|
||||||
@ -252,56 +225,54 @@ function Export() {
|
|||||||
</DropdownMenuContent>
|
</DropdownMenuContent>
|
||||||
</DropdownMenu>
|
</DropdownMenu>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
<Calendar mode="range" selected={date} onSelect={setDate} />
|
||||||
<Popover>
|
<div className="w-full flex justify-evenly">
|
||||||
<PopoverTrigger asChild>
|
<input
|
||||||
<Button variant="outline">{`${
|
className="w-36 p-1 border border-input bg-background text-secondary-foreground hover:bg-accent hover:text-accent-foreground dark:[color-scheme:dark]"
|
||||||
|
id="startTime"
|
||||||
|
type="time"
|
||||||
|
value={startTime}
|
||||||
|
step="1"
|
||||||
|
onChange={(e) => setStartTime(e.target.value)}
|
||||||
|
/>
|
||||||
|
<input
|
||||||
|
className="w-36 p-1 mx-2 border border-input bg-background text-secondary-foreground hover:bg-accent hover:text-accent-foreground dark:[color-scheme:dark]"
|
||||||
|
id="endTime"
|
||||||
|
type="time"
|
||||||
|
value={endTime}
|
||||||
|
step="1"
|
||||||
|
onChange={(e) => setEndTime(e.target.value)}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
<div className="w-full flex items-center justify-between px-4">
|
||||||
|
{`${
|
||||||
date?.from ? format(date?.from, "LLL dd, y") : ""
|
date?.from ? format(date?.from, "LLL dd, y") : ""
|
||||||
} ${startTime} -> ${
|
} ${startTime} -> ${
|
||||||
date?.to ? format(date?.to, "LLL dd, y") : ""
|
date?.to ? format(date?.to, "LLL dd, y") : ""
|
||||||
} ${endTime}`}</Button>
|
} ${endTime}`}
|
||||||
</PopoverTrigger>
|
<Button
|
||||||
<PopoverContent className="w-84">
|
className="my-4"
|
||||||
<Calendar mode="range" selected={date} onSelect={setDate} />
|
variant="select"
|
||||||
<div className="flex justify-between">
|
onClick={() => onHandleExport()}
|
||||||
<input
|
>
|
||||||
className="p-1 border border-input bg-background text-secondary-foreground hover:bg-accent hover:text-accent-foreground dark:[color-scheme:dark]"
|
Submit
|
||||||
id="startTime"
|
</Button>
|
||||||
type="time"
|
</div>
|
||||||
value={startTime}
|
</Content>
|
||||||
step="1"
|
</Create>
|
||||||
onChange={(e) => setStartTime(e.target.value)}
|
</div>
|
||||||
/>
|
|
||||||
<input
|
|
||||||
className="p-1 mx-2 border border-input bg-background text-secondary-foreground hover:bg-accent hover:text-accent-foreground dark:[color-scheme:dark]"
|
|
||||||
id="endTime"
|
|
||||||
type="time"
|
|
||||||
value={endTime}
|
|
||||||
step="1"
|
|
||||||
onChange={(e) => setEndTime(e.target.value)}
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
</PopoverContent>
|
|
||||||
</Popover>
|
|
||||||
<div>
|
|
||||||
<Button className="my-4" onClick={() => onHandleExport()}>
|
|
||||||
Submit
|
|
||||||
</Button>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
|
<div className="size-full overflow-hidden">
|
||||||
{exports && (
|
{exports && (
|
||||||
<Card className="h-full p-4 xl:w-1/2 overflow-y-auto">
|
<div className="size-full grid gap-2 sm:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4 overflow-y-auto">
|
||||||
<Heading as="h3">Exports</Heading>
|
|
||||||
{Object.values(exports).map((item) => (
|
{Object.values(exports).map((item) => (
|
||||||
<ExportCard
|
<ExportCard
|
||||||
key={item.name}
|
key={item.name}
|
||||||
file={item}
|
file={item}
|
||||||
onSelect={(file) => setSelectedClip(file)}
|
|
||||||
onDelete={(file) => setDeleteClip(file)}
|
onDelete={(file) => setDeleteClip(file)}
|
||||||
/>
|
/>
|
||||||
))}
|
))}
|
||||||
</Card>
|
</div>
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
Loading…
Reference in New Issue
Block a user