aboutsummaryrefslogtreecommitdiff
path: root/modern/src/MainController.js
diff options
context:
space:
mode:
Diffstat (limited to 'modern/src/MainController.js')
-rw-r--r--modern/src/MainController.js22
1 files changed, 22 insertions, 0 deletions
diff --git a/modern/src/MainController.js b/modern/src/MainController.js
new file mode 100644
index 0000000..6ae98fd
--- /dev/null
+++ b/modern/src/MainController.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 MainController = () => {
+ 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()(MainController); \ No newline at end of file