diff --git a/src/client/components/gauge.tsx b/src/client/components/gauge.tsx index f8443ff..71ed324 100644 --- a/src/client/components/gauge.tsx +++ b/src/client/components/gauge.tsx @@ -22,7 +22,7 @@ type Props = { export default function Gauge(props: Props) { const { percentage, invert, title, onClick } = props - const { theme: systemTheme } = useContext(ThemeContext) + const { theme } = useContext(ThemeContext) return ( diff --git a/src/client/components/line-chart.tsx b/src/client/components/line-chart.tsx index 03037d6..bde5dd6 100644 --- a/src/client/components/line-chart.tsx +++ b/src/client/components/line-chart.tsx @@ -7,11 +7,8 @@ import { ChartsReferenceLine } from '@mui/x-charts/ChartsReferenceLine' import { LinePlot, MarkPlot } from '@mui/x-charts/LineChart' import { ChartsXAxis } from '@mui/x-charts/ChartsXAxis' import { ChartsYAxis } from '@mui/x-charts/ChartsYAxis' -import { ThemeProvider, createTheme } from '@mui/material/styles' -import CssBaseline from '@mui/material/CssBaseline' import { useTranslation } from 'react-i18next' import { LanguageContext } from '@/client/context/language' -import { ThemeContext } from '../context/theme' type Props = { id: string @@ -24,12 +21,6 @@ type Props = { export default function LineChart(props: Props) { const { id, inputVoltage, inputVoltageNominal, outputVoltage, updated } = props const lng = useContext(LanguageContext) - const { theme } = useContext(ThemeContext) - const darkTheme = createTheme({ - palette: { - mode: theme, - }, - }) const { t } = useTranslation(lng) const [inputVoltageData, setInputVoltageData] = useState>([]) const [outputVoltageData, setOutputVoltageData] = useState>([]) @@ -49,47 +40,44 @@ export default function LineChart(props: Props) { }, [id, inputVoltage, outputVoltage, updated]) return ( - - - + index) }]} + yAxis={[ + { + scaleType: 'linear', + valueFormatter: (value: number) => `${value}V`, + min: inputVoltageNominal + ? Math.min(...inputVoltageData, ...outputVoltageData, inputVoltageNominal) + : Math.min(...inputVoltageData, ...outputVoltageData), + max: inputVoltageNominal + ? Math.max(...inputVoltageData, ...outputVoltageData, inputVoltageNominal) + : Math.max(...inputVoltageData, ...outputVoltageData), + }, + ]} > - index) }]} - yAxis={[ - { - scaleType: 'linear', - valueFormatter: (value: number) => `${value}V`, - min: inputVoltageNominal - ? Math.min(...inputVoltageData, ...outputVoltageData, inputVoltageNominal) - : Math.min(...inputVoltageData, ...outputVoltageData), - max: inputVoltageNominal - ? Math.max(...inputVoltageData, ...outputVoltageData, inputVoltageNominal) - : Math.max(...inputVoltageData, ...outputVoltageData), - }, - ]} - > - - - {inputVoltageNominal && ( - - )} - - - - - - - + + + {inputVoltageNominal && ( + + )} + + + + + + ) } diff --git a/src/client/components/watts-chart.tsx b/src/client/components/watts-chart.tsx index 24b6ba5..01d6968 100644 --- a/src/client/components/watts-chart.tsx +++ b/src/client/components/watts-chart.tsx @@ -7,11 +7,8 @@ import { ChartsReferenceLine } from '@mui/x-charts/ChartsReferenceLine' import { LinePlot, MarkPlot } from '@mui/x-charts/LineChart' import { ChartsXAxis } from '@mui/x-charts/ChartsXAxis' import { ChartsYAxis } from '@mui/x-charts/ChartsYAxis' -import { ThemeProvider, createTheme } from '@mui/material/styles' -import CssBaseline from '@mui/material/CssBaseline' import { useTranslation } from 'react-i18next' import { LanguageContext } from '@/client/context/language' -import { ThemeContext } from '../context/theme' type Props = { id: string @@ -25,12 +22,6 @@ export default function WattsChart(props: Props) { const [dataPoints, setDataPoints] = useState>([]) const prevDataRef = useRef(id) const lng = useContext(LanguageContext) - const { theme } = useContext(ThemeContext) - const darkTheme = createTheme({ - palette: { - mode: theme, - }, - }) const { t } = useTranslation(lng) useEffect(() => { @@ -44,40 +35,37 @@ export default function WattsChart(props: Props) { }, [id, realpower, updated]) return ( - - - + index) }]} + yAxis={[ + { + scaleType: 'linear', + valueFormatter: (value: number) => `${value}V`, + min: realpowerNominal ? Math.min(...dataPoints, realpowerNominal) : Math.min(...dataPoints), + max: realpowerNominal ? Math.max(...dataPoints, realpowerNominal) : Math.max(...dataPoints), + }, + ]} > - index) }]} - yAxis={[ - { - scaleType: 'linear', - valueFormatter: (value: number) => `${value}V`, - min: realpowerNominal ? Math.min(...dataPoints, realpowerNominal) : Math.min(...dataPoints), - max: realpowerNominal ? Math.max(...dataPoints, realpowerNominal) : Math.max(...dataPoints), - }, - ]} - > - - - {realpowerNominal && ( - - )} - - - - - - - + + + {realpowerNominal && ( + + )} + + + + + + ) } diff --git a/src/client/components/wrapper.tsx b/src/client/components/wrapper.tsx index 40086f5..de1a87d 100644 --- a/src/client/components/wrapper.tsx +++ b/src/client/components/wrapper.tsx @@ -12,6 +12,8 @@ import { ExclamationCircleIcon as ExclamationCircleIconSolid } from '@heroicons/ import { Button } from '@material-tailwind/react' import { useTranslation } from 'react-i18next' import { useRouter } from 'next/navigation' +import { ThemeProvider, createTheme } from '@mui/material/styles' +import CssBaseline from '@mui/material/CssBaseline' import { MemoizedGrid } from '@/client/components/grid' import Gauge from '@/client/components/gauge' @@ -23,6 +25,7 @@ import Loader from '@/client/components/loader' import ChartsContainer from '@/client/components/charts-container' import { LanguageContext } from '@/client/context/language' +import { ThemeContext } from '@/client/context/theme' import { upsStatus } from '@/common/constants' import { DEVICE, DeviceData } from '@/common/types' @@ -59,6 +62,12 @@ export default function Wrapper({ getDevicesAction, checkSettingsAction, disconn const lng = useContext(LanguageContext) const { t } = useTranslation(lng) const router = useRouter() + const { theme } = useContext(ThemeContext) + const materialTheme = createTheme({ + palette: { + mode: theme, + }, + }) const { isLoading, data, refetch } = useQuery({ queryKey: ['devicesData'], queryFn: async () => await getDevicesAction(), @@ -207,65 +216,68 @@ export default function Wrapper({ getDevicesAction, checkSettingsAction, disconn } return ( -
- refetch()} - onRefetch={() => refetch()} - onDeviceChange={(name: string) => - data.devices && setPreferredDevice(data.devices.findIndex((d: DEVICE) => d.name === name)) - } - onDisconnect={handleDisconnect} - devices={data.devices} - /> -
-
-
-
- {vars['ups.mfr']?.value || vars['ups.model']?.value ? ( - <> -

- {t('manufacturer')}: {vars['ups.mfr']?.value} -

-

- {t('model')}: {vars['ups.model']?.value} -

- - ) : ( - <> -

- {t('device')}: {ups.description} -

- - )} -

