I'm tired

This commit is contained in:
Ren Amamiya
2023-03-23 13:03:34 +07:00
parent b3baacb3e0
commit 705430a11e
6 changed files with 80 additions and 75 deletions

View File

@@ -1,35 +1,26 @@
import BaseLayout from '@layouts/base';
import { getActiveAccount } from '@utils/storage';
import LumeSymbol from '@assets/icons/Lume';
import { useLocalStorage } from '@rehooks/local-storage';
import { useRouter } from 'next/router';
import { JSXElementConstructor, ReactElement, ReactFragment, ReactPortal, useEffect, useRef, useState } from 'react';
import { JSXElementConstructor, ReactElement, ReactFragment, ReactPortal, useEffect } from 'react';
export default function Page() {
const router = useRouter();
const [currentUser]: object[] = useLocalStorage('current-user');
const [loading, setLoading] = useState(true);
const timer = useRef(null);
useEffect(() => {
if (currentUser) {
timer.current = setTimeout(() => {
setLoading(false);
router.push('/newsfeed/following');
}, 1000);
} else {
timer.current = setTimeout(() => {
setLoading(false);
router.push('/onboarding');
}, 1000);
}
// clean up
return () => {
clearTimeout(timer.current);
};
}, [currentUser, router]);
getActiveAccount()
.then((res: any[]) => {
if (res.length > 0) {
router.push('/newsfeed/following');
} else {
router.push('/onboarding');
}
})
.catch(console.error);
}, [router]);
return (
<div className="relative h-full overflow-hidden">
@@ -47,21 +38,19 @@ export default function Page() {
</div>
</div>
<div className="absolute bottom-16 left-1/2 -translate-x-1/2 transform">
{loading && (
<svg
className="h-5 w-5 animate-spin text-black dark:text-white"
xmlns="http://www.w3.org/2000/svg"
fill="none"
viewBox="0 0 24 24"
>
<circle className="opacity-25" cx="12" cy="12" r="10" stroke="currentColor" strokeWidth="4"></circle>
<path
className="opacity-75"
fill="currentColor"
d="M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z"
></path>
</svg>
)}
<svg
className="h-5 w-5 animate-spin text-black dark:text-white"
xmlns="http://www.w3.org/2000/svg"
fill="none"
viewBox="0 0 24 24"
>
<circle className="opacity-25" cx="12" cy="12" r="10" stroke="currentColor" strokeWidth="4"></circle>
<path
className="opacity-75"
fill="currentColor"
d="M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z"
></path>
</svg>
</div>
</div>
</div>