aboutsummaryrefslogtreecommitdiff
path: root/modern/src/CachingController.js
diff options
context:
space:
mode:
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 00000000..fa3b9f6b
--- /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);