From 84b3f8913d1120a218f56c8a13c06f4bda093061 Mon Sep 17 00:00:00 2001 From: Vitaly Turovsky Date: Wed, 30 Oct 2024 23:53:45 +0300 Subject: [PATCH] fix: don't make text move in loading screens --- src/react/AppStatus.tsx | 40 ++++++++++++++++++++++++---------------- 1 file changed, 24 insertions(+), 16 deletions(-) diff --git a/src/react/AppStatus.tsx b/src/react/AppStatus.tsx index 31f086415..19b4abbfe 100644 --- a/src/react/AppStatus.tsx +++ b/src/react/AppStatus.tsx @@ -14,27 +14,26 @@ export default ({ actionsSlot = null as React.ReactNode | null, children }) => { - const [loadingDots, setLoadingDots] = useState('') + const [loadingDotIndex, setLoadingDotIndex] = useState(0) useEffect(() => { - void statusRunner() - }, []) - - const statusRunner = async () => { - const array = ['.', '..', '...', ''] - - const timer = async (ms) => new Promise((resolve) => { setTimeout(resolve, ms) }) + const statusRunner = async () => { + const timer = async (ms) => new Promise((resolve) => { setTimeout(resolve, ms) }) - const load = async () => { - // eslint-disable-next-line no-constant-condition - for (let i = 0; true; i = (i + 1) % array.length) { - setLoadingDots(array[i]) - await timer(500) // eslint-disable-line no-await-in-loop + const load = async () => { + // eslint-disable-next-line no-constant-condition + while (true) { + setLoadingDotIndex(i => (i + 1) % 4) + await timer(500) // eslint-disable-line no-await-in-loop + } } + + void load() } - void load() - } + void statusRunner() + }, []) + return ( {status} - {isError || hideDots ? '' : loadingDots} +

{description}

{lastStatus ? `Last status: ${lastStatus}` : lastStatus}