mirror of
https://github.com/blakeblackshear/frigate.git
synced 2026-03-10 10:33:11 +03:00
Some checks are pending
CI / AMD64 Build (push) Waiting to run
CI / ARM Build (push) Waiting to run
CI / Jetson Jetpack 6 (push) Waiting to run
CI / AMD64 Extra Build (push) Blocked by required conditions
CI / ARM Extra Build (push) Blocked by required conditions
CI / Synaptics Build (push) Blocked by required conditions
CI / Assemble and push default build (push) Blocked by required conditions
* improve chip tooltip display - use formatList to use i18n separators instead of commas - ensure the correct event type is used so sublabels are not run through normalization - remove smart-capitalization classes as translated labels use i18n (which includes capitalization) - give icons an optional key so that the console doesn't complain about duplication when rendering * Add grace period for recording segment checks to prevent spurious ffmpeg restarts * add admin precedence to proxy role_map resolution to prevent downgrade * clean up * formatting * work around radix pointer events issue when dialog is opened from drawer fixes https://github.com/blakeblackshear/frigate/discussions/21940 * prevent console warnings about missing titles and descriptions make these invisible with sr-only * remove duplicate language * Adjust handling for device sizes * Cleanup --------- Co-authored-by: Nicolas Mowen <nickmowen213@gmail.com>
152 lines
3.9 KiB
TypeScript
152 lines
3.9 KiB
TypeScript
import { useState, useEffect } from "react";
|
|
import {
|
|
AlertDialog,
|
|
AlertDialogAction,
|
|
AlertDialogCancel,
|
|
AlertDialogContent,
|
|
AlertDialogDescription,
|
|
AlertDialogFooter,
|
|
AlertDialogHeader,
|
|
AlertDialogTitle,
|
|
} from "@/components/ui/alert-dialog";
|
|
import {
|
|
Sheet,
|
|
SheetContent,
|
|
SheetHeader,
|
|
SheetTitle,
|
|
SheetDescription,
|
|
} from "@/components/ui/sheet";
|
|
import { Button } from "@/components/ui/button";
|
|
import ActivityIndicator from "@/components/indicators/activity-indicator";
|
|
import { baseUrl } from "@/api/baseUrl";
|
|
|
|
import { useTranslation } from "react-i18next";
|
|
|
|
type RestartDialogProps = {
|
|
isOpen: boolean;
|
|
onClose: () => void;
|
|
onRestart: () => void;
|
|
};
|
|
|
|
export default function RestartDialog({
|
|
isOpen,
|
|
onClose,
|
|
onRestart,
|
|
}: RestartDialogProps) {
|
|
const { t } = useTranslation("components/dialog");
|
|
const [restartDialogOpen, setRestartDialogOpen] = useState(isOpen);
|
|
const [restartingSheetOpen, setRestartingSheetOpen] = useState(false);
|
|
const [countdown, setCountdown] = useState(60);
|
|
|
|
const clearBodyPointerEvents = () => {
|
|
if (typeof document !== "undefined") {
|
|
document.body.style.pointerEvents = "";
|
|
}
|
|
};
|
|
|
|
useEffect(() => {
|
|
setRestartDialogOpen(isOpen);
|
|
}, [isOpen]);
|
|
|
|
useEffect(() => {
|
|
let countdownInterval: NodeJS.Timeout;
|
|
|
|
if (restartingSheetOpen) {
|
|
countdownInterval = setInterval(() => {
|
|
setCountdown((prevCountdown) => prevCountdown - 1);
|
|
}, 1000);
|
|
}
|
|
|
|
return () => {
|
|
clearInterval(countdownInterval);
|
|
};
|
|
}, [restartingSheetOpen]);
|
|
|
|
useEffect(() => {
|
|
if (countdown === 0) {
|
|
window.location.href = baseUrl;
|
|
}
|
|
}, [countdown]);
|
|
|
|
const handleRestart = () => {
|
|
setRestartingSheetOpen(true);
|
|
onRestart();
|
|
};
|
|
|
|
const handleForceReload = () => {
|
|
window.location.href = baseUrl;
|
|
};
|
|
|
|
return (
|
|
<>
|
|
<AlertDialog
|
|
open={restartDialogOpen}
|
|
onOpenChange={(open) => {
|
|
if (!open) {
|
|
setRestartDialogOpen(false);
|
|
onClose();
|
|
clearBodyPointerEvents();
|
|
}
|
|
}}
|
|
>
|
|
<AlertDialogContent
|
|
onCloseAutoFocus={(event) => {
|
|
event.preventDefault();
|
|
clearBodyPointerEvents();
|
|
}}
|
|
>
|
|
<AlertDialogHeader>
|
|
<AlertDialogTitle>{t("restart.title")}</AlertDialogTitle>
|
|
<AlertDialogDescription className="sr-only">
|
|
{t("restart.description")}
|
|
</AlertDialogDescription>
|
|
</AlertDialogHeader>
|
|
<AlertDialogFooter>
|
|
<AlertDialogCancel>
|
|
{t("button.cancel", { ns: "common" })}
|
|
</AlertDialogCancel>
|
|
<AlertDialogAction onClick={handleRestart}>
|
|
{t("restart.button")}
|
|
</AlertDialogAction>
|
|
</AlertDialogFooter>
|
|
</AlertDialogContent>
|
|
</AlertDialog>
|
|
|
|
<Sheet
|
|
open={restartingSheetOpen}
|
|
onOpenChange={() => setRestartingSheetOpen(false)}
|
|
>
|
|
<SheetContent
|
|
side="top"
|
|
onInteractOutside={(e) => e.preventDefault()}
|
|
className="[&>button:first-of-type]:hidden"
|
|
>
|
|
<div className="flex flex-col items-center">
|
|
<ActivityIndicator />
|
|
<SheetHeader className="mt-5 text-center">
|
|
<SheetTitle className="text-center">
|
|
{t("restart.restarting.title")}
|
|
</SheetTitle>
|
|
<SheetDescription className="text-center">
|
|
<div>
|
|
{t("restart.restarting.content", {
|
|
countdown,
|
|
})}
|
|
</div>
|
|
</SheetDescription>
|
|
</SheetHeader>
|
|
<Button
|
|
size="lg"
|
|
className="mt-5"
|
|
aria-label={t("restart.restarting.button")}
|
|
onClick={handleForceReload}
|
|
>
|
|
{t("restart.restarting.button")}
|
|
</Button>
|
|
</div>
|
|
</SheetContent>
|
|
</Sheet>
|
|
</>
|
|
);
|
|
}
|