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 +++++++++++++++++++++++++++++++++- modern/src/store/calendars.js | 16 +++++++++ modern/src/store/commands.js | 16 +++++++++ modern/src/store/computedAttributes.js | 16 +++++++++ modern/src/store/drivers.js | 16 +++++++++ modern/src/store/groups.js | 16 +++++++++ modern/src/store/index.js | 22 ++++++++++++ modern/src/store/maintenances.js | 16 +++++++++ modern/src/store/notifications.js | 16 +++++++++ 9 files changed, 198 insertions(+), 1 deletion(-) create mode 100644 modern/src/store/calendars.js create mode 100644 modern/src/store/commands.js create mode 100644 modern/src/store/computedAttributes.js create mode 100644 modern/src/store/drivers.js create mode 100644 modern/src/store/groups.js create mode 100644 modern/src/store/maintenances.js create mode 100644 modern/src/store/notifications.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; } diff --git a/modern/src/store/calendars.js b/modern/src/store/calendars.js new file mode 100644 index 0000000..3aa4d89 --- /dev/null +++ b/modern/src/store/calendars.js @@ -0,0 +1,16 @@ +import { createSlice } from '@reduxjs/toolkit'; + +const { reducer, actions } = createSlice({ + name: 'calendars', + initialState: { + items: {}, + }, + reducers: { + update(state, action) { + action.payload.forEach(item => state.items[item['id']] = item); + }, + } +}); + +export { actions as calendarsActions }; +export { reducer as calendarsReducer }; diff --git a/modern/src/store/commands.js b/modern/src/store/commands.js new file mode 100644 index 0000000..d18d609 --- /dev/null +++ b/modern/src/store/commands.js @@ -0,0 +1,16 @@ +import { createSlice } from '@reduxjs/toolkit'; + +const { reducer, actions } = createSlice({ + name: 'commands', + initialState: { + items: {}, + }, + reducers: { + update(state, action) { + action.payload.forEach(item => state.items[item['id']] = item); + }, + } +}); + +export { actions as commandsActions }; +export { reducer as commandsReducer }; diff --git a/modern/src/store/computedAttributes.js b/modern/src/store/computedAttributes.js new file mode 100644 index 0000000..d9e3531 --- /dev/null +++ b/modern/src/store/computedAttributes.js @@ -0,0 +1,16 @@ +import { createSlice } from '@reduxjs/toolkit'; + +const { reducer, actions } = createSlice({ + name: 'computedAttributes', + initialState: { + items: {}, + }, + reducers: { + update(state, action) { + action.payload.forEach(item => state.items[item['id']] = item); + }, + } +}); + +export { actions as computedAttributesActions }; +export { reducer as computedAttributesReducer }; diff --git a/modern/src/store/drivers.js b/modern/src/store/drivers.js new file mode 100644 index 0000000..63522d7 --- /dev/null +++ b/modern/src/store/drivers.js @@ -0,0 +1,16 @@ +import { createSlice } from '@reduxjs/toolkit'; + +const { reducer, actions } = createSlice({ + name: 'drivers', + initialState: { + items: {}, + }, + reducers: { + update(state, action) { + action.payload.forEach(item => state.items[item['id']] = item); + }, + } +}); + +export { actions as driversActions }; +export { reducer as driversReducer }; diff --git a/modern/src/store/groups.js b/modern/src/store/groups.js new file mode 100644 index 0000000..483323f --- /dev/null +++ b/modern/src/store/groups.js @@ -0,0 +1,16 @@ +import { createSlice } from '@reduxjs/toolkit'; + +const { reducer, actions } = createSlice({ + name: 'groups', + initialState: { + items: {}, + }, + reducers: { + update(state, action) { + action.payload.forEach(item => state.items[item['id']] = item); + }, + } +}); + +export { actions as groupsActions }; +export { reducer as groupsReducer }; diff --git a/modern/src/store/index.js b/modern/src/store/index.js index 1fddae9..9163e44 100644 --- a/modern/src/store/index.js +++ b/modern/src/store/index.js @@ -4,17 +4,39 @@ import { sessionReducer as session } from './session'; import { devicesReducer as devices } from './devices'; import { positionsReducer as positions } from './positions'; import { geofencesReducer as geofences } from './geofences'; +import { groupsReducer as groups } from './groups'; +import { driversReducer as drivers } from './drivers'; +import { maintenancesReducer as maintenances } from './maintenances'; +import { calendarsReducer as calendars } from './calendars'; +import { computedAttributesReducer as computedAttributes } from './computedAttributes'; +import { commandsReducer as commands } from './commands'; +import { notificationsReducer as notifications } from './notifications'; const reducer = combineReducers({ session, devices, positions, geofences, + groups, + drivers, + maintenances, + calendars, + computedAttributes, + commands, + notifications, + }); export { sessionActions } from './session'; export { devicesActions } from './devices'; export { positionsActions } from './positions'; export { geofencesActions } from './geofences'; +export { groupsActions } from './groups'; +export { driversActions } from './drivers'; +export { maintenancesActions } from './maintenances'; +export { calendarsActions } from './calendars'; +export { computedAttributesActions } from './computedAttributes'; +export { commandsActions } from './commands'; +export { notificationsActions } from './notifications'; export default configureStore({ reducer }); diff --git a/modern/src/store/maintenances.js b/modern/src/store/maintenances.js new file mode 100644 index 0000000..0813f6b --- /dev/null +++ b/modern/src/store/maintenances.js @@ -0,0 +1,16 @@ +import { createSlice } from '@reduxjs/toolkit'; + +const { reducer, actions } = createSlice({ + name: 'maintenances', + initialState: { + items: {}, + }, + reducers: { + update(state, action) { + action.payload.forEach(item => state.items[item['id']] = item); + }, + } +}); + +export { actions as maintenancesActions }; +export { reducer as maintenancesReducer }; diff --git a/modern/src/store/notifications.js b/modern/src/store/notifications.js new file mode 100644 index 0000000..be8a989 --- /dev/null +++ b/modern/src/store/notifications.js @@ -0,0 +1,16 @@ +import { createSlice } from '@reduxjs/toolkit'; + +const { reducer, actions } = createSlice({ + name: 'notifications', + initialState: { + items: {}, + }, + reducers: { + update(state, action) { + action.payload.forEach(item => state.items[item['id']] = item); + }, + } +}); + +export { actions as notificationsActions }; +export { reducer as notificationsReducer }; -- cgit v1.2.3 From 127a2628b61b0a151eb5225af7ecaf483f907665 Mon Sep 17 00:00:00 2001 From: Ashutosh Bishnoi Date: Tue, 27 Apr 2021 11:18:42 +0530 Subject: Deleting somne of the stores --- modern/src/CachingController.js | 38 +--------------------------------- modern/src/store/calendars.js | 16 -------------- modern/src/store/commands.js | 16 -------------- modern/src/store/computedAttributes.js | 16 -------------- modern/src/store/index.js | 13 ------------ modern/src/store/notifications.js | 16 -------------- 6 files changed, 1 insertion(+), 114 deletions(-) delete mode 100644 modern/src/store/calendars.js delete mode 100644 modern/src/store/commands.js delete mode 100644 modern/src/store/computedAttributes.js delete mode 100644 modern/src/store/notifications.js diff --git a/modern/src/CachingController.js b/modern/src/CachingController.js index faeec48..3f808de 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, groupsActions, driversActions, calendarsActions, commandsActions, computedAttributesActions, maintenancesActions, notificationsActions } from './store'; +import { geofencesActions, groupsActions, driversActions, maintenancesActions } from './store'; import { useEffectAsync } from './reactHelper'; const CachingController = () => { @@ -34,33 +34,6 @@ const CachingController = () => { } }, [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'); @@ -68,15 +41,6 @@ const CachingController = () => { 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; diff --git a/modern/src/store/calendars.js b/modern/src/store/calendars.js deleted file mode 100644 index 3aa4d89..0000000 --- a/modern/src/store/calendars.js +++ /dev/null @@ -1,16 +0,0 @@ -import { createSlice } from '@reduxjs/toolkit'; - -const { reducer, actions } = createSlice({ - name: 'calendars', - initialState: { - items: {}, - }, - reducers: { - update(state, action) { - action.payload.forEach(item => state.items[item['id']] = item); - }, - } -}); - -export { actions as calendarsActions }; -export { reducer as calendarsReducer }; diff --git a/modern/src/store/commands.js b/modern/src/store/commands.js deleted file mode 100644 index d18d609..0000000 --- a/modern/src/store/commands.js +++ /dev/null @@ -1,16 +0,0 @@ -import { createSlice } from '@reduxjs/toolkit'; - -const { reducer, actions } = createSlice({ - name: 'commands', - initialState: { - items: {}, - }, - reducers: { - update(state, action) { - action.payload.forEach(item => state.items[item['id']] = item); - }, - } -}); - -export { actions as commandsActions }; -export { reducer as commandsReducer }; diff --git a/modern/src/store/computedAttributes.js b/modern/src/store/computedAttributes.js deleted file mode 100644 index d9e3531..0000000 --- a/modern/src/store/computedAttributes.js +++ /dev/null @@ -1,16 +0,0 @@ -import { createSlice } from '@reduxjs/toolkit'; - -const { reducer, actions } = createSlice({ - name: 'computedAttributes', - initialState: { - items: {}, - }, - reducers: { - update(state, action) { - action.payload.forEach(item => state.items[item['id']] = item); - }, - } -}); - -export { actions as computedAttributesActions }; -export { reducer as computedAttributesReducer }; diff --git a/modern/src/store/index.js b/modern/src/store/index.js index 9163e44..6e2bb20 100644 --- a/modern/src/store/index.js +++ b/modern/src/store/index.js @@ -7,10 +7,6 @@ import { geofencesReducer as geofences } from './geofences'; import { groupsReducer as groups } from './groups'; import { driversReducer as drivers } from './drivers'; import { maintenancesReducer as maintenances } from './maintenances'; -import { calendarsReducer as calendars } from './calendars'; -import { computedAttributesReducer as computedAttributes } from './computedAttributes'; -import { commandsReducer as commands } from './commands'; -import { notificationsReducer as notifications } from './notifications'; const reducer = combineReducers({ session, @@ -20,11 +16,6 @@ const reducer = combineReducers({ groups, drivers, maintenances, - calendars, - computedAttributes, - commands, - notifications, - }); export { sessionActions } from './session'; @@ -34,9 +25,5 @@ export { geofencesActions } from './geofences'; export { groupsActions } from './groups'; export { driversActions } from './drivers'; export { maintenancesActions } from './maintenances'; -export { calendarsActions } from './calendars'; -export { computedAttributesActions } from './computedAttributes'; -export { commandsActions } from './commands'; -export { notificationsActions } from './notifications'; export default configureStore({ reducer }); diff --git a/modern/src/store/notifications.js b/modern/src/store/notifications.js deleted file mode 100644 index be8a989..0000000 --- a/modern/src/store/notifications.js +++ /dev/null @@ -1,16 +0,0 @@ -import { createSlice } from '@reduxjs/toolkit'; - -const { reducer, actions } = createSlice({ - name: 'notifications', - initialState: { - items: {}, - }, - reducers: { - update(state, action) { - action.payload.forEach(item => state.items[item['id']] = item); - }, - } -}); - -export { actions as notificationsActions }; -export { reducer as notificationsReducer }; -- cgit v1.2.3