From 2254bf9c1664cee1a3acdf0d405317d49294200a Mon Sep 17 00:00:00 2001 From: Proddy Date: Sat, 29 Apr 2023 15:35:54 +0200 Subject: [PATCH] fix eslint warnings --- interface/src/framework/system/SystemLog.tsx | 6 +++--- interface/src/i18n/formatters.ts | 2 +- interface/src/project/DashboardDevices.tsx | 20 ++++++++++--------- interface/src/project/DashboardSensors.tsx | 18 +++++++++-------- .../project/DashboardSensorsAnalogDialog.tsx | 4 ++-- interface/src/project/DashboardStatus.tsx | 2 +- interface/src/project/SettingsEntities.tsx | 2 +- interface/src/project/SettingsScheduler.tsx | 1 - interface/src/utils/useWs.ts | 1 + mock-api/server.js | 1 + 10 files changed, 31 insertions(+), 26 deletions(-) diff --git a/interface/src/framework/system/SystemLog.tsx b/interface/src/framework/system/SystemLog.tsx index 8390e7d37..8d44f7603 100644 --- a/interface/src/framework/system/SystemLog.tsx +++ b/interface/src/framework/system/SystemLog.tsx @@ -31,7 +31,7 @@ const useWindowSize = () => { return size; }; -const LogEntryLine = styled('div')(({ theme }) => ({ +const LogEntryLine = styled('div')(() => ({ color: '#bbbbbb', fontFamily: 'monospace', fontSize: '14px', @@ -125,7 +125,7 @@ const SystemLog: FC = () => { useEffect(() => { void fetchLog(); - }, []); + }, [fetchLog]); useEffect(() => { const es = new EventSource(addAccessTokenParameter(LOG_EVENTSOURCE_URL)); @@ -138,7 +138,7 @@ const SystemLog: FC = () => { return () => { es.close(); }; - }, []); + }); const saveSettings = async () => { if (data) { diff --git a/interface/src/i18n/formatters.ts b/interface/src/i18n/formatters.ts index 592a53490..6818d3da7 100644 --- a/interface/src/i18n/formatters.ts +++ b/interface/src/i18n/formatters.ts @@ -1,7 +1,7 @@ import type { Locales, Formatters } from './i18n-types'; import type { FormattersInitializer } from 'typesafe-i18n'; -export const initFormatters: FormattersInitializer = (locale: Locales) => { +export const initFormatters: FormattersInitializer = () => { const formatters: Formatters = { // add your formatter functions here }; diff --git a/interface/src/project/DashboardDevices.tsx b/interface/src/project/DashboardDevices.tsx index 1760f22b1..51e55f1e0 100644 --- a/interface/src/project/DashboardDevices.tsx +++ b/interface/src/project/DashboardDevices.tsx @@ -27,7 +27,7 @@ import { useRowSelect } from '@table-library/react-table-library/select'; import { useSort, SortToggleType } from '@table-library/react-table-library/sort'; import { Table, Header, HeaderRow, HeaderCell, Body, Row, Cell } from '@table-library/react-table-library/table'; import { useTheme } from '@table-library/react-table-library/theme'; -import { useState, useContext, useEffect } from 'react'; +import { useState, useContext, useEffect, useCallback } from 'react'; import { IconContext } from 'react-icons'; import { toast } from 'react-toastify'; @@ -183,24 +183,26 @@ const DashboardDevices: FC = () => { ); const fetchDeviceData = async (id: number) => { - try { - setDeviceData((await EMSESP.readDeviceData({ id })).data); - } catch (error) { - toast.error(extractErrorMessage(error, LL.PROBLEM_LOADING())); + if (!deviceValueDialogOpen) { + try { + setDeviceData((await EMSESP.readDeviceData({ id })).data); + } catch (error) { + toast.error(extractErrorMessage(error, LL.PROBLEM_LOADING())); + } } }; - const fetchCoreData = async () => { + const fetchCoreData = useCallback(async () => { try { setCoreData((await EMSESP.readCoreData()).data); } catch (error) { toast.error(extractErrorMessage(error, LL.PROBLEM_LOADING())); } - }; + }, [LL]); useEffect(() => { void fetchCoreData(); - }, []); + }, [fetchCoreData]); const refreshData = () => { if (selectedDevice) { @@ -280,7 +282,7 @@ const DashboardDevices: FC = () => { return () => { clearInterval(timer); }; - }, []); + }); const deviceValueDialogSave = async (dv: DeviceValue) => { try { diff --git a/interface/src/project/DashboardSensors.tsx b/interface/src/project/DashboardSensors.tsx index 2ac954ec2..b43cf91b6 100644 --- a/interface/src/project/DashboardSensors.tsx +++ b/interface/src/project/DashboardSensors.tsx @@ -102,16 +102,18 @@ const DashboardSensors: FC = () => { ]); const fetchSensorData = useCallback(async () => { - try { - setSensorData((await EMSESP.readSensorData()).data); - } catch (error) { - toast.error(extractErrorMessage(error, LL.PROBLEM_LOADING())); + if (!analogDialogOpen && !temperatureDialogOpen) { + try { + setSensorData((await EMSESP.readSensorData()).data); + } catch (error) { + toast.error(extractErrorMessage(error, LL.PROBLEM_LOADING())); + } } - }, [LL]); + }, [LL, analogDialogOpen, temperatureDialogOpen]); useEffect(() => { void fetchSensorData(); - }, []); + }, [fetchSensorData]); const getSortIcon = (state: any, sortKey: any) => { if (state.sortKey === sortKey && state.reverse) { @@ -160,11 +162,11 @@ const DashboardSensors: FC = () => { ); useEffect(() => { - const timer = setInterval(() => fetchSensorData(), 60000); + const timer = setInterval(() => fetchSensorData(), 30000); return () => { clearInterval(timer); }; - }, [fetchSensorData]); + }); const formatDurationMin = (duration_min: number) => { const days = Math.trunc((duration_min * 60000) / 86400000); diff --git a/interface/src/project/DashboardSensorsAnalogDialog.tsx b/interface/src/project/DashboardSensorsAnalogDialog.tsx index 2964e4f5f..35d4a0b44 100644 --- a/interface/src/project/DashboardSensorsAnalogDialog.tsx +++ b/interface/src/project/DashboardSensorsAnalogDialog.tsx @@ -213,7 +213,7 @@ const DashboardSensorsAnalogDialog = ({ name="f" label={LL.FREQ()} value={numberValue(editItem.f)} - // fullWidth + fullWidth type="number" variant="outlined" onChange={updateFormValue} @@ -228,7 +228,7 @@ const DashboardSensorsAnalogDialog = ({ name="o" label={LL.DUTY_CYCLE()} value={numberValue(editItem.o)} - // fullWidth + fullWidth type="number" variant="outlined" onChange={updateFormValue} diff --git a/interface/src/project/DashboardStatus.tsx b/interface/src/project/DashboardStatus.tsx index 3c23a6adb..887a142d8 100644 --- a/interface/src/project/DashboardStatus.tsx +++ b/interface/src/project/DashboardStatus.tsx @@ -116,7 +116,7 @@ const DashboardStatus: FC = () => { return () => { clearInterval(timer); }; - }, []); + }); const showName = (id: any) => { const name: keyof Translation['STATUS_NAMES'] = id; diff --git a/interface/src/project/SettingsEntities.tsx b/interface/src/project/SettingsEntities.tsx index 0da5ff8e8..8093107ac 100644 --- a/interface/src/project/SettingsEntities.tsx +++ b/interface/src/project/SettingsEntities.tsx @@ -130,7 +130,7 @@ const SettingsEntities: FC = () => { useEffect(() => { void fetchEntities(); - }, []); + }, [fetchEntities]); const saveEntities = async () => { if (entities) { diff --git a/interface/src/project/SettingsScheduler.tsx b/interface/src/project/SettingsScheduler.tsx index 4e3da6116..59fdee05b 100644 --- a/interface/src/project/SettingsScheduler.tsx +++ b/interface/src/project/SettingsScheduler.tsx @@ -117,7 +117,6 @@ const SettingsScheduler: FC = () => { } }, [LL]); - // on mount useEffect(() => { const formatter = new Intl.DateTimeFormat(locale, { weekday: 'short', timeZone: 'UTC' }); const days = [1, 2, 3, 4, 5, 6, 7].map((day) => { diff --git a/interface/src/utils/useWs.ts b/interface/src/utils/useWs.ts index 8e30da18b..3471c691e 100644 --- a/interface/src/utils/useWs.ts +++ b/interface/src/utils/useWs.ts @@ -83,6 +83,7 @@ export const useWs = (wsUrl: string, wsThrottle = 100) => { } }); ws.current = instance; + // eslint-disable-next-line @typescript-eslint/unbound-method return instance.close; }, [wsUrl, onMessage]); diff --git a/mock-api/server.js b/mock-api/server.js index 7016c4757..fbeef3264 100644 --- a/mock-api/server.js +++ b/mock-api/server.js @@ -826,6 +826,7 @@ const emsesp_deviceentities_4 = [ // LOG rest_server.get(FETCH_LOG_ENDPOINT, (req, res) => { const encoded = msgpack.encode(fetch_log); + console.log('fetchlog'); res.write(encoded, 'binary'); res.end(null, 'binary'); });