Skip to content

Commit

Permalink
Merge pull request #1317 from geelongmicrosoldering/patch-3
Browse files Browse the repository at this point in the history
Better User experience when getting data from API
  • Loading branch information
tananaev authored Dec 27, 2024
2 parents 582af9c + 712de60 commit 8a36147
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 12 deletions.
28 changes: 17 additions & 11 deletions src/other/ReplayPage.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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);
}
});

Expand Down Expand Up @@ -213,7 +219,7 @@ const ReplayPage = () => {
</div>
</>
) : (
<ReportFilter handleSubmit={handleSubmit} fullScreen showOnly />
<ReportFilter handleSubmit={handleSubmit} fullScreen showOnly loading={loading} />
)}
</Paper>
</div>
Expand Down
2 changes: 1 addition & 1 deletion src/reports/components/ReportFilter.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 8a36147

Please sign in to comment.