diff options
author | Anton Tananaev <anton.tananaev@gmail.com> | 2021-04-19 09:34:28 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-04-19 09:34:28 -0700 |
commit | 047bf86480e2b3e215c13df2af0da456a664b507 (patch) | |
tree | 9edd2ceef5a1a381d416a1b03f529b0088c559a7 /modern/src/CachingController.js | |
parent | 2de99a83b3c45bc15faed44a1b248d56698b292b (diff) | |
parent | 2691e78cd4d5486581656a490b9fb5386e68a5d9 (diff) | |
download | trackermap-web-047bf86480e2b3e215c13df2af0da456a664b507.tar.gz trackermap-web-047bf86480e2b3e215c13df2af0da456a664b507.tar.bz2 trackermap-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.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..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); |