From 189996a34a946ee1cab5c5865a8bf3e895c11eb3 Mon Sep 17 00:00:00 2001 From: AkiraFukushima Date: Wed, 6 Dec 2023 01:02:10 +0900 Subject: [PATCH] refs #4653 Save the last account and go to there when opened --- renderer/pages/accounts/[id]/[timeline].tsx | 4 +++- renderer/pages/index.tsx | 11 ++++++++++- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/renderer/pages/accounts/[id]/[timeline].tsx b/renderer/pages/accounts/[id]/[timeline].tsx index ce8a7478..88bab026 100644 --- a/renderer/pages/accounts/[id]/[timeline].tsx +++ b/renderer/pages/accounts/[id]/[timeline].tsx @@ -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) { diff --git a/renderer/pages/index.tsx b/renderer/pages/index.tsx index 5db02c80..de887178 100644 --- a/renderer/pages/index.tsx +++ b/renderer/pages/index.tsx @@ -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()