From d2de65460577a46dfa20f8df6870b10fa9c7d49e Mon Sep 17 00:00:00 2001 From: Anton Tananaev Date: Mon, 20 Jun 2022 08:36:36 -0700 Subject: Loading shimmer for settings --- modern/src/common/components/TableShimmer.js | 14 ++++++++++++++ modern/src/settings/CalendarsPage.js | 21 ++++++++++++++------- modern/src/settings/CommandsPage.js | 21 ++++++++++++++------- modern/src/settings/ComputedAttributesPage.js | 21 ++++++++++++++------- modern/src/settings/DriversPage.js | 21 ++++++++++++++------- modern/src/settings/GroupsPage.js | 21 ++++++++++++++------- modern/src/settings/MaintenancesPage.js | 21 ++++++++++++++------- modern/src/settings/NotificationsPage.js | 21 ++++++++++++++------- modern/src/settings/UsersPage.js | 21 ++++++++++++++------- 9 files changed, 126 insertions(+), 56 deletions(-) create mode 100644 modern/src/common/components/TableShimmer.js (limited to 'modern') diff --git a/modern/src/common/components/TableShimmer.js b/modern/src/common/components/TableShimmer.js new file mode 100644 index 00000000..3208551f --- /dev/null +++ b/modern/src/common/components/TableShimmer.js @@ -0,0 +1,14 @@ +import React from 'react'; +import { Skeleton, TableCell, TableRow } from '@mui/material'; + +const TableShimmer = ({ columns }) => [...Array(3)].map(() => ( + + {[...Array(columns)].map(() => ( + + + + ))} + +)); + +export default TableShimmer; diff --git a/modern/src/settings/CalendarsPage.js b/modern/src/settings/CalendarsPage.js index ea28967c..e46fe8f1 100644 --- a/modern/src/settings/CalendarsPage.js +++ b/modern/src/settings/CalendarsPage.js @@ -9,6 +9,7 @@ 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'; const useStyles = makeStyles((theme) => ({ columnAction: { @@ -23,13 +24,19 @@ const CalendarsPage = () => { const [timestamp, setTimestamp] = useState(Date.now()); const [items, setItems] = useState([]); + const [loading, setLoading] = useState(false); useEffectAsync(async () => { - const response = await fetch('/api/calendars'); - if (response.ok) { - setItems(await response.json()); - } else { - throw Error(await response.text()); + setLoading(true); + try { + const response = await fetch('/api/calendars'); + if (response.ok) { + setItems(await response.json()); + } else { + throw Error(await response.text()); + } + } finally { + setLoading(false); } }, [timestamp]); @@ -43,14 +50,14 @@ const CalendarsPage = () => { - {items.map((item) => ( + {!loading ? items.map((item) => ( {item.name} - ))} + )) : ()} diff --git a/modern/src/settings/CommandsPage.js b/modern/src/settings/CommandsPage.js index 5ff194d5..3963952b 100644 --- a/modern/src/settings/CommandsPage.js +++ b/modern/src/settings/CommandsPage.js @@ -11,6 +11,7 @@ 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'; const useStyles = makeStyles((theme) => ({ columnAction: { @@ -25,13 +26,19 @@ const CommandsPage = () => { const [timestamp, setTimestamp] = useState(Date.now()); const [items, setItems] = useState([]); + const [loading, setLoading] = useState(false); useEffectAsync(async () => { - const response = await fetch('/api/commands'); - if (response.ok) { - setItems(await response.json()); - } else { - throw Error(await response.text()); + setLoading(true); + try { + const response = await fetch('/api/commands'); + if (response.ok) { + setItems(await response.json()); + } else { + throw Error(await response.text()); + } + } finally { + setLoading(false); } }, [timestamp]); @@ -47,7 +54,7 @@ const CommandsPage = () => { - {items.map((item) => ( + {!loading ? items.map((item) => ( {item.description} {t(prefixString('command', item.type))} @@ -56,7 +63,7 @@ const CommandsPage = () => { - ))} + )) : ()} diff --git a/modern/src/settings/ComputedAttributesPage.js b/modern/src/settings/ComputedAttributesPage.js index 5de79dc0..952ea677 100644 --- a/modern/src/settings/ComputedAttributesPage.js +++ b/modern/src/settings/ComputedAttributesPage.js @@ -10,6 +10,7 @@ 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'; const useStyles = makeStyles((theme) => ({ columnAction: { @@ -24,14 +25,20 @@ const ComputedAttributesPage = () => { const [timestamp, setTimestamp] = useState(Date.now()); const [items, setItems] = useState([]); + const [loading, setLoading] = useState(false); const administrator = useAdministrator(); useEffectAsync(async () => { - const response = await fetch('/api/attributes/computed'); - if (response.ok) { - setItems(await response.json()); - } else { - throw Error(await response.text()); + setLoading(true); + try { + const response = await fetch('/api/attributes/computed'); + if (response.ok) { + setItems(await response.json()); + } else { + throw Error(await response.text()); + } + } finally { + setLoading(false); } }, [timestamp]); @@ -48,7 +55,7 @@ const ComputedAttributesPage = () => { - {items.map((item) => ( + {!loading ? items.map((item) => ( {item.description} {item.attribute} @@ -60,7 +67,7 @@ const ComputedAttributesPage = () => { )} - ))} + )) : ()} diff --git a/modern/src/settings/DriversPage.js b/modern/src/settings/DriversPage.js index cdff5488..7700f5cd 100644 --- a/modern/src/settings/DriversPage.js +++ b/modern/src/settings/DriversPage.js @@ -9,6 +9,7 @@ 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'; const useStyles = makeStyles((theme) => ({ columnAction: { @@ -23,13 +24,19 @@ const DriversPage = () => { const [timestamp, setTimestamp] = useState(Date.now()); const [items, setItems] = useState([]); + const [loading, setLoading] = useState(false); useEffectAsync(async () => { - const response = await fetch('/api/drivers'); - if (response.ok) { - setItems(await response.json()); - } else { - throw Error(await response.text()); + setLoading(true); + try { + const response = await fetch('/api/drivers'); + if (response.ok) { + setItems(await response.json()); + } else { + throw Error(await response.text()); + } + } finally { + setLoading(false); } }, [timestamp]); @@ -44,7 +51,7 @@ const DriversPage = () => { - {items.map((item) => ( + {!loading ? items.map((item) => ( {item.name} {item.uniqueId} @@ -52,7 +59,7 @@ const DriversPage = () => { - ))} + )) : ()} diff --git a/modern/src/settings/GroupsPage.js b/modern/src/settings/GroupsPage.js index 16a907c2..50f441eb 100644 --- a/modern/src/settings/GroupsPage.js +++ b/modern/src/settings/GroupsPage.js @@ -9,6 +9,7 @@ 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'; const useStyles = makeStyles((theme) => ({ columnAction: { @@ -23,13 +24,19 @@ const GroupsPage = () => { const [timestamp, setTimestamp] = useState(Date.now()); const [items, setItems] = useState([]); + const [loading, setLoading] = useState(false); useEffectAsync(async () => { - const response = await fetch('/api/groups'); - if (response.ok) { - setItems(await response.json()); - } else { - throw Error(await response.text()); + setLoading(true); + try { + const response = await fetch('/api/groups'); + if (response.ok) { + setItems(await response.json()); + } else { + throw Error(await response.text()); + } + } finally { + setLoading(false); } }, [timestamp]); @@ -43,14 +50,14 @@ const GroupsPage = () => { - {items.map((item) => ( + {!loading ? items.map((item) => ( {item.name} - ))} + )) : ()} diff --git a/modern/src/settings/MaintenancesPage.js b/modern/src/settings/MaintenancesPage.js index 7569e7bf..da77be7e 100644 --- a/modern/src/settings/MaintenancesPage.js +++ b/modern/src/settings/MaintenancesPage.js @@ -12,6 +12,7 @@ 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'; const useStyles = makeStyles((theme) => ({ columnAction: { @@ -28,15 +29,21 @@ const MaintenacesPage = () => { const [timestamp, setTimestamp] = useState(Date.now()); const [items, setItems] = useState([]); + const [loading, setLoading] = useState(false); const speedUnit = useAttributePreference('speedUnit'); const distanceUnit = useAttributePreference('distanceUnit'); useEffectAsync(async () => { - const response = await fetch('/api/maintenance'); - if (response.ok) { - setItems(await response.json()); - } else { - throw Error(await response.text()); + setLoading(true); + try { + const response = await fetch('/api/maintenance'); + if (response.ok) { + setItems(await response.json()); + } else { + throw Error(await response.text()); + } + } finally { + setLoading(false); } }, [timestamp]); @@ -69,7 +76,7 @@ const MaintenacesPage = () => { - {items.map((item) => ( + {!loading ? items.map((item) => ( {item.name} {item.type} @@ -79,7 +86,7 @@ const MaintenacesPage = () => { - ))} + )) : ()} diff --git a/modern/src/settings/NotificationsPage.js b/modern/src/settings/NotificationsPage.js index bdc9857f..6e268507 100644 --- a/modern/src/settings/NotificationsPage.js +++ b/modern/src/settings/NotificationsPage.js @@ -11,6 +11,7 @@ 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'; const useStyles = makeStyles((theme) => ({ columnAction: { @@ -25,13 +26,19 @@ const NotificationsPage = () => { const [timestamp, setTimestamp] = useState(Date.now()); const [items, setItems] = useState([]); + const [loading, setLoading] = useState(false); useEffectAsync(async () => { - const response = await fetch('/api/notifications'); - if (response.ok) { - setItems(await response.json()); - } else { - throw Error(await response.text()); + setLoading(true); + try { + const response = await fetch('/api/notifications'); + if (response.ok) { + setItems(await response.json()); + } else { + throw Error(await response.text()); + } + } finally { + setLoading(false); } }, [timestamp]); @@ -59,7 +66,7 @@ const NotificationsPage = () => { - {items.map((item) => ( + {!loading ? items.map((item) => ( {t(prefixString('event', item.type))} {formatBoolean(item.always, t)} @@ -69,7 +76,7 @@ const NotificationsPage = () => { - ))} + )) : ()} diff --git a/modern/src/settings/UsersPage.js b/modern/src/settings/UsersPage.js index ad755936..cffee2f6 100644 --- a/modern/src/settings/UsersPage.js +++ b/modern/src/settings/UsersPage.js @@ -10,6 +10,7 @@ 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'; const useStyles = makeStyles((theme) => ({ columnAction: { @@ -24,13 +25,19 @@ const UsersPage = () => { const [timestamp, setTimestamp] = useState(Date.now()); const [items, setItems] = useState([]); + const [loading, setLoading] = useState(false); useEffectAsync(async () => { - const response = await fetch('/api/users'); - if (response.ok) { - setItems(await response.json()); - } else { - throw Error(await response.text()); + setLoading(true); + try { + const response = await fetch('/api/users'); + if (response.ok) { + setItems(await response.json()); + } else { + throw Error(await response.text()); + } + } finally { + setLoading(false); } }, [timestamp]); @@ -47,7 +54,7 @@ const UsersPage = () => { - {items.map((item) => ( + {!loading ? items.map((item) => ( {item.name} {item.email} @@ -57,7 +64,7 @@ const UsersPage = () => { - ))} + )) : ()} -- cgit v1.2.3