- {t('serial')}: {vars['device.serial']?.value} -

+ + +
+ refetch()} + onRefetch={() => refetch()} + onDeviceChange={(name: string) => + data.devices && setPreferredDevice(data.devices.findIndex((d: DEVICE) => d.name === name)) + } + onDisconnect={handleDisconnect} + devices={data.devices} + /> +
+
+
+
+ {vars['ups.mfr']?.value || vars['ups.model']?.value ? ( + <> +

+ {t('manufacturer')}: {vars['ups.mfr']?.value} +

+

+ {t('model')}: {vars['ups.model']?.value} +

+ + ) : ( + <> +

+ {t('device')}: {ups.description} +

+ + )} +

+ {t('serial')}: {vars['device.serial']?.value} +

+
+
+

+ {getStatus(vars['ups.status']?.value as keyof typeof upsStatus)} +  {upsStatus[vars['ups.status']?.value as keyof typeof upsStatus]} +

+
-
-

- {getStatus(vars['ups.status']?.value as keyof typeof upsStatus)} -  {upsStatus[vars['ups.status']?.value as keyof typeof upsStatus]} -

+
+
{currentLoad()}
+
{currentWh()}
+
+ +
-
-
-
{currentLoad()}
-
{currentWh()}
+
- +
+
- -
- -
-
-
+
) }