From 744144fc8883a035c5a0b63b53535c2361656b3e Mon Sep 17 00:00:00 2001 From: Anton Tananaev Date: Mon, 24 Oct 2022 21:29:00 -0700 Subject: Add devices page --- modern/src/Navigation.js | 2 + modern/src/settings/DevicesPage.js | 79 ++++++++++++++++++++++++++ modern/src/settings/components/SettingsMenu.js | 7 +++ 3 files changed, 88 insertions(+) create mode 100644 modern/src/settings/DevicesPage.js (limited to 'modern/src') diff --git a/modern/src/Navigation.js b/modern/src/Navigation.js index 1c26424f..d08fc12b 100644 --- a/modern/src/Navigation.js +++ b/modern/src/Navigation.js @@ -47,6 +47,7 @@ import AccumulatorsPage from './settings/AccumulatorsPage'; import CommandSendPage from './settings/CommandSendPage'; import App from './App'; import ChangeServerPage from './other/ChangeServerPage'; +import DevicesPage from './settings/DevicesPage'; const Navigation = () => { const navigate = useNavigate(); @@ -112,6 +113,7 @@ const Navigation = () => { } /> } /> } /> + } /> } /> } /> } /> diff --git a/modern/src/settings/DevicesPage.js b/modern/src/settings/DevicesPage.js new file mode 100644 index 00000000..f3ee218f --- /dev/null +++ b/modern/src/settings/DevicesPage.js @@ -0,0 +1,79 @@ +import React, { useState } from 'react'; +import { + Table, TableRow, TableCell, TableHead, TableBody, +} from '@mui/material'; +import makeStyles from '@mui/styles/makeStyles'; +import { useEffectAsync } from '../reactHelper'; +import { useTranslation } from '../common/components/LocalizationProvider'; +import PageLayout from '../common/components/PageLayout'; +import SettingsMenu from './components/SettingsMenu'; +import CollectionFab from './components/CollectionFab'; +import CollectionActions from './components/CollectionActions'; +import TableShimmer from '../common/components/TableShimmer'; +import SearchHeader, { filterByKeyword } from './components/SearchHeader'; + +const useStyles = makeStyles((theme) => ({ + columnAction: { + width: '1%', + paddingRight: theme.spacing(1), + }, +})); + +const DevicesPage = () => { + const classes = useStyles(); + const t = useTranslation(); + + const [timestamp, setTimestamp] = useState(Date.now()); + const [items, setItems] = useState([]); + const [searchKeyword, setSearchKeyword] = useState(''); + const [loading, setLoading] = useState(false); + + useEffectAsync(async () => { + setLoading(true); + try { + const response = await fetch('/api/devices'); + if (response.ok) { + setItems(await response.json()); + } else { + throw Error(await response.text()); + } + } finally { + setLoading(false); + } + }, [timestamp]); + + return ( + } breadcrumbs={['settingsTitle', 'sharedDrivers']}> + + + + + {t('sharedName')} + {t('deviceIdentifier')} + {t('sharedPhone')} + {t('deviceModel')} + {t('deviceContact')} + + + + + {!loading ? items.filter(filterByKeyword(searchKeyword)).map((item) => ( + + {item.name} + {item.uniqueId} + {item.phone} + {item.model} + {item.contact} + + + + + )) : ()} + +
+ +
+ ); +}; + +export default DevicesPage; diff --git a/modern/src/settings/components/SettingsMenu.js b/modern/src/settings/components/SettingsMenu.js index 7a1bf1b3..6a431ba1 100644 --- a/modern/src/settings/components/SettingsMenu.js +++ b/modern/src/settings/components/SettingsMenu.js @@ -12,6 +12,7 @@ import BuildIcon from '@mui/icons-material/Build'; import PeopleIcon from '@mui/icons-material/People'; import TodayIcon from '@mui/icons-material/Today'; import PublishIcon from '@mui/icons-material/Publish'; +import SmartphoneIcon from '@mui/icons-material/Smartphone'; import { Link, useLocation } from 'react-router-dom'; import { useSelector } from 'react-redux'; import { useTranslation } from '../../common/components/LocalizationProvider'; @@ -61,6 +62,12 @@ const SettingsMenu = () => { icon={} selected={location.pathname === `/settings/user/${userId}`} /> + } + selected={location.pathname.startsWith('/settings/device')} + />