From 1af103d5eee026199be33d4f24b13d742b9b6996 Mon Sep 17 00:00:00 2001 From: proddy Date: Sun, 17 Mar 2024 23:23:09 +0100 Subject: [PATCH] updates to web pages --- .vscode/settings.json | 5 +- interface/src/AuthenticatedRouting.tsx | 79 ++++++++----------- .../src/components/layout/LayoutMenu.tsx | 20 +++-- interface/src/framework/ap/AccessPoint.tsx | 6 +- interface/src/framework/mqtt/Mqtt.tsx | 5 +- .../framework/network/NetworkConnection.tsx | 8 +- interface/src/framework/ntp/NTPStatusForm.tsx | 6 +- interface/src/framework/ntp/NetworkTime.tsx | 5 +- .../security/SecuritySettingsForm.tsx | 2 +- interface/src/framework/system/SystemLog.tsx | 2 +- .../src/framework/system/SystemStatusForm.tsx | 21 ++--- .../system/SystemStatusVersionDialog.tsx | 2 +- .../src/framework/system/UploadDownload.tsx | 7 +- interface/src/i18n/en/index.ts | 2 +- interface/src/project/DeviceIcon.tsx | 7 +- interface/src/project/Devices.tsx | 15 +--- interface/src/project/EMSStatus.tsx | 29 +++---- interface/src/project/Sensors.tsx | 22 ++---- mock-api/handler.ts | 13 ++- mock-api/server.js | 2 +- src/emsesp.cpp | 2 +- src/locale_translations.h | 3 +- 22 files changed, 121 insertions(+), 142 deletions(-) diff --git a/.vscode/settings.json b/.vscode/settings.json index 38fe48929..493bf41fe 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -84,5 +84,8 @@ "**/*.map", "**/ArduinoJson/**" ], - "cSpell.enableFiletypes": ["!cpp"] + "cSpell.enableFiletypes": [ + "!cpp", + "!typescript" + ] } \ No newline at end of file diff --git a/interface/src/AuthenticatedRouting.tsx b/interface/src/AuthenticatedRouting.tsx index a05573e2a..689a325c2 100644 --- a/interface/src/AuthenticatedRouting.tsx +++ b/interface/src/AuthenticatedRouting.tsx @@ -1,7 +1,8 @@ +import { useContext, type FC } from 'react'; import { Navigate, Routes, Route } from 'react-router-dom'; import Help from './project/Help'; -import type { FC } from 'react'; -import { Layout, RequireAdmin } from 'components'; +import { Layout } from 'components'; +import { AuthenticatedContext } from 'contexts/authentication'; import Settings from 'framework/Settings'; import AccessPoint from 'framework/ap/AccessPoint'; import Mqtt from 'framework/mqtt/Mqtt'; @@ -18,49 +19,35 @@ import Devices from 'project/Devices'; import Scheduler from 'project/Scheduler'; import Sensors from 'project/Sensors'; -const AuthenticatedRouting: FC = () => ( - - - } /> - } /> - - } /> - } /> - } /> - - {/* TODO only show the rest here if admin */} - - } /> - - - - - } - /> - } /> - } /> - } /> - } /> - } /> - } /> - - - - } - /> - } /> - - } /> - - } /> - - -); +const AuthenticatedRouting: FC = () => { + const { me } = useContext(AuthenticatedContext); + return ( + + + } /> + } /> + } /> + } /> + } /> + {me.admin && ( + <> + } /> + } /> + } /> + } /> + } /> + } /> + } /> + } /> + } /> + } /> + } /> + } /> + + )} + + + ); +}; export default AuthenticatedRouting; diff --git a/interface/src/components/layout/LayoutMenu.tsx b/interface/src/components/layout/LayoutMenu.tsx index 49c46cb4c..9a43749c1 100644 --- a/interface/src/components/layout/LayoutMenu.tsx +++ b/interface/src/components/layout/LayoutMenu.tsx @@ -2,7 +2,7 @@ import AccountCircleIcon from '@mui/icons-material/AccountCircle'; import AssessmentIcon from '@mui/icons-material/Assessment'; import CategoryIcon from '@mui/icons-material/Category'; import ConstructionIcon from '@mui/icons-material/Construction'; -import InfoIcon from '@mui/icons-material/Info'; +import LiveHelpIcon from '@mui/icons-material/LiveHelp'; import MoreTimeIcon from '@mui/icons-material/MoreTime'; import PersonIcon from '@mui/icons-material/Person'; import PlaylistAddIcon from '@mui/icons-material/PlaylistAdd'; @@ -73,14 +73,24 @@ const LayoutMenu: FC = () => { - - - + + + - + diff --git a/interface/src/framework/ap/AccessPoint.tsx b/interface/src/framework/ap/AccessPoint.tsx index 0aa655f84..e8b14bbf2 100644 --- a/interface/src/framework/ap/AccessPoint.tsx +++ b/interface/src/framework/ap/AccessPoint.tsx @@ -1,12 +1,10 @@ import { Tab } from '@mui/material'; -import { useContext } from 'react'; import { Navigate, Routes, Route } from 'react-router-dom'; import APSettingsForm from './APSettingsForm'; import APStatusForm from './APStatusForm'; import type { FC } from 'react'; import { RequireAdmin, RouterTabs, useLayoutTitle, useRouterTab } from 'components'; -import { AuthenticatedContext } from 'contexts/authentication'; import { useI18nContext } from 'i18n/i18n-react'; @@ -15,14 +13,12 @@ const AccessPoint: FC = () => { useLayoutTitle(LL.ACCESS_POINT(0)); - const authenticatedContext = useContext(AuthenticatedContext); - const { routerTab } = useRouterTab(); return ( <> - + diff --git a/interface/src/framework/mqtt/Mqtt.tsx b/interface/src/framework/mqtt/Mqtt.tsx index 59779948f..0ef430924 100644 --- a/interface/src/framework/mqtt/Mqtt.tsx +++ b/interface/src/framework/mqtt/Mqtt.tsx @@ -1,12 +1,10 @@ import { Tab } from '@mui/material'; -import { useContext } from 'react'; import { Navigate, Route, Routes } from 'react-router-dom'; import MqttSettingsForm from './MqttSettingsForm'; import MqttStatusForm from './MqttStatusForm'; import type { FC } from 'react'; import { RequireAdmin, RouterTabs, useLayoutTitle, useRouterTab } from 'components'; -import { AuthenticatedContext } from 'contexts/authentication'; import { useI18nContext } from 'i18n/i18n-react'; @@ -15,13 +13,12 @@ const Mqtt: FC = () => { useLayoutTitle('MQTT'); - const authenticatedContext = useContext(AuthenticatedContext); const { routerTab } = useRouterTab(); return ( <> - + diff --git a/interface/src/framework/network/NetworkConnection.tsx b/interface/src/framework/network/NetworkConnection.tsx index 4d676324e..2e093ac3b 100644 --- a/interface/src/framework/network/NetworkConnection.tsx +++ b/interface/src/framework/network/NetworkConnection.tsx @@ -1,5 +1,5 @@ import { Tab } from '@mui/material'; -import { useCallback, useContext, useState } from 'react'; +import { useCallback, useState } from 'react'; import { Navigate, Routes, Route, useNavigate } from 'react-router-dom'; import NetworkSettingsForm from './NetworkSettingsForm'; import NetworkStatusForm from './NetworkStatusForm'; @@ -9,7 +9,6 @@ import type { FC } from 'react'; import type { WiFiNetwork } from 'types'; import { RequireAdmin, RouterTabs, useLayoutTitle, useRouterTab } from 'components'; -import { AuthenticatedContext } from 'contexts/authentication'; import { useI18nContext } from 'i18n/i18n-react'; const NetworkConnection: FC = () => { @@ -18,7 +17,6 @@ const NetworkConnection: FC = () => { const { routerTab } = useRouterTab(); - const authenticatedContext = useContext(AuthenticatedContext); const navigate = useNavigate(); const [selectedNetwork, setSelectedNetwork] = useState(); @@ -44,8 +42,8 @@ const NetworkConnection: FC = () => { }} > - - + + diff --git a/interface/src/framework/ntp/NTPStatusForm.tsx b/interface/src/framework/ntp/NTPStatusForm.tsx index bf5122369..38f76be31 100644 --- a/interface/src/framework/ntp/NTPStatusForm.tsx +++ b/interface/src/framework/ntp/NTPStatusForm.tsx @@ -22,7 +22,7 @@ import { Typography } from '@mui/material'; import { useRequest } from 'alova'; -import { useContext, useState } from 'react'; +import { useState } from 'react'; import { toast } from 'react-toastify'; import type { Theme } from '@mui/material'; import type { FC } from 'react'; @@ -31,7 +31,6 @@ import type { NTPStatus } from 'types'; import { dialogStyle } from 'CustomTheme'; import * as NTPApi from 'api/ntp'; import { ButtonRow, FormLoader, SectionContent } from 'components'; -import { AuthenticatedContext } from 'contexts/authentication'; import { useI18nContext } from 'i18n/i18n-react'; import { NTPSyncStatus } from 'types'; @@ -59,7 +58,6 @@ const NTPStatusForm: FC = () => { const [localTime, setLocalTime] = useState(''); const [settingTime, setSettingTime] = useState(false); const [processing, setProcessing] = useState(false); - const { me } = useContext(AuthenticatedContext); const { LL } = useI18nContext(); @@ -201,7 +199,7 @@ const NTPStatusForm: FC = () => { - {me.admin && data && !isNtpActive(data) && ( + {data && !isNtpActive(data) && (