aboutsummaryrefslogtreecommitdiff
path: root/modern/src/CachingController.js
diff options
context:
space:
mode:
authorAshutosh Bishnoi <mail2bishnoi@gmail.com>2021-04-16 19:02:35 +0530
committerAshutosh Bishnoi <mail2bishnoi@gmail.com>2021-04-16 19:02:35 +0530
commit006ee184700c3fb04267950e52a39c697500e66c (patch)
treeb9689e7d48f05a966c5f9ed2975842cef1da9260 /modern/src/CachingController.js
parent1fd5cd30a392ed0cc0937a4df8947e53a378fe28 (diff)
downloadetbsa-traccar-web-006ee184700c3fb04267950e52a39c697500e66c.tar.gz
etbsa-traccar-web-006ee184700c3fb04267950e52a39c697500e66c.tar.bz2
etbsa-traccar-web-006ee184700c3fb04267950e52a39c697500e66c.zip
Rename the MainController to CachingController
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..7adb39b
--- /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);