From 8940a61d4e848ff1b66b4a8f577e20a2a6233162 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mose=20M=C3=BCller?= Date: Thu, 21 Dec 2023 07:46:53 +0100 Subject: [PATCH] adds WebSettings context --- frontend/src/App.tsx | 23 +++++++++++++---------- frontend/src/WebSettings.tsx | 8 ++++++++ 2 files changed, 21 insertions(+), 10 deletions(-) create mode 100644 frontend/src/WebSettings.tsx diff --git a/frontend/src/App.tsx b/frontend/src/App.tsx index 675817a..bfeabd1 100644 --- a/frontend/src/App.tsx +++ b/frontend/src/App.tsx @@ -13,6 +13,7 @@ import { } from './components/NotificationsComponent'; import { ConnectionToast } from './components/ConnectionToast'; import { SerializedValue, setNestedValueByPath, State } from './utils/stateUtils'; +import { WebSettingsContext, WebSetting } from './WebSettings'; type Action = | { type: 'SET_DATA'; data: State } @@ -42,6 +43,7 @@ const reducer = (state: State, action: Action): State => { }; const App = () => { const [state, dispatch] = useReducer(reducer, null); + const [webSettings, setWebSettings] = useState>({}); const [isInstantUpdate, setIsInstantUpdate] = useState(false); const [showSettings, setShowSettings] = useState(false); const [showNotification, setShowNotification] = useState(false); @@ -68,10 +70,9 @@ const App = () => { fetch(`http://${hostname}:${port}/service-properties`) .then((response) => response.json()) .then((data: State) => dispatch({ type: 'SET_DATA', data })); - fetch(`http://${hostname}:${port}/web-settings`).then((response) => - response.json() - ); - // .then((data: State) => dispatch({ type: 'SET_DATA', data })); + fetch(`http://${hostname}:${port}/web-settings`) + .then((response) => response.json()) + .then((data: Record) => setWebSettings(data)); setConnectionStatus('connected'); }); socket.on('disconnect', () => { @@ -182,12 +183,14 @@ const App = () => {
- + + +
diff --git a/frontend/src/WebSettings.tsx b/frontend/src/WebSettings.tsx new file mode 100644 index 0000000..2b37a57 --- /dev/null +++ b/frontend/src/WebSettings.tsx @@ -0,0 +1,8 @@ +import { createContext } from 'react'; + +export const WebSettingsContext = createContext({}); + +export type WebSetting = { + displayName: string; + index: number; +}[];