From 2d5ec8721c2d9ae3d519dd5ff267a05b5f1ab96b Mon Sep 17 00:00:00 2001 From: Ashutosh Bishnoi Date: Tue, 20 Apr 2021 12:15:13 +0530 Subject: Created mostly used stores --- modern/src/CachingController.js | 65 ++++++++++++++++++++++++++++++++++++++++- 1 file changed, 64 insertions(+), 1 deletion(-) (limited to 'modern/src/CachingController.js') diff --git a/modern/src/CachingController.js b/modern/src/CachingController.js index fa3b9f6..faeec48 100644 --- a/modern/src/CachingController.js +++ b/modern/src/CachingController.js @@ -1,6 +1,6 @@ import { useDispatch, useSelector } from 'react-redux'; import { connect } from 'react-redux'; -import { geofencesActions } from './store'; +import { geofencesActions, groupsActions, driversActions, calendarsActions, commandsActions, computedAttributesActions, maintenancesActions, notificationsActions } from './store'; import { useEffectAsync } from './reactHelper'; const CachingController = () => { @@ -15,6 +15,69 @@ const CachingController = () => { } } }, [authenticated]); + + useEffectAsync(async () => { + if (authenticated) { + const response = await fetch('/api/groups'); + if (response.ok) { + dispatch(groupsActions.update(await response.json())); + } + } + }, [authenticated]); + + useEffectAsync(async () => { + if (authenticated) { + const response = await fetch('/api/drivers'); + if (response.ok) { + dispatch(driversActions.update(await response.json())); + } + } + }, [authenticated]); + + useEffectAsync(async () => { + if (authenticated) { + const response = await fetch('/api/calendars'); + if (response.ok) { + dispatch(calendarsActions.update(await response.json())); + } + } + }, [authenticated]); + + useEffectAsync(async () => { + if (authenticated) { + const response = await fetch('/api/commands'); + if (response.ok) { + dispatch(commandsActions.update(await response.json())); + } + } + }, [authenticated]); + + useEffectAsync(async () => { + if (authenticated) { + const response = await fetch('/api/attributes/computed'); + if (response.ok) { + dispatch(computedAttributesActions.update(await response.json())); + } + } + }, [authenticated]); + + useEffectAsync(async () => { + if (authenticated) { + const response = await fetch('/api/maintenance'); + if (response.ok) { + dispatch(maintenancesActions.update(await response.json())); + } + } + }, [authenticated]); + + useEffectAsync(async () => { + if (authenticated) { + const response = await fetch('/api/notifications'); + if (response.ok) { + dispatch(notificationsActions.update(await response.json())); + } + } + }, [authenticated]); return null; } -- cgit v1.2.3