1
0
mirror of https://github.com/h3poteto/whalebird-desktop synced 2024-12-26 00:33:59 +01:00
Whalebird-desktop-client-ma.../renderer/pages/accounts/[id]/[timeline].tsx

63 lines
2.3 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-12-12 16:49:00 +01:00
import Report from '@/components/report/Report'
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-12-12 16:49:00 +01:00
const [report, setReport] = useState<Entity.Status | null>(null)
2023-11-03 12:37:40 +01:00
useEffect(() => {
if (router.query.id) {
if (router.query.id && typeof localStorage !== 'undefined') {
localStorage.setItem('lastAccount', router.query.id as string)
}
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-12-12 16:49:00 +01:00
useEffect(() => {
if (router.query.modal && router.query.report_target_id) {
const f = async () => {
const res = await client.getStatus(router.query.report_target_id as string)
setReport(res.data)
}
f()
}
}, [router.query.modal, router.query.report_target_id])
2023-11-04 10:14:00 +01:00
if (!account || !client) return null
return (
<>
{(router.query.timeline as string) === 'notifications' ? (
<Notifications account={account} client={client} setAttachment={setAttachment} />
) : (
<Timeline timeline={router.query.timeline as string} account={account} client={client} setAttachment={setAttachment} />
)}
<Media open={attachment !== null} close={() => setAttachment(null)} attachment={attachment} />
{report && <Report open={report !== null} close={() => setReport(null)} status={report} client={client} />}
</>
)
2023-11-01 17:20:27 +01:00
}