Merge pull request #1317 from geelongmicrosoldering/patch-3

Better User experience when getting data from API
This commit is contained in:
Anton Tananaev 2024-12-27 06:23:15 -08:00 committed by GitHub
commit 8a361471ad
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 18 additions and 12 deletions

View File

@ -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>

View File

@ -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