aboutsummaryrefslogtreecommitdiff
path: root/modern/src/other/GeofencesList.js
diff options
context:
space:
mode:
authorAnton Tananaev <anton@traccar.org>2022-05-22 16:02:10 -0700
committerAnton Tananaev <anton@traccar.org>2022-05-22 16:02:10 -0700
commitd447490a186a473dc398a9214fd37c5180fdcf7d (patch)
treed50e59a101aef5e189d33225e8663e3d6be4cae8 /modern/src/other/GeofencesList.js
parentdd18f6264b1a5eb006b4b57951176f7da9cf4fe1 (diff)
downloadtrackermap-web-d447490a186a473dc398a9214fd37c5180fdcf7d.tar.gz
trackermap-web-d447490a186a473dc398a9214fd37c5180fdcf7d.tar.bz2
trackermap-web-d447490a186a473dc398a9214fd37c5180fdcf7d.zip
Fix geofence refresh
Diffstat (limited to 'modern/src/other/GeofencesList.js')
-rw-r--r--modern/src/other/GeofencesList.js14
1 files changed, 12 insertions, 2 deletions
diff --git a/modern/src/other/GeofencesList.js b/modern/src/other/GeofencesList.js
index 202ae3b1..4abb528c 100644
--- a/modern/src/other/GeofencesList.js
+++ b/modern/src/other/GeofencesList.js
@@ -6,8 +6,9 @@ import List from '@material-ui/core/List';
import ListItem from '@material-ui/core/ListItem';
import ListItemText from '@material-ui/core/ListItemText';
-import { devicesActions } from '../store';
+import { devicesActions, geofencesActions } from '../store';
import CollectionActions from '../settings/components/CollectionActions';
+import { useCatchCallback } from '../reactHelper';
const useStyles = makeStyles(() => ({
list: {
@@ -27,13 +28,22 @@ const GeofencesList = () => {
const items = useSelector((state) => state.geofences.items);
+ const refreshGeofences = useCatchCallback(async () => {
+ const response = await fetch('/api/geofences');
+ if (response.ok) {
+ dispatch(geofencesActions.refresh(await response.json()));
+ } else {
+ throw Error(await response.text());
+ }
+ }, [dispatch]);
+
return (
<List className={classes.list}>
{Object.values(items).map((item, index, list) => (
<Fragment key={item.id}>
<ListItem button key={item.id} onClick={() => dispatch(devicesActions.select(item.id))}>
<ListItemText primary={item.name} />
- <CollectionActions itemId={item.id} editPath="/settings/geofence" endpoint="geofences" />
+ <CollectionActions itemId={item.id} editPath="/settings/geofence" endpoint="geofences" setTimestamp={refreshGeofences} />
</ListItem>
{index < list.length - 1 ? <Divider /> : null}
</Fragment>