feat: add loading indicator

This commit is contained in:
trafficlunar 2024-12-22 21:17:43 +00:00
parent a93073caf9
commit 41ab349e43
8 changed files with 70 additions and 22 deletions

26
src/context/Loading.tsx Normal file
View file

@ -0,0 +1,26 @@
import { createContext, ReactNode, useState } from "react";
import LoadingIndicator from "@/assets/loading.svg?react";
interface Props {
children: ReactNode;
}
export const LoadingContext = createContext({
loading: false,
setLoading: ((value: boolean) => {}) as React.Dispatch<React.SetStateAction<boolean>>,
});
export const LoadingProvider = ({ children }: Props) => {
const [loading, setLoading] = useState(true);
return (
<LoadingContext.Provider value={{ loading, setLoading }}>
{loading && (
<div className="absolute w-full h-full z-[9999] backdrop-brightness-50 flex justify-center items-center gap-4">
<LoadingIndicator fill="white" className="w-16 h-16" />
</div>
)}
{children}
</LoadingContext.Provider>
);
};