forked from blakeblackshear/frigate
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'blakeblackshear:dev' into dev
- Loading branch information
Showing
5 changed files
with
144 additions
and
108 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,122 @@ | ||
import { useState, useEffect } from "react"; | ||
import { | ||
AlertDialog, | ||
AlertDialogAction, | ||
AlertDialogCancel, | ||
AlertDialogContent, | ||
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"; | ||
|
||
type RestartDialogProps = { | ||
isOpen: boolean; | ||
onClose: () => void; | ||
onRestart: () => void; | ||
}; | ||
|
||
export default function RestartDialog({ | ||
isOpen, | ||
onClose, | ||
onRestart, | ||
}: RestartDialogProps) { | ||
const [restartDialogOpen, setRestartDialogOpen] = useState(isOpen); | ||
const [restartingSheetOpen, setRestartingSheetOpen] = useState(false); | ||
const [countdown, setCountdown] = useState(60); | ||
|
||
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={() => { | ||
setRestartDialogOpen(false); | ||
onClose(); | ||
}} | ||
> | ||
<AlertDialogContent> | ||
<AlertDialogHeader> | ||
<AlertDialogTitle> | ||
Are you sure you want to restart Frigate? | ||
</AlertDialogTitle> | ||
</AlertDialogHeader> | ||
<AlertDialogFooter> | ||
<AlertDialogCancel>Cancel</AlertDialogCancel> | ||
<AlertDialogAction onClick={handleRestart}> | ||
Restart | ||
</AlertDialogAction> | ||
</AlertDialogFooter> | ||
</AlertDialogContent> | ||
</AlertDialog> | ||
|
||
<Sheet | ||
open={restartingSheetOpen} | ||
onOpenChange={() => setRestartingSheetOpen(false)} | ||
> | ||
<SheetContent side="top" onInteractOutside={(e) => e.preventDefault()}> | ||
<div className="flex flex-col items-center"> | ||
<ActivityIndicator /> | ||
<SheetHeader className="mt-5 text-center"> | ||
<SheetTitle className="text-center"> | ||
Frigate is Restarting | ||
</SheetTitle> | ||
<SheetDescription className="text-center"> | ||
<div>This page will reload in {countdown} seconds.</div> | ||
</SheetDescription> | ||
</SheetHeader> | ||
<Button | ||
size="lg" | ||
className="mt-5" | ||
aria-label="Force reload now" | ||
onClick={handleForceReload} | ||
> | ||
Force Reload Now | ||
</Button> | ||
</div> | ||
</SheetContent> | ||
</Sheet> | ||
</> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters