From e66bb788f569fc3123e22372e871759d4d420c52 Mon Sep 17 00:00:00 2001 From: Desmond Kyeremeh Date: Fri, 23 Jul 2021 13:51:48 +0000 Subject: moved stuff to selectors --- modern/src/common/selectors.js | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'modern/src/common') diff --git a/modern/src/common/selectors.js b/modern/src/common/selectors.js index 44a0c547..ddf9dbec 100644 --- a/modern/src/common/selectors.js +++ b/modern/src/common/selectors.js @@ -1,3 +1,7 @@ export const getIsAdmin = (state) => state.session.user?.administrator; export const getUserId = (state) => state.session.user?.id; + +export const getDevices = (state) => Object.values(state.devices.items); + +export const getItemPosition = (itemId) => (state) => state.positions.items[itemId]; -- cgit v1.2.3 From 8f26d3171d8d0bccfbd00893498a6ed9db45adb2 Mon Sep 17 00:00:00 2001 From: Desmond Kyeremeh Date: Mon, 26 Jul 2021 11:59:59 +0000 Subject: renamed selector getItemPosition to getPosition --- modern/src/DevicesList.js | 4 ++-- modern/src/common/selectors.js | 2 +- modern/src/map/StatusView.js | 3 ++- 3 files changed, 5 insertions(+), 4 deletions(-) (limited to 'modern/src/common') diff --git a/modern/src/DevicesList.js b/modern/src/DevicesList.js index 07eeac3e..cbf3a0a9 100644 --- a/modern/src/DevicesList.js +++ b/modern/src/DevicesList.js @@ -18,7 +18,7 @@ import { devicesActions } from './store'; import EditCollectionView from './EditCollectionView'; import { useEffectAsync } from './reactHelper'; import { formatPosition } from './common/formatter'; -import { getDevices, getItemPosition } from './common/selectors'; +import { getDevices, getPosition } from './common/selectors'; const useStyles = makeStyles((theme) => ({ list: { @@ -86,7 +86,7 @@ const DeviceRow = ({ data, index, style }) => { const { items } = data; const item = items[index]; - const position = useSelector(getItemPosition(item.id)); + const position = useSelector(getPosition(item.id)); const showIgnition = position?.attributes.hasOwnProperty('ignition') && position.attributes.ignition; return ( diff --git a/modern/src/common/selectors.js b/modern/src/common/selectors.js index ddf9dbec..0c4c02e1 100644 --- a/modern/src/common/selectors.js +++ b/modern/src/common/selectors.js @@ -4,4 +4,4 @@ export const getUserId = (state) => state.session.user?.id; export const getDevices = (state) => Object.values(state.devices.items); -export const getItemPosition = (itemId) => (state) => state.positions.items[itemId]; +export const getPosition = (id) => (state) => state.positions.items[id]; diff --git a/modern/src/map/StatusView.js b/modern/src/map/StatusView.js index 20e5b749..c0f723d2 100644 --- a/modern/src/map/StatusView.js +++ b/modern/src/map/StatusView.js @@ -2,10 +2,11 @@ import React from 'react'; import { useSelector } from 'react-redux'; import t from '../common/localization'; import { formatPosition } from '../common/formatter'; +import { getPosition } from '../common/selectors'; const StatusView = ({ deviceId, onShowDetails }) => { const device = useSelector((state) => state.devices.items[deviceId]); - const position = useSelector((state) => state.positions.items[deviceId]); + const position = useSelector(getPosition(deviceId)); const handleClick = (e) => { e.preventDefault(); -- cgit v1.2.3