From ec90dfb13aa9b811f4bec52bf5df6f9a739711d5 Mon Sep 17 00:00:00 2001 From: Hristo Nedelkov Date: Thu, 17 Aug 2023 12:01:11 +0300 Subject: [PATCH] Implement redux in device health check --- src/App.tsx | 13 +-- .../DeviceHealthCheck/DeviceHealthCheck.tsx | 22 ++++- src/redux/deviceHealthCheck/slice.tsx | 89 +++++++------------ 3 files changed, 58 insertions(+), 66 deletions(-) diff --git a/src/App.tsx b/src/App.tsx index 10f7de4d..ccba5342 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -7,6 +7,8 @@ import LandingPage from './pages/LandingPage/LandingPage' import DeviceHealthCheck from './pages/DeviceHealthCheck/DeviceHealthCheck' import ConnectDevicePage from './pages/ConnectDevicePage/ConnectDevicePage' import DeviceSyncStatus from './pages/DeviceSyncStatus/DeviceSyncStatus' +import { Provider as ReduxProvider } from 'react-redux' +import store from './redux/store' const router = createBrowserRouter([ { @@ -20,20 +22,21 @@ const router = createBrowserRouter([ { path: '/connect-device', element: , - }, { path: '/device-sync-status', element: , - } + }, ]) function App() { return ( - - - + + + + + ) } diff --git a/src/pages/DeviceHealthCheck/DeviceHealthCheck.tsx b/src/pages/DeviceHealthCheck/DeviceHealthCheck.tsx index 4bb9d649..2f0bcd13 100644 --- a/src/pages/DeviceHealthCheck/DeviceHealthCheck.tsx +++ b/src/pages/DeviceHealthCheck/DeviceHealthCheck.tsx @@ -9,8 +9,13 @@ import { Button, InformationBox } from '@status-im/components' import Icon from '../../components/General/Icon' import DeviceMemory from '../../components/Charts/DeviceMemoryHealth' import DeviceNetworkHealth from '../../components/Charts/DeviceNetworkHealth' +import { useSelector } from 'react-redux' +import { RootState } from '../../redux/store' const DeviceHealthCheck = () => { + // Extract state from Redux store + const deviceHealthState = useSelector((state: RootState) => state.deviceHealth) + console.log(deviceHealthState) return ( { isAdvancedSettings={true} /> - - + + - - + + ) => { - state.storage = action.payload.storage; - state.maxStorage = action.payload.maxStorage; + state.storage = action.payload.storage + state.maxStorage = action.payload.maxStorage }, setCpuLoad: (state, action: PayloadAction) => { - state.cpuLoad = action.payload; + state.cpuLoad = action.payload }, setMemory: (state, action: PayloadAction<{ memory: number[]; maxMemory: number }>) => { - state.memory = action.payload.memory; - state.maxMemory = action.payload.maxMemory; + state.memory = action.payload.memory + state.maxMemory = action.payload.maxMemory }, - setNetworkHealth: (state, action: PayloadAction<{ uploadRate: number[]; downloadRate: number[] }>) => { - state.uploadRate = action.payload.uploadRate; - state.downloadRate = action.payload.downloadRate; + setNetworkHealth: ( + state, + action: PayloadAction<{ uploadRate: number[]; downloadRate: number[] }>, + ) => { + state.uploadRate = action.payload.uploadRate + state.downloadRate = action.payload.downloadRate }, - setHealthInfo: (state, action: PayloadAction<{ - usedStorage: number; - maxRamMemory: number; - usedRamMemory: number; - cpuClockRate: number; - networkLatency: number; - }>) => { - state.usedStorage = action.payload.usedStorage; - state.maxRamMemory = action.payload.maxRamMemory; - state.usedRamMemory = action.payload.usedRamMemory; - state.cpuClockRate = action.payload.cpuClockRate; - state.networkLatency = action.payload.networkLatency; - }, - } -}); + }, +}) -export const { - setStorage, - setCpuLoad, - setMemory, - setNetworkHealth, - setHealthInfo -} = deviceHealthSlice.actions; +export const { setStorage, setCpuLoad, setMemory, setNetworkHealth} = + deviceHealthSlice.actions -export default deviceHealthSlice.reducer; +export default deviceHealthSlice.reducer