From c3f9846a7467c2321dd4eccdb8aa445045694a8f Mon Sep 17 00:00:00 2001 From: microsoldering Date: Fri, 27 Dec 2024 15:36:51 +1100 Subject: [PATCH] Update ReplayPage.jsx Disable "Show" button while we wait for api response. Prevents subsequent API requests until the first one has returned --- src/other/ReplayPage.jsx | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/other/ReplayPage.jsx b/src/other/ReplayPage.jsx index ce3b3467..da1ac01c 100644 --- a/src/other/ReplayPage.jsx +++ b/src/other/ReplayPage.jsx @@ -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,6 +132,7 @@ const ReplayPage = () => { }, [setShowCard]); const handleSubmit = useCatch(async ({ deviceId, from, to }) => { + setLoading(true); setSelectedDeviceId(deviceId); setFrom(from); setTo(to); @@ -140,12 +142,14 @@ const ReplayPage = () => { setIndex(0); const positions = await response.json(); setPositions(positions); + setLoading(false); if (positions.length) { setExpanded(false); } else { throw Error(t('sharedNoData')); } } else { + setLoading(false); throw Error(await response.text()); } }); @@ -213,7 +217,7 @@ const ReplayPage = () => { ) : ( - + )}