mirror of
https://github.com/blakeblackshear/frigate.git
synced 2026-02-13 06:35:24 +03:00
Improve export handling when errors occur
This commit is contained in:
parent
e9da453190
commit
f726c600ce
@ -1,7 +1,7 @@
|
|||||||
import ActivityIndicator from "../indicators/activity-indicator";
|
import ActivityIndicator from "../indicators/activity-indicator";
|
||||||
import { LuTrash } from "react-icons/lu";
|
import { LuTrash } from "react-icons/lu";
|
||||||
import { Button } from "../ui/button";
|
import { Button } from "../ui/button";
|
||||||
import { useState } from "react";
|
import { useCallback, useState } from "react";
|
||||||
import { isDesktop } from "react-device-detect";
|
import { isDesktop } from "react-device-detect";
|
||||||
import { FaDownload, FaPlay } from "react-icons/fa";
|
import { FaDownload, FaPlay } from "react-icons/fa";
|
||||||
import Chip from "../indicators/Chip";
|
import Chip from "../indicators/Chip";
|
||||||
@ -47,6 +47,15 @@ export default function ExportCard({
|
|||||||
update: string;
|
update: string;
|
||||||
}>();
|
}>();
|
||||||
|
|
||||||
|
const submitRename = useCallback(() => {
|
||||||
|
if (editName == undefined) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
onRename(exportedRecording.id, editName.update);
|
||||||
|
setEditName(undefined);
|
||||||
|
}, [editName, exportedRecording, onRename, setEditName]);
|
||||||
|
|
||||||
useKeyboardListener(
|
useKeyboardListener(
|
||||||
editName != undefined ? ["Enter"] : [],
|
editName != undefined ? ["Enter"] : [],
|
||||||
(key, modifiers) => {
|
(key, modifiers) => {
|
||||||
@ -57,8 +66,7 @@ export default function ExportCard({
|
|||||||
editName &&
|
editName &&
|
||||||
editName.update.length > 0
|
editName.update.length > 0
|
||||||
) {
|
) {
|
||||||
onRename(exportedRecording.id, editName.update);
|
submitRename();
|
||||||
setEditName(undefined);
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
@ -98,8 +106,7 @@ export default function ExportCard({
|
|||||||
variant="select"
|
variant="select"
|
||||||
disabled={(editName?.update?.length ?? 0) == 0}
|
disabled={(editName?.update?.length ?? 0) == 0}
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
onRename(exportedRecording.id, editName.update);
|
submitRename();
|
||||||
setEditName(undefined);
|
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
Save
|
Save
|
||||||
|
|||||||
@ -12,10 +12,12 @@ import {
|
|||||||
import { Button } from "@/components/ui/button";
|
import { Button } from "@/components/ui/button";
|
||||||
import { Dialog, DialogContent, DialogTitle } from "@/components/ui/dialog";
|
import { Dialog, DialogContent, DialogTitle } from "@/components/ui/dialog";
|
||||||
import { Input } from "@/components/ui/input";
|
import { Input } from "@/components/ui/input";
|
||||||
|
import { Toaster } from "@/components/ui/sonner";
|
||||||
import { DeleteClipType, Export } from "@/types/export";
|
import { DeleteClipType, Export } from "@/types/export";
|
||||||
import axios from "axios";
|
import axios from "axios";
|
||||||
import { useCallback, useEffect, useMemo, useState } from "react";
|
import { useCallback, useEffect, useMemo, useState } from "react";
|
||||||
import { LuFolderX } from "react-icons/lu";
|
import { LuFolderX } from "react-icons/lu";
|
||||||
|
import { toast } from "sonner";
|
||||||
import useSWR from "swr";
|
import useSWR from "swr";
|
||||||
|
|
||||||
function Exports() {
|
function Exports() {
|
||||||
@ -63,12 +65,26 @@ function Exports() {
|
|||||||
|
|
||||||
const onHandleRename = useCallback(
|
const onHandleRename = useCallback(
|
||||||
(id: string, update: string) => {
|
(id: string, update: string) => {
|
||||||
axios.patch(`export/${id}/${update}`).then((response) => {
|
axios
|
||||||
if (response.status == 200) {
|
.patch(`export/${id}/${update}`)
|
||||||
setDeleteClip(undefined);
|
.then((response) => {
|
||||||
mutate();
|
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",
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
},
|
},
|
||||||
[mutate],
|
[mutate],
|
||||||
);
|
);
|
||||||
@ -79,6 +95,8 @@ function Exports() {
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="flex size-full flex-col gap-2 overflow-hidden px-1 pt-2 md:p-2">
|
<div className="flex size-full flex-col gap-2 overflow-hidden px-1 pt-2 md:p-2">
|
||||||
|
<Toaster closeButton={true} />
|
||||||
|
|
||||||
<AlertDialog
|
<AlertDialog
|
||||||
open={deleteClip != undefined}
|
open={deleteClip != undefined}
|
||||||
onOpenChange={() => setDeleteClip(undefined)}
|
onOpenChange={() => setDeleteClip(undefined)}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user