From ad94dc32e90626d42b8d4baeefadefa0042824ec Mon Sep 17 00:00:00 2001 From: Anton Tananaev Date: Tue, 24 May 2022 08:21:22 -0700 Subject: Show last update time --- .../src/common/components/LocalizationProvider.js | 16 +++- modern/src/main/DevicesList.js | 102 +++++++++++---------- 2 files changed, 69 insertions(+), 49 deletions(-) (limited to 'modern') diff --git a/modern/src/common/components/LocalizationProvider.js b/modern/src/common/components/LocalizationProvider.js index 147ac5ca..db3e1fb9 100644 --- a/modern/src/common/components/LocalizationProvider.js +++ b/modern/src/common/components/LocalizationProvider.js @@ -1,5 +1,9 @@ /* eslint-disable import/no-relative-packages */ -import React, { createContext, useContext, useMemo } from 'react'; +import React, { + createContext, useContext, useEffect, useMemo, +} from 'react'; +import moment from 'moment'; +import 'moment/min/locales.min'; import af from '../../../../web/l10n/af.json'; import ar from '../../../../web/l10n/ar.json'; @@ -146,6 +150,16 @@ export const LocalizationProvider = ({ children }) => { const value = useMemo(() => ({ languages, language, setLanguage }), [languages, language, setLanguage]); + useEffect(() => { + let selected; + if (language.length > 2) { + selected = `${language.slice(0, 2)}-${language.slice(-2).toLowerCase()}`; + } else { + selected = language; + } + moment.locale([selected, 'en']); + }, [language]); + return ( {children} diff --git a/modern/src/main/DevicesList.js b/modern/src/main/DevicesList.js index 06b75715..fe963124 100644 --- a/modern/src/main/DevicesList.js +++ b/modern/src/main/DevicesList.js @@ -6,7 +6,6 @@ import Avatar from '@mui/material/Avatar'; import List from '@mui/material/List'; import ListItem from '@mui/material/ListItem'; import ListItemAvatar from '@mui/material/ListItemAvatar'; -import ListItemSecondaryAction from '@mui/material/ListItemSecondaryAction'; import ListItemText from '@mui/material/ListItemText'; import { FixedSizeList } from 'react-window'; import AutoSizer from 'react-virtualized-auto-sizer'; @@ -20,6 +19,7 @@ import FlashOnIcon from '@mui/icons-material/FlashOn'; import FlashOffIcon from '@mui/icons-material/FlashOff'; import ErrorIcon from '@mui/icons-material/Error'; +import moment from 'moment'; import { devicesActions } from '../store'; import { useEffectAsync } from '../reactHelper'; import { @@ -63,9 +63,6 @@ const useStyles = makeStyles((theme) => ({ neutral: { color: theme.palette.colors.neutral, }, - indicators: { - lineHeight: 1, - }, })); const DeviceRow = ({ data, index, style }) => { @@ -77,6 +74,15 @@ const DeviceRow = ({ data, index, style }) => { const item = items[index]; const position = useSelector((state) => state.positions.items[item.id]); + const secondaryText = () => { + const status = formatStatus(item.status, t); + if (item.lastUpdate) { + const lastUpdate = moment(item.lastUpdate).fromNow(); + return `${status} ${lastUpdate}`; + } + return status; + }; + return (
dispatch(devicesActions.select(item.id))}> @@ -87,52 +93,52 @@ const DeviceRow = ({ data, index, style }) => { - - {position && ( - <> - {position.attributes.hasOwnProperty('alarm') && ( - - - - - - )} - {position.attributes.hasOwnProperty('ignition') && ( - - - {position.attributes.ignition ? ( - - ) : ( - - )} - - - )} - {position.attributes.hasOwnProperty('batteryLevel') && ( - - - {position.attributes.batteryLevel > 70 ? ( - position.attributes.charge - ? () - : () - ) : position.attributes.batteryLevel > 30 ? ( - position.attributes.charge - ? () - : () - ) : ( - position.attributes.charge - ? () - : () - )} - - - )} - - )} - + {position && ( + <> + {position.attributes.hasOwnProperty('alarm') && ( + + + + + + )} + {position.attributes.hasOwnProperty('ignition') && ( + + + {position.attributes.ignition ? ( + + ) : ( + + )} + + + )} + {position.attributes.hasOwnProperty('batteryLevel') && ( + + + {position.attributes.batteryLevel > 70 ? ( + position.attributes.charge + ? () + : () + ) : position.attributes.batteryLevel > 30 ? ( + position.attributes.charge + ? () + : () + ) : ( + position.attributes.charge + ? () + : () + )} + + + )} + + )}
); -- cgit v1.2.3