diff options
author | Anton Tananaev <anton@traccar.org> | 2022-06-20 08:52:38 -0700 |
---|---|---|
committer | Anton Tananaev <anton@traccar.org> | 2022-06-20 08:52:38 -0700 |
commit | b84fa9a5ee0d68dd922b2fb13a62e9b453397da0 (patch) | |
tree | f8d98846b18ebe8b7af916147964551cebab6208 /modern/src/reports/SummaryReportPage.js | |
parent | d2de65460577a46dfa20f8df6870b10fa9c7d49e (diff) | |
download | trackermap-web-b84fa9a5ee0d68dd922b2fb13a62e9b453397da0.tar.gz trackermap-web-b84fa9a5ee0d68dd922b2fb13a62e9b453397da0.tar.bz2 trackermap-web-b84fa9a5ee0d68dd922b2fb13a62e9b453397da0.zip |
Add shimmer to reports
Diffstat (limited to 'modern/src/reports/SummaryReportPage.js')
-rw-r--r-- | modern/src/reports/SummaryReportPage.js | 37 |
1 files changed, 22 insertions, 15 deletions
diff --git a/modern/src/reports/SummaryReportPage.js b/modern/src/reports/SummaryReportPage.js index 233bfe98..f6ec0691 100644 --- a/modern/src/reports/SummaryReportPage.js +++ b/modern/src/reports/SummaryReportPage.js @@ -15,6 +15,7 @@ import usePersistedState from '../common/util/usePersistedState'; import ColumnSelect from './components/ColumnSelect'; import { useCatch } from '../reactHelper'; import useReportStyles from './common/useReportStyles'; +import TableShimmer from '../common/components/TableShimmer'; const columnsArray = [ ['deviceId', 'sharedDevice'], @@ -42,23 +43,29 @@ const SummaryReportPage = () => { const [columns, setColumns] = usePersistedState('summaryColumns', ['deviceId', 'startTime', 'distance', 'averageSpeed']); const [daily, setDaily] = useState(false); const [items, setItems] = useState([]); + const [loading, setLoading] = useState(false); const handleSubmit = useCatch(async ({ deviceIds, groupIds, from, to, mail, headers }) => { - const query = new URLSearchParams({ from, to, daily, mail }); - deviceIds.forEach((deviceId) => query.append('deviceId', deviceId)); - groupIds.forEach((groupId) => query.append('groupId', groupId)); - const response = await fetch(`/api/reports/summary?${query.toString()}`, { headers }); - if (response.ok) { - const contentType = response.headers.get('content-type'); - if (contentType) { - if (contentType === 'application/json') { - setItems(await response.json()); - } else { - window.location.assign(window.URL.createObjectURL(await response.blob())); + setLoading(true); + try { + const query = new URLSearchParams({ from, to, daily, mail }); + deviceIds.forEach((deviceId) => query.append('deviceId', deviceId)); + groupIds.forEach((groupId) => query.append('groupId', groupId)); + const response = await fetch(`/api/reports/summary?${query.toString()}`, { headers }); + if (response.ok) { + const contentType = response.headers.get('content-type'); + if (contentType) { + if (contentType === 'application/json') { + setItems(await response.json()); + } else { + window.location.assign(window.URL.createObjectURL(await response.blob())); + } } + } else { + throw Error(await response.text()); } - } else { - throw Error(await response.text()); + } finally { + setLoading(false); } }); @@ -107,7 +114,7 @@ const SummaryReportPage = () => { </TableRow> </TableHead> <TableBody> - {items.map((item) => ( + {!loading ? items.map((item) => ( <TableRow key={(`${item.deviceId}_${Date.parse(item.startTime)}`)}> {columns.map((key) => ( <TableCell key={key}> @@ -115,7 +122,7 @@ const SummaryReportPage = () => { </TableCell> ))} </TableRow> - ))} + )) : (<TableShimmer columns={columns.length} />)} </TableBody> </Table> </PageLayout> |