Skip to content

Commit

Permalink
Fix store refresh
Browse files Browse the repository at this point in the history
  • Loading branch information
tananaev committed Dec 12, 2023
1 parent 3b38142 commit 7d607db
Show file tree
Hide file tree
Showing 7 changed files with 15 additions and 11 deletions.
10 changes: 5 additions & 5 deletions modern/src/CachingController.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const CachingController = () => {
if (authenticated) {
const response = await fetch('/api/geofences');
if (response.ok) {
dispatch(geofencesActions.update(await response.json()));
dispatch(geofencesActions.refresh(await response.json()));
} else {
throw Error(await response.text());
}
Expand All @@ -24,7 +24,7 @@ const CachingController = () => {
if (authenticated) {
const response = await fetch('/api/groups');
if (response.ok) {
dispatch(groupsActions.update(await response.json()));
dispatch(groupsActions.refresh(await response.json()));
} else {
throw Error(await response.text());
}
Expand All @@ -35,7 +35,7 @@ const CachingController = () => {
if (authenticated) {
const response = await fetch('/api/drivers');
if (response.ok) {
dispatch(driversActions.update(await response.json()));
dispatch(driversActions.refresh(await response.json()));
} else {
throw Error(await response.text());
}
Expand All @@ -46,7 +46,7 @@ const CachingController = () => {
if (authenticated) {
const response = await fetch('/api/maintenance');
if (response.ok) {
dispatch(maintenancesActions.update(await response.json()));
dispatch(maintenancesActions.refresh(await response.json()));
} else {
throw Error(await response.text());
}
Expand All @@ -57,7 +57,7 @@ const CachingController = () => {
if (authenticated) {
const response = await fetch('/api/calendars');
if (response.ok) {
dispatch(calendarsActions.update(await response.json()));
dispatch(calendarsActions.refresh(await response.json()));
} else {
throw Error(await response.text());
}
Expand Down
2 changes: 1 addition & 1 deletion modern/src/settings/CalendarPage.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ const CalendarPage = () => {
const onItemSaved = useCatch(async () => {
const response = await fetch('/api/calendars');
if (response.ok) {
dispatch(calendarsActions.update(await response.json()));
dispatch(calendarsActions.refresh(await response.json()));
} else {
throw Error(await response.text());
}
Expand Down
2 changes: 1 addition & 1 deletion modern/src/settings/GroupPage.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ const GroupPage = () => {
const onItemSaved = useCatch(async () => {
const response = await fetch('/api/groups');
if (response.ok) {
dispatch(groupsActions.update(await response.json()));
dispatch(groupsActions.refresh(await response.json()));
} else {
throw Error(await response.text());
}
Expand Down
3 changes: 2 additions & 1 deletion modern/src/store/calendars.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ const { reducer, actions } = createSlice({
items: {},
},
reducers: {
update(state, action) {
refresh(state, action) {
state.items = {};
action.payload.forEach((item) => state.items[item.id] = item);
},
},
Expand Down
3 changes: 2 additions & 1 deletion modern/src/store/drivers.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ const { reducer, actions } = createSlice({
items: {},
},
reducers: {
update(state, action) {
refresh(state, action) {
state.items = {};
action.payload.forEach((item) => state.items[item.uniqueId] = item);
},
},
Expand Down
3 changes: 2 additions & 1 deletion modern/src/store/groups.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ const { reducer, actions } = createSlice({
items: {},
},
reducers: {
update(state, action) {
refresh(state, action) {
state.items = {};
action.payload.forEach((item) => state.items[item.id] = item);
},
},
Expand Down
3 changes: 2 additions & 1 deletion modern/src/store/maintenances.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ const { reducer, actions } = createSlice({
items: {},
},
reducers: {
update(state, action) {
refresh(state, action) {
state.items = {};
action.payload.forEach((item) => state.items[item.id] = item);
},
},
Expand Down

0 comments on commit 7d607db

Please sign in to comment.