2023-11-02 01:20:27 +09:00
|
|
|
import { useRouter } from 'next/router'
|
|
|
|
import { useEffect } from 'react'
|
|
|
|
import { db } from '@/db'
|
2024-01-09 21:30:05 +09:00
|
|
|
import { Spinner } from '@material-tailwind/react'
|
2023-11-02 01:20:27 +09:00
|
|
|
|
|
|
|
export default function Index() {
|
|
|
|
const router = useRouter()
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
const f = async () => {
|
|
|
|
const accounts = await db.accounts.toArray()
|
|
|
|
if (accounts.length > 0) {
|
2023-12-06 01:02:10 +09:00
|
|
|
if (typeof localStorage !== 'undefined') {
|
|
|
|
const lastAccount = localStorage.getItem(`lastAccount`)
|
2024-01-12 22:14:33 +09:00
|
|
|
if (parseInt(lastAccount) >= 0) {
|
2023-12-06 01:02:10 +09:00
|
|
|
router.push(`/accounts/${lastAccount}`)
|
|
|
|
} else {
|
|
|
|
router.push(`/accounts/${accounts[0].id}`)
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
router.push(`/accounts/${accounts[0].id}`)
|
|
|
|
}
|
2023-11-02 01:20:27 +09:00
|
|
|
}
|
|
|
|
}
|
|
|
|
f()
|
|
|
|
}, [])
|
|
|
|
|
|
|
|
return (
|
|
|
|
<div className="h-screen w-full flex justify-center items-center">
|
2024-01-09 21:30:05 +09:00
|
|
|
<Spinner />
|
2023-11-02 01:20:27 +09:00
|
|
|
</div>
|
|
|
|
)
|
|
|
|
}
|