mirror of
https://github.com/blakeblackshear/frigate.git
synced 2024-11-21 19:07:46 +01:00
Add ability to search exports (#10850)
* Add ability to search exports * Fix export saving
This commit is contained in:
parent
af320c8c09
commit
b26ceff44d
@ -12,6 +12,7 @@ import { Input } from "../ui/input";
|
|||||||
import useKeyboardListener from "@/hooks/use-keyboard-listener";
|
import useKeyboardListener from "@/hooks/use-keyboard-listener";
|
||||||
|
|
||||||
type ExportProps = {
|
type ExportProps = {
|
||||||
|
className: string;
|
||||||
file: {
|
file: {
|
||||||
name: string;
|
name: string;
|
||||||
};
|
};
|
||||||
@ -19,7 +20,12 @@ type ExportProps = {
|
|||||||
onDelete: (file: string) => void;
|
onDelete: (file: string) => void;
|
||||||
};
|
};
|
||||||
|
|
||||||
export default function ExportCard({ file, onRename, onDelete }: ExportProps) {
|
export default function ExportCard({
|
||||||
|
className,
|
||||||
|
file,
|
||||||
|
onRename,
|
||||||
|
onDelete,
|
||||||
|
}: ExportProps) {
|
||||||
const videoRef = useRef<HTMLVideoElement | null>(null);
|
const videoRef = useRef<HTMLVideoElement | null>(null);
|
||||||
const [hovered, setHovered] = useState(false);
|
const [hovered, setHovered] = useState(false);
|
||||||
const [playing, setPlaying] = useState(false);
|
const [playing, setPlaying] = useState(false);
|
||||||
@ -94,7 +100,7 @@ export default function ExportCard({ file, onRename, onDelete }: ExportProps) {
|
|||||||
</Dialog>
|
</Dialog>
|
||||||
|
|
||||||
<div
|
<div
|
||||||
className="relative aspect-video bg-black rounded-2xl flex justify-center items-center"
|
className={`relative aspect-video bg-black rounded-2xl flex justify-center items-center ${className}`}
|
||||||
onMouseEnter={
|
onMouseEnter={
|
||||||
isDesktop && !inProgress ? () => setHovered(true) : undefined
|
isDesktop && !inProgress ? () => setHovered(true) : undefined
|
||||||
}
|
}
|
||||||
|
@ -64,10 +64,13 @@ export default function ExportDialog({
|
|||||||
}
|
}
|
||||||
|
|
||||||
axios
|
axios
|
||||||
.post(`export/${camera}/start/${range.after}/end/${range.before}`, {
|
.post(
|
||||||
|
`export/${camera}/start/${Math.round(range.after)}/end/${Math.round(range.before)}`,
|
||||||
|
{
|
||||||
playback: "realtime",
|
playback: "realtime",
|
||||||
name,
|
name,
|
||||||
})
|
},
|
||||||
|
)
|
||||||
.then((response) => {
|
.then((response) => {
|
||||||
if (response.status == 200) {
|
if (response.status == 200) {
|
||||||
toast.success(
|
toast.success(
|
||||||
|
@ -66,10 +66,13 @@ export default function MobileReviewSettingsDrawer({
|
|||||||
}
|
}
|
||||||
|
|
||||||
axios
|
axios
|
||||||
.post(`export/${camera}/start/${range.after}/end/${range.before}`, {
|
.post(
|
||||||
|
`export/${camera}/start/${Math.round(range.after)}/end/${Math.round(range.before)}`,
|
||||||
|
{
|
||||||
playback: "realtime",
|
playback: "realtime",
|
||||||
name,
|
name,
|
||||||
})
|
},
|
||||||
|
)
|
||||||
.then((response) => {
|
.then((response) => {
|
||||||
if (response.status == 200) {
|
if (response.status == 200) {
|
||||||
toast.success(
|
toast.success(
|
||||||
|
@ -10,8 +10,9 @@ import {
|
|||||||
AlertDialogTitle,
|
AlertDialogTitle,
|
||||||
} from "@/components/ui/alert-dialog";
|
} from "@/components/ui/alert-dialog";
|
||||||
import { Button } from "@/components/ui/button";
|
import { Button } from "@/components/ui/button";
|
||||||
|
import { Input } from "@/components/ui/input";
|
||||||
import axios from "axios";
|
import axios from "axios";
|
||||||
import { useCallback, useState } from "react";
|
import { useCallback, useMemo, useState } from "react";
|
||||||
import useSWR from "swr";
|
import useSWR from "swr";
|
||||||
|
|
||||||
type ExportItem = {
|
type ExportItem = {
|
||||||
@ -19,24 +20,30 @@ type ExportItem = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
function Export() {
|
function Export() {
|
||||||
const { data: exports, mutate } = useSWR<ExportItem[]>(
|
const { data: allExports, mutate } = useSWR<ExportItem[]>(
|
||||||
"exports/",
|
"exports/",
|
||||||
(url: string) => axios({ baseURL: baseUrl, url }).then((res) => res.data),
|
(url: string) => axios({ baseURL: baseUrl, url }).then((res) => res.data),
|
||||||
);
|
);
|
||||||
|
|
||||||
const [deleteClip, setDeleteClip] = useState<string | undefined>();
|
// Search
|
||||||
|
|
||||||
const onHandleRename = useCallback(
|
const [search, setSearch] = useState("");
|
||||||
(original: string, update: string) => {
|
|
||||||
axios.patch(`export/${original}/${update}`).then((response) => {
|
const exports = useMemo(() => {
|
||||||
if (response.status == 200) {
|
if (!search || !allExports) {
|
||||||
setDeleteClip(undefined);
|
return allExports;
|
||||||
mutate();
|
|
||||||
}
|
}
|
||||||
});
|
|
||||||
},
|
return allExports.filter((exp) =>
|
||||||
[mutate],
|
exp.name
|
||||||
|
.toLowerCase()
|
||||||
|
.includes(search.toLowerCase().replaceAll(" ", "_")),
|
||||||
);
|
);
|
||||||
|
}, [allExports, search]);
|
||||||
|
|
||||||
|
// Deleting
|
||||||
|
|
||||||
|
const [deleteClip, setDeleteClip] = useState<string | undefined>();
|
||||||
|
|
||||||
const onHandleDelete = useCallback(() => {
|
const onHandleDelete = useCallback(() => {
|
||||||
if (!deleteClip) {
|
if (!deleteClip) {
|
||||||
@ -51,8 +58,22 @@ function Export() {
|
|||||||
});
|
});
|
||||||
}, [deleteClip, 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 (
|
return (
|
||||||
<div className="size-full p-2 overflow-hidden flex flex-col">
|
<div className="size-full p-2 overflow-hidden flex flex-col gap-2">
|
||||||
<AlertDialog
|
<AlertDialog
|
||||||
open={deleteClip != undefined}
|
open={deleteClip != undefined}
|
||||||
onOpenChange={() => setDeleteClip(undefined)}
|
onOpenChange={() => setDeleteClip(undefined)}
|
||||||
@ -73,12 +94,24 @@ function Export() {
|
|||||||
</AlertDialogContent>
|
</AlertDialogContent>
|
||||||
</AlertDialog>
|
</AlertDialog>
|
||||||
|
|
||||||
|
<div className="w-full p-2 flex items-center justify-center">
|
||||||
|
<Input
|
||||||
|
className="w-full md:w-1/3 bg-muted"
|
||||||
|
placeholder="Search"
|
||||||
|
value={search}
|
||||||
|
onChange={(e) => setSearch(e.target.value)}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
|
||||||
<div className="w-full overflow-hidden">
|
<div className="w-full overflow-hidden">
|
||||||
{exports && (
|
{allExports && exports && (
|
||||||
<div className="size-full grid gap-2 sm:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4 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">
|
||||||
{Object.values(exports).map((item) => (
|
{Object.values(allExports).map((item) => (
|
||||||
<ExportCard
|
<ExportCard
|
||||||
key={item.name}
|
key={item.name}
|
||||||
|
className={
|
||||||
|
search == "" || exports.includes(item) ? "" : "hidden"
|
||||||
|
}
|
||||||
file={item}
|
file={item}
|
||||||
onRename={onHandleRename}
|
onRename={onHandleRename}
|
||||||
onDelete={(file) => setDeleteClip(file)}
|
onDelete={(file) => setDeleteClip(file)}
|
||||||
|
Loading…
Reference in New Issue
Block a user