aboutsummaryrefslogtreecommitdiff
path: root/modern/src/reports/TripReportPage.js
diff options
context:
space:
mode:
authorAnton Tananaev <anton@traccar.org>2022-06-20 08:52:38 -0700
committerAnton Tananaev <anton@traccar.org>2022-06-20 08:52:38 -0700
commitb84fa9a5ee0d68dd922b2fb13a62e9b453397da0 (patch)
treef8d98846b18ebe8b7af916147964551cebab6208 /modern/src/reports/TripReportPage.js
parentd2de65460577a46dfa20f8df6870b10fa9c7d49e (diff)
downloadtrackermap-web-b84fa9a5ee0d68dd922b2fb13a62e9b453397da0.tar.gz
trackermap-web-b84fa9a5ee0d68dd922b2fb13a62e9b453397da0.tar.bz2
trackermap-web-b84fa9a5ee0d68dd922b2fb13a62e9b453397da0.zip
Add shimmer to reports
Diffstat (limited to 'modern/src/reports/TripReportPage.js')
-rw-r--r--modern/src/reports/TripReportPage.js33
1 files changed, 20 insertions, 13 deletions
diff --git a/modern/src/reports/TripReportPage.js b/modern/src/reports/TripReportPage.js
index d2b4d9ef..5ad51f00 100644
--- a/modern/src/reports/TripReportPage.js
+++ b/modern/src/reports/TripReportPage.js
@@ -19,6 +19,7 @@ import useReportStyles from './common/useReportStyles';
import MapView from '../map/core/MapView';
import MapRoutePath from '../map/MapRoutePath';
import AddressValue from '../common/components/AddressValue';
+import TableShimmer from '../common/components/TableShimmer';
const columnsArray = [
['startTime', 'reportStartTime'],
@@ -46,6 +47,7 @@ const TripReportPage = () => {
const [columns, setColumns] = usePersistedState('tripColumns', ['startTime', 'endTime', 'distance', 'averageSpeed']);
const [items, setItems] = useState([]);
+ const [loading, setLoading] = useState(false);
const [selectedItem, setSelectedItem] = useState(null);
const [route, setRoute] = useState(null);
@@ -72,19 +74,24 @@ const TripReportPage = () => {
}, [selectedItem]);
const handleSubmit = useCatch(async ({ deviceId, from, to, mail, headers }) => {
- const query = new URLSearchParams({ deviceId, from, to, mail });
- const response = await fetch(`/api/reports/trips?${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/trips?${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);
}
});
@@ -137,7 +144,7 @@ const TripReportPage = () => {
</TableRow>
</TableHead>
<TableBody>
- {items.map((item) => (
+ {!loading ? items.map((item) => (
<TableRow key={item.startPositionId}>
<TableCell className={classes.columnAction} padding="none">
{selectedItem === item ? (
@@ -156,7 +163,7 @@ const TripReportPage = () => {
</TableCell>
))}
</TableRow>
- ))}
+ )) : (<TableShimmer columns={columns.length + 1} startAction />)}
</TableBody>
</Table>
</div>