aboutsummaryrefslogtreecommitdiff
path: root/modern/src/reports/StopReportPage.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/StopReportPage.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/StopReportPage.js')
-rw-r--r--modern/src/reports/StopReportPage.js33
1 files changed, 20 insertions, 13 deletions
diff --git a/modern/src/reports/StopReportPage.js b/modern/src/reports/StopReportPage.js
index 9e42cb33..bacbe928 100644
--- a/modern/src/reports/StopReportPage.js
+++ b/modern/src/reports/StopReportPage.js
@@ -21,6 +21,7 @@ import MapPositions from '../map/MapPositions';
import MapView from '../map/core/MapView';
import MapCamera from '../map/MapCamera';
import AddressValue from '../common/components/AddressValue';
+import TableShimmer from '../common/components/TableShimmer';
const columnsArray = [
['startTime', 'reportStartTime'],
@@ -42,22 +43,28 @@ const StopReportPage = () => {
const [columns, setColumns] = usePersistedState('stopColumns', ['startTime', 'endTime', 'startOdometer', '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/stops?${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/stops?${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);
}
});
@@ -111,7 +118,7 @@ const StopReportPage = () => {
</TableRow>
</TableHead>
<TableBody>
- {items.map((item) => (
+ {!loading ? items.map((item) => (
<TableRow key={item.positionId}>
<TableCell className={classes.columnAction} padding="none">
{selectedItem === item ? (
@@ -130,7 +137,7 @@ const StopReportPage = () => {
</TableCell>
))}
</TableRow>
- ))}
+ )) : (<TableShimmer columns={columns.length + 1} startAction />)}
</TableBody>
</Table>
</div>