From fff14f7dc61382804f7a27e333d2e8fbbef6d681 Mon Sep 17 00:00:00 2001
From: spacebares <57186372+spacebares@users.noreply.github.com>
Date: Tue, 27 Jun 2023 17:27:49 -0400
Subject: [PATCH] support multiple viewmodes for UI options and menus
---
frigate/config.py | 12 +++++++++---
web/src/AppBar.jsx | 26 +++++++++++++++++++-------
web/src/Sidebar.jsx | 19 ++++++++++++-------
web/src/app.tsx | 6 +++---
web/src/components/AppBar.jsx | 17 +----------------
web/src/components/Menu.jsx | 3 ++-
web/src/components/ViewOption.jsx | 12 ++++++++++++
web/src/components/ViewOptionEnum.tsx | 5 +++++
web/src/context/index.jsx | 19 ++++++++++---------
web/src/routes/Camera.jsx | 8 +++++---
web/src/routes/Cameras.jsx | 7 ++++---
web/src/routes/Events.jsx | 16 ++++++++--------
web/src/routes/System.jsx | 8 +++-----
13 files changed, 93 insertions(+), 65 deletions(-)
create mode 100644 web/src/components/ViewOption.jsx
create mode 100644 web/src/components/ViewOptionEnum.tsx
diff --git a/frigate/config.py b/frigate/config.py
index 14b94a82d..c91e75da4 100644
--- a/frigate/config.py
+++ b/frigate/config.py
@@ -67,6 +67,12 @@ class DateTimeStyleEnum(str, Enum):
short = "short"
+class ViewModeEnum(str, Enum):
+ user = "user"
+ advanced = "advanced"
+ admin = "admin"
+
+
class UIConfig(FrigateBaseModel):
live_mode: LiveModeEnum = Field(
default=LiveModeEnum.mse, title="Default Live Mode."
@@ -85,9 +91,9 @@ class UIConfig(FrigateBaseModel):
strftime_fmt: Optional[str] = Field(
default=None, title="Override date and time format using strftime syntax."
)
- show_advanced_options: bool = Field(
- default=True,
- title="Default setting to show Advanced Options, such as Config, Camera Rec/Motion/Snap buttons, go2rtc dashboard and more.",
+ viewmode: ViewModeEnum = Field(
+ default=ViewModeEnum.admin,
+ title="Default setting to display or hide certain options and menus in Frigate.",
)
diff --git a/web/src/AppBar.jsx b/web/src/AppBar.jsx
index fc57458cb..6c4b047ce 100644
--- a/web/src/AppBar.jsx
+++ b/web/src/AppBar.jsx
@@ -8,15 +8,16 @@ import DarkModeIcon from './icons/DarkMode';
import SettingsIcon from './icons/Settings';
import FrigateRestartIcon from './icons/FrigateRestart';
import Prompt from './components/Prompt';
-import { useDarkMode, useAdvOptions } from './context';
+import { useDarkMode, useViewMode } from './context';
import { useCallback, useRef, useState } from 'preact/hooks';
import { useRestart } from './api/ws';
+import { ViewModeTypes } from './components/ViewOptionEnum'
export default function AppBar() {
const [showMoreMenu, setShowMoreMenu] = useState(false);
const [showDialog, setShowDialog] = useState(false);
const [showDialogWait, setShowDialogWait] = useState(false);
- const { showAdvOptions, setShowAdvOptions } = useAdvOptions();
+ const { viewMode, setViewMode } = useViewMode();
const { setDarkMode } = useDarkMode();
const { send: sendRestart } = useRestart();
@@ -28,10 +29,13 @@ export default function AppBar() {
[setDarkMode, setShowMoreMenu]
);
- const handleToggleAdvOptions = useCallback(() => {
- setShowAdvOptions(showAdvOptions === 1 ? 0 : 1);
- setShowMoreMenu(false);
- },[showAdvOptions, setShowAdvOptions, setShowMoreMenu]);
+ const handleSetViewMode = useCallback(
+ (value) => {
+ setViewMode(value);
+ setShowMoreMenu(false);
+ },
+ [setViewMode, setShowMoreMenu]
+ );
const moreRef = useRef(null);
@@ -68,7 +72,15 @@ export default function AppBar() {