-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLoadingSpinner.tsx
45 lines (43 loc) · 1.21 KB
/
LoadingSpinner.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import { SpinnerCircular } from "spinners-react";
import { LoaderState } from "../hooks/useLoader";
export function LoadingSpinner({ loader }: { loader: LoaderState<unknown> }): JSX.Element {
switch (loader.type) {
case "loading":
return (
<div className="flex">
<SpinnerCircular size={30} thickness={300} />
<span className="ml-2">{loader.count === 0 ? "Loading..." : "Still loading..."}</span>
</div>
);
case "loading-slowly":
return (
<div className="flex">
<SpinnerCircular size={30} thickness={300} />
<span className="ml-2">It's taking longer than expected.</span>
</div>
);
case "failed-attempt":
return (
<p className="text-red-800">
Encountered and error: {loader.error.message}.
</p>
)
case "retrying":
return (
<p className="text-red-800">
Retrying...
</p>
)
case "success":
return (
<p className="text-green-800">{`${loader.value}`}</p>
)
case "failed":
return (
<p className="text-red-800">
Failed after 3 attempts. Please contact support.
</p>
)
}
return <></>
}