mirror of
https://github.com/traccar/traccar-web.git
synced 2025-01-07 03:26:42 +08:00
Merge pull request #1317 from geelongmicrosoldering/patch-3
Better User experience when getting data from API
This commit is contained in:
commit
8a361471ad
@ -92,6 +92,7 @@ const ReplayPage = () => {
|
||||
const [to, setTo] = useState();
|
||||
const [expanded, setExpanded] = useState(true);
|
||||
const [playing, setPlaying] = useState(false);
|
||||
const [loading, setLoading] = useState(false);
|
||||
|
||||
const deviceName = useSelector((state) => {
|
||||
if (selectedDeviceId) {
|
||||
@ -131,22 +132,27 @@ const ReplayPage = () => {
|
||||
}, [setShowCard]);
|
||||
|
||||
const handleSubmit = useCatch(async ({ deviceId, from, to }) => {
|
||||
setLoading(true);
|
||||
setSelectedDeviceId(deviceId);
|
||||
setFrom(from);
|
||||
setTo(to);
|
||||
const query = new URLSearchParams({ deviceId, from, to });
|
||||
const response = await fetch(`/api/positions?${query.toString()}`);
|
||||
if (response.ok) {
|
||||
setIndex(0);
|
||||
const positions = await response.json();
|
||||
setPositions(positions);
|
||||
if (positions.length) {
|
||||
setExpanded(false);
|
||||
try {
|
||||
const response = await fetch(`/api/positions?${query.toString()}`);
|
||||
if (response.ok) {
|
||||
setIndex(0);
|
||||
const positions = await response.json();
|
||||
setPositions(positions);
|
||||
if (positions.length) {
|
||||
setExpanded(false);
|
||||
} else {
|
||||
throw Error(t('sharedNoData'));
|
||||
}
|
||||
} else {
|
||||
throw Error(t('sharedNoData'));
|
||||
throw Error(await response.text());
|
||||
}
|
||||
} else {
|
||||
throw Error(await response.text());
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
});
|
||||
|
||||
@ -213,7 +219,7 @@ const ReplayPage = () => {
|
||||
</div>
|
||||
</>
|
||||
) : (
|
||||
<ReportFilter handleSubmit={handleSubmit} fullScreen showOnly />
|
||||
<ReportFilter handleSubmit={handleSubmit} fullScreen showOnly loading={loading} />
|
||||
)}
|
||||
</Paper>
|
||||
</div>
|
||||
|
@ -186,7 +186,7 @@ const ReportFilter = ({
|
||||
disabled={disabled}
|
||||
onClick={() => handleClick('json')}
|
||||
>
|
||||
<Typography variant="button" noWrap>{t('reportShow')}</Typography>
|
||||
<Typography variant="button" noWrap>{t(loading ? 'sharedLoading' : 'reportShow')}</Typography>
|
||||
</Button>
|
||||
) : (
|
||||
<SplitButton
|
||||
|
Loading…
Reference in New Issue
Block a user