Merge pull request #4694 from h3poteto/iss-4653/save-account

refs #4653 Save the last account and go to there when opened
This commit is contained in:
AkiraFukushima 2023-12-06 01:05:00 +09:00 committed by GitHub
commit 391b31fb8e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 2 deletions

View File

@ -14,7 +14,9 @@ export default function Page() {
useEffect(() => {
if (router.query.id) {
console.log(router)
if (router.query.id && typeof localStorage !== 'undefined') {
localStorage.setItem('lastAccount', router.query.id as string)
}
const f = async () => {
const a = await db.accounts.get(parseInt(router.query.id as string))
if (a) {

View File

@ -11,7 +11,16 @@ export default function Index() {
const f = async () => {
const accounts = await db.accounts.toArray()
if (accounts.length > 0) {
router.push(`/accounts/${accounts[0].id}`)
if (typeof localStorage !== 'undefined') {
const lastAccount = localStorage.getItem(`lastAccount`)
if (lastAccount) {
router.push(`/accounts/${lastAccount}`)
} else {
router.push(`/accounts/${accounts[0].id}`)
}
} else {
router.push(`/accounts/${accounts[0].id}`)
}
}
}
f()