diff options
author | Ashutosh Bishnoi <mail2bishnoi@gmail.com> | 2021-04-16 19:02:35 +0530 |
---|---|---|
committer | Ashutosh Bishnoi <mail2bishnoi@gmail.com> | 2021-04-16 19:02:35 +0530 |
commit | 006ee184700c3fb04267950e52a39c697500e66c (patch) | |
tree | b9689e7d48f05a966c5f9ed2975842cef1da9260 /modern/src/CachingController.js | |
parent | 1fd5cd30a392ed0cc0937a4df8947e53a378fe28 (diff) | |
download | trackermap-web-006ee184700c3fb04267950e52a39c697500e66c.tar.gz trackermap-web-006ee184700c3fb04267950e52a39c697500e66c.tar.bz2 trackermap-web-006ee184700c3fb04267950e52a39c697500e66c.zip |
Rename the MainController to CachingController
Diffstat (limited to 'modern/src/CachingController.js')
-rw-r--r-- | modern/src/CachingController.js | 22 |
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..7adb39b8 --- /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); |