Whalebird-desktop-client-ma.../renderer/pages/accounts/[id]/[timeline].tsx

51 lines
1.7 KiB
TypeScript
Raw Normal View History

2023-11-01 17:20:27 +01:00
import { useRouter } from 'next/router'
2023-11-03 12:37:40 +01:00
import Timeline from '@/components/timelines/Timeline'
import { useEffect, useState } from 'react'
2023-11-03 12:37:40 +01:00
import { Account, db } from '@/db'
2023-12-02 11:26:45 +01:00
import generator, { Entity, MegalodonInterface } from 'megalodon'
2023-11-04 10:14:00 +01:00
import Notifications from '@/components/timelines/Notifications'
2023-12-02 11:26:45 +01:00
import Media from '@/components/Media'
2023-11-01 17:20:27 +01:00
2023-11-03 12:37:40 +01:00
export default function Page() {
2023-11-01 17:20:27 +01:00
const router = useRouter()
2023-11-03 12:37:40 +01:00
const [account, setAccount] = useState<Account | null>(null)
const [client, setClient] = useState<MegalodonInterface>(null)
2023-12-02 11:26:45 +01:00
const [attachment, setAttachment] = useState<Entity.Attachment | null>(null)
2023-11-03 12:37:40 +01:00
useEffect(() => {
if (router.query.id) {
2023-11-15 16:15:44 +01:00
console.log(router)
2023-11-03 12:37:40 +01:00
const f = async () => {
const a = await db.accounts.get(parseInt(router.query.id as string))
if (a) {
setAccount(a)
const c = generator(a.sns, a.url, a.access_token, 'Whalebird')
setClient(c)
}
}
f()
}
}, [router.query.id])
useEffect(() => {
if (router.query.timeline && router.query.id && typeof localStorage !== 'undefined') {
localStorage.setItem(`${router.query.id}_lastTimeline`, router.query.timeline as string)
}
}, [router.query.id, router.query.timeline])
2023-11-04 10:14:00 +01:00
if (!account || !client) return null
switch (router.query.timeline as string) {
case 'notifications': {
2023-12-02 11:26:45 +01:00
return <Notifications account={account} client={client} setAttachment={setAttachment} />
2023-11-04 10:14:00 +01:00
}
default: {
2023-12-02 11:26:45 +01:00
return (
<>
<Timeline timeline={router.query.timeline as string} account={account} client={client} setAttachment={setAttachment} />
<Media open={attachment !== null} close={() => setAttachment(null)} attachment={attachment} />
</>
)
2023-11-04 10:14:00 +01:00
}
}
2023-11-01 17:20:27 +01:00
}