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/RouteReportPage.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/RouteReportPage.js')
-rw-r--r-- | modern/src/reports/RouteReportPage.js | 33 |
1 files changed, 20 insertions, 13 deletions
diff --git a/modern/src/reports/RouteReportPage.js b/modern/src/reports/RouteReportPage.js index 5796e80c..1c24a15b 100644 --- a/modern/src/reports/RouteReportPage.js +++ b/modern/src/reports/RouteReportPage.js @@ -17,6 +17,7 @@ import MapView from '../map/core/MapView'; import MapRoutePath from '../map/MapRoutePath'; import MapPositions from '../map/MapPositions'; import useReportStyles from './common/useReportStyles'; +import TableShimmer from '../common/components/TableShimmer'; const RouteReportPage = () => { const classes = useReportStyles(); @@ -26,22 +27,28 @@ const RouteReportPage = () => { const [columns, setColumns] = usePersistedState('routeColumns', ['fixTime', 'latitude', 'longitude', 'speed', 'address']); const [items, setItems] = useState([]); + const [loading, setLoading] = useState(false); const [selectedItem, setSelectedItem] = useState(null); const handleSubmit = useCatch(async ({ deviceId, from, to, mail, headers }) => { - const query = new URLSearchParams({ deviceId, from, to, mail }); - const response = await fetch(`/api/reports/route?${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({ deviceId, from, to, mail }); + const response = await fetch(`/api/reports/route?${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); } }); @@ -74,7 +81,7 @@ const RouteReportPage = () => { </TableRow> </TableHead> <TableBody> - {items.map((item) => ( + {!loading ? items.map((item) => ( <TableRow key={item.id}> <TableCell className={classes.columnAction} padding="none"> {selectedItem === item ? ( @@ -97,7 +104,7 @@ const RouteReportPage = () => { </TableCell> ))} </TableRow> - ))} + )) : (<TableShimmer columns={columns.length + 1} startAction />)} </TableBody> </Table> </div> |