handle bookmark delete loading state
This commit is contained in:
24
packages/web/src/components/loading-spinner.tsx
Normal file
24
packages/web/src/components/loading-spinner.tsx
Normal file
@@ -0,0 +1,24 @@
|
||||
import { useState, useEffect, useRef } from "react"
|
||||
|
||||
// courtesy of https://github.com/sindresorhus/cli-spinners
|
||||
const FRAMES = ["-", "\\", "|", "/"]
|
||||
|
||||
function LoadingSpinner() {
|
||||
const [frame, setFrame] = useState(0)
|
||||
const timer = useRef<ReturnType<typeof setInterval>>(null)
|
||||
|
||||
useEffect(() => {
|
||||
timer.current = setInterval(() => {
|
||||
setFrame((frame) => (frame === 3 ? 0 : frame + 1))
|
||||
}, 100)
|
||||
return () => {
|
||||
if (timer.current) {
|
||||
clearInterval(timer.current)
|
||||
}
|
||||
}
|
||||
}, [])
|
||||
|
||||
return <span className="whitespace-pre">{FRAMES[frame]}</span>
|
||||
}
|
||||
|
||||
export { LoadingSpinner }
|
Reference in New Issue
Block a user