Updating ui
This commit is contained in:
33
ui/src/components/Loader.tsx
Normal file
33
ui/src/components/Loader.tsx
Normal file
@@ -0,0 +1,33 @@
|
||||
'use client';
|
||||
|
||||
import { refresh } from "@/api/auth";
|
||||
import { userState } from "@/state/auth";
|
||||
import { Skeleton } from "@mantine/core";
|
||||
import { useEffect, useState } from "react";
|
||||
import { useRecoilState } from "recoil";
|
||||
|
||||
export default function Loading({ children }: { children: React.ReactNode }) {
|
||||
const [loading, setLoading] = useState(true);
|
||||
const [user, setUser] = useRecoilState(userState);
|
||||
|
||||
useEffect(() => {
|
||||
checkUser();
|
||||
}, []);
|
||||
|
||||
async function checkUser() {
|
||||
setLoading(true);
|
||||
if (!user) {
|
||||
const response = await refresh();
|
||||
if (response) {
|
||||
setUser(response.user);
|
||||
}
|
||||
}
|
||||
setLoading(false);
|
||||
}
|
||||
|
||||
if (loading) {
|
||||
return <Skeleton height={'100%'} />;
|
||||
} else {
|
||||
return <>{children}</>;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user