aboutsummaryrefslogtreecommitdiff
path: root/modern/src/CachingController.js
diff options
context:
space:
mode:
authorAnton Tananaev <anton.tananaev@gmail.com>2021-04-19 09:34:28 -0700
committerGitHub <noreply@github.com>2021-04-19 09:34:28 -0700
commit047bf86480e2b3e215c13df2af0da456a664b507 (patch)
tree9edd2ceef5a1a381d416a1b03f529b0088c559a7 /modern/src/CachingController.js
parent2de99a83b3c45bc15faed44a1b248d56698b292b (diff)
parent2691e78cd4d5486581656a490b9fb5386e68a5d9 (diff)
downloadetbsa-traccar-web-047bf86480e2b3e215c13df2af0da456a664b507.tar.gz
etbsa-traccar-web-047bf86480e2b3e215c13df2af0da456a664b507.tar.bz2
etbsa-traccar-web-047bf86480e2b3e215c13df2af0da456a664b507.zip
Merge pull request #839 from mail2bishnoi/event_type_convsersion
Event type Localization and geofence store creation
Diffstat (limited to 'modern/src/CachingController.js')
-rw-r--r--modern/src/CachingController.js22
1 files changed, 22 insertions, 0 deletions
diff --git a/modern/src/CachingController.js b/modern/src/CachingController.js
new file mode 100644
index 0000000..fa3b9f6
--- /dev/null
+++ b/modern/src/CachingController.js
@@ -0,0 +1,22 @@
+import { useDispatch, useSelector } from 'react-redux';
+import { connect } from 'react-redux';
+import { geofencesActions } from './store';
+import { useEffectAsync } from './reactHelper';
+
+const CachingController = () => {
+ const authenticated = useSelector(state => !!state.session.user);
+ const dispatch = useDispatch();
+
+ useEffectAsync(async () => {
+ if (authenticated) {
+ const response = await fetch('/api/geofences');
+ if (response.ok) {
+ dispatch(geofencesActions.update(await response.json()));
+ }
+ }
+ }, [authenticated]);
+
+ return null;
+}
+
+export default connect()(CachingController);