import { Account, db } from '@/db' import { Card, Chip, List, ListItem, ListItemPrefix, ListItemSuffix } from '@material-tailwind/react' import generator, { Entity } from 'megalodon' import { useRouter } from 'next/router' import { useEffect, useState } from 'react' import { useHotkeys } from 'react-hotkeys-hook' import { FaBell, FaBookmark, FaGlobe, FaHouse, FaList, FaStar, FaUsers } from 'react-icons/fa6' import { useIntl } from 'react-intl' import Jump from '../Jump' import { useUnreads } from '@/provider/unreads' type LayoutProps = { children: React.ReactNode } export type Timeline = { id: string title: string icon: JSX.Element path: string } export default function Layout({ children }: LayoutProps) { const router = useRouter() const { formatMessage } = useIntl() const { unreads } = useUnreads() const [account, setAccount] = useState(null) const [lists, setLists] = useState>([]) const [openJump, setOpenJump] = useState(false) useHotkeys('mod+k', () => setOpenJump(current => !current)) useEffect(() => { if (router.query.id) { const f = async () => { const acct = await db.accounts.get(parseInt(router.query.id as string)) if (!acct) return setAccount(acct) } f() } }, [router.query.id]) useEffect(() => { if (!account) return const c = generator(account.sns, account.url, account.access_token, 'Whalebird') const f = async () => { const res = await c.getLists() setLists(res.data) } f() }, [account]) const pages: Array = [ { id: 'home', title: formatMessage({ id: 'timeline.home' }), icon: , path: `/accounts/${router.query.id}/home` }, { id: 'notifications', title: formatMessage({ id: 'timeline.notifications' }), icon: , path: `/accounts/${router.query.id}/notifications` }, { id: 'local', title: formatMessage({ id: 'timeline.local' }), icon: , path: `/accounts/${router.query.id}/local` }, { id: 'public', title: formatMessage({ id: 'timeline.public' }), icon: , path: `/accounts/${router.query.id}/public` }, { id: 'favourites', title: formatMessage({ id: 'timeline.favourites' }), icon: , path: `/accounts/${router.query.id}/favourites` }, { id: 'bookmarks', title: formatMessage({ id: 'timeline.bookmarks' }), icon: , path: `/accounts/${router.query.id}/bookmarks` } ] return (
setOpenJump(false)} timelines={pages} />

{account?.username}

@{account?.domain}

{pages.map(page => ( router.push(page.path)} className="sidebar-menu-item text-blue-100 overflow-hidden whitespace-nowrap" title={page.title} > {page.icon} {page.title} {page.id === 'notifications' && unreads[account?.id?.toString()] ? ( ) : null} ))} {lists.map(list => ( router.push({ pathname: `/accounts/${router.query.id}/list_${list.id}` })} className="sidebar-menu-item text-blue-100 overflow-hidden whitespace-nowrap" title={list.title} >
{list.title}
))}
{children}
) }