Skip to content

Commit 1fdcd24

Browse files
committed
Improve design of loading indicator
1 parent a43480d commit 1fdcd24

2 files changed

Lines changed: 61 additions & 17 deletions

File tree

Lines changed: 51 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,68 @@
11
import clsx from 'clsx'
2+
import {useEffect, useRef} from 'react'
3+
import FavIcon from "web/public/FavIcon";
4+
25
export type SpinnerSize = 'sm' | 'md' | 'lg'
36

4-
function getSizeClass(size: SpinnerSize) {
5-
switch (size) {
6-
case 'sm':
7-
return 'h-4 w-4 border-2'
8-
case 'md':
9-
return 'h-6 w-6 border-4'
10-
case 'lg':
11-
default:
12-
return 'h-8 w-8 border-4'
13-
}
14-
}
7+
// function getSizeClass(size: SpinnerSize) {
8+
// switch (size) {
9+
// case 'sm':
10+
// return 'h-4 w-4 border-2'
11+
// case 'md':
12+
// return 'h-6 w-6 border-4'
13+
// case 'lg':
14+
// default:
15+
// return 'h-8 w-8 border-4'
16+
// }
17+
// }
18+
1519

1620
export function LoadingIndicator(props: {
1721
className?: string
1822
spinnerClassName?: string
19-
size?: SpinnerSize
23+
size?: 'sm' | 'md' | 'lg'
2024
}) {
21-
const { className, spinnerClassName, size = 'lg' } = props
25+
const {className, spinnerClassName} = props
26+
const compassRef = useRef<HTMLDivElement>(null)
27+
28+
useEffect(() => {
29+
const el = compassRef.current
30+
if (!el) return
31+
32+
let angle = 0
33+
let timeoutId: number
34+
35+
const randomTurn = () => {
36+
// Randomly choose direction and angle
37+
const direction = Math.random() > 0.5 ? 1 : -1
38+
const delta = Math.random() * 75 + 5
39+
angle = direction * delta
40+
41+
el.style.transform = `rotate(${angle}deg)`
42+
43+
// Random delay before next movement
44+
const delay = Math.random() * 400 + 400
45+
timeoutId = window.setTimeout(randomTurn, delay)
46+
}
47+
48+
randomTurn()
49+
return () => clearTimeout(timeoutId)
50+
}, [])
51+
2252
return (
23-
<div className={clsx('flex items-center justify-center', className)}>
53+
<div className={clsx('flex items-center justify-center mt-8', className)}>
2454
<div
55+
ref={compassRef}
2556
className={clsx(
26-
'border-primary-500 inline-block animate-spin rounded-full border-solid border-r-transparent',
27-
getSizeClass(size),
57+
'inline-block transition-transform duration-700 ease-in-out',
58+
// getSizeClass(size),
2859
spinnerClassName
2960
)}
3061
role="status"
31-
/>
62+
>
63+
<FavIcon className="dark:invert w-20 h-20"/>
64+
</div>
3265
</div>
3366
)
3467
}
68+

web/pages/loading.tsx

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
"use client";
2+
3+
import {LoadingIndicator} from "web/components/widgets/loading-indicator";
4+
import {LovePage} from "web/components/love-page";
5+
6+
export default function Loading() {
7+
return <LovePage trackPageView={'loading'}>
8+
<LoadingIndicator/>
9+
</LovePage>;
10+
}

0 commit comments

Comments
 (0)