mirror of
https://github.com/blakeblackshear/frigate.git
synced 2025-01-21 00:06:44 +01:00
Add ability to restart
This commit is contained in:
parent
a2d5754e4b
commit
436b10a87b
@ -5,12 +5,18 @@ import Menu, { MenuItem, MenuSeparator } from './components/Menu';
|
|||||||
import AutoAwesomeIcon from './icons/AutoAwesome';
|
import AutoAwesomeIcon from './icons/AutoAwesome';
|
||||||
import LightModeIcon from './icons/LightMode';
|
import LightModeIcon from './icons/LightMode';
|
||||||
import DarkModeIcon from './icons/DarkMode';
|
import DarkModeIcon from './icons/DarkMode';
|
||||||
|
import FrigateRestartIcon from './icons/FrigateRestart';
|
||||||
|
import Dialog from './components/Dialog';
|
||||||
import { useDarkMode } from './context';
|
import { useDarkMode } from './context';
|
||||||
import { useCallback, useRef, useState } from 'preact/hooks';
|
import { useCallback, useRef, useState } from 'preact/hooks';
|
||||||
|
import { useRestart } from './api/mqtt';
|
||||||
|
|
||||||
export default function AppBar() {
|
export default function AppBar() {
|
||||||
const [showMoreMenu, setShowMoreMenu] = useState(false);
|
const [showMoreMenu, setShowMoreMenu] = useState(false);
|
||||||
|
const [showDialog, setShowDialog] = useState(false);
|
||||||
|
const [showDialogWait, setShowDialogWait] = useState(false);
|
||||||
const { setDarkMode } = useDarkMode();
|
const { setDarkMode } = useDarkMode();
|
||||||
|
const { send: sendRestart } = useRestart();
|
||||||
|
|
||||||
const handleSelectDarkMode = useCallback(
|
const handleSelectDarkMode = useCallback(
|
||||||
(value, label) => {
|
(value, label) => {
|
||||||
@ -30,6 +36,21 @@ export default function AppBar() {
|
|||||||
setShowMoreMenu(false);
|
setShowMoreMenu(false);
|
||||||
}, [setShowMoreMenu]);
|
}, [setShowMoreMenu]);
|
||||||
|
|
||||||
|
const handleClickRestartDialog = useCallback(() => {
|
||||||
|
setShowDialog(false);
|
||||||
|
setShowDialogWait(true);
|
||||||
|
sendRestart();
|
||||||
|
}, [setShowDialog]);
|
||||||
|
|
||||||
|
const handleDismissRestartDialog = () => {
|
||||||
|
setShowDialog(false);
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleRestart = useCallback(() => {
|
||||||
|
setShowMoreMenu(false);
|
||||||
|
setShowDialog(true);
|
||||||
|
});
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Fragment>
|
<Fragment>
|
||||||
<BaseAppBar title={LinkedLogo} overflowRef={moreRef} onOverflowClick={handleShowMenu} />
|
<BaseAppBar title={LinkedLogo} overflowRef={moreRef} onOverflowClick={handleShowMenu} />
|
||||||
@ -39,7 +60,26 @@ export default function AppBar() {
|
|||||||
<MenuSeparator />
|
<MenuSeparator />
|
||||||
<MenuItem icon={LightModeIcon} label="Light" value="light" onSelect={handleSelectDarkMode} />
|
<MenuItem icon={LightModeIcon} label="Light" value="light" onSelect={handleSelectDarkMode} />
|
||||||
<MenuItem icon={DarkModeIcon} label="Dark" value="dark" onSelect={handleSelectDarkMode} />
|
<MenuItem icon={DarkModeIcon} label="Dark" value="dark" onSelect={handleSelectDarkMode} />
|
||||||
|
<MenuSeparator />
|
||||||
|
<MenuItem icon={FrigateRestartIcon} label="Restart Frigate" onSelect={handleRestart} />
|
||||||
</Menu>
|
</Menu>
|
||||||
|
) : null},
|
||||||
|
{showDialog ? (
|
||||||
|
<Dialog
|
||||||
|
onDismiss={handleDismissRestartDialog}
|
||||||
|
title="Restart Frigate"
|
||||||
|
text="Are you sure ?"
|
||||||
|
actions={[
|
||||||
|
{ text: "Yes", color: "red", onClick: handleClickRestartDialog },
|
||||||
|
{ text: "Cancel", onClick: handleDismissRestartDialog },
|
||||||
|
]}
|
||||||
|
/>
|
||||||
|
) : null},
|
||||||
|
{showDialogWait ? (
|
||||||
|
<Dialog
|
||||||
|
title="Restart in progress"
|
||||||
|
text="Please wait a few seconds for the restart to complete before reloading the page."
|
||||||
|
/>
|
||||||
) : null}
|
) : null}
|
||||||
</Fragment>
|
</Fragment>
|
||||||
);
|
);
|
||||||
|
Loading…
Reference in New Issue
Block a user