From 006ee184700c3fb04267950e52a39c697500e66c Mon Sep 17 00:00:00 2001 From: Ashutosh Bishnoi Date: Fri, 16 Apr 2021 19:02:35 +0530 Subject: Rename the MainController to CachingController --- modern/src/CachingController.js | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 modern/src/CachingController.js (limited to 'modern/src/CachingController.js') 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); -- cgit v1.2.3 From 2691e78cd4d5486581656a490b9fb5386e68a5d9 Mon Sep 17 00:00:00 2001 From: Ashutosh Bishnoi Date: Mon, 19 Apr 2021 13:12:57 +0530 Subject: More code formatting --- modern/src/App.js | 1 - modern/src/CachingController.js | 2 +- modern/src/reports/EventReportPage.js | 2 +- 3 files changed, 2 insertions(+), 3 deletions(-) (limited to 'modern/src/CachingController.js') diff --git a/modern/src/App.js b/modern/src/App.js index 7f8a582..5fd10de 100644 --- a/modern/src/App.js +++ b/modern/src/App.js @@ -29,7 +29,6 @@ import ComputedAttributePage from './settings/ComputedAttributePage'; import MaintenancesPage from './settings/MaintenancesPage'; import MaintenancePage from './settings/MaintenancePage'; import StatisticsPage from './admin/StatisticsPage'; - import CachingController from './CachingController'; const App = () => { diff --git a/modern/src/CachingController.js b/modern/src/CachingController.js index 7adb39b..fa3b9f6 100644 --- a/modern/src/CachingController.js +++ b/modern/src/CachingController.js @@ -3,7 +3,6 @@ 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(); @@ -16,6 +15,7 @@ const CachingController = () => { } } }, [authenticated]); + return null; } diff --git a/modern/src/reports/EventReportPage.js b/modern/src/reports/EventReportPage.js index 2478cad..a14fc93 100644 --- a/modern/src/reports/EventReportPage.js +++ b/modern/src/reports/EventReportPage.js @@ -63,7 +63,7 @@ const EventReportPage = () => { const [items, setItems] = useState([]); const formatGeofence = value => { - if (value !== 0) { + if (value > 0) { const geofence = geofences[value]; return geofence ? geofence.name : ''; } -- cgit v1.2.3