Skip to content

Commit

Permalink
fix: don't make text move in loading screens
Browse files Browse the repository at this point in the history
  • Loading branch information
zardoy committed Oct 30, 2024
1 parent 03c6a3f commit 84b3f89
Showing 1 changed file with 24 additions and 16 deletions.
40 changes: 24 additions & 16 deletions src/react/AppStatus.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
<Screen
Expand All @@ -48,7 +47,16 @@ export default ({
>
{status}
</span>
{isError || hideDots ? '' : loadingDots}
<div style={{ display: 'inline-flex', gap: '1px', }} hidden={hideDots || isError}>
{
[...'...'].map((dot, i) => {
return <span
key={i} style={{
visibility: loadingDotIndex <= i ? 'hidden' : 'visible',
}}>{dot}</span>
})
}
</div>
<p className={styles['potential-problem']}>{description}</p>
<p className={styles['last-status']}>{lastStatus ? `Last status: ${lastStatus}` : lastStatus}</p>
</>
Expand Down

0 comments on commit 84b3f89

Please sign in to comment.