import { Account, db } from '@/db' import { Card, Chip, List, ListItem, ListItemPrefix, ListItemSuffix } from '@material-tailwind/react' import generator, { Entity, MegalodonInterface } from 'megalodon' import { useRouter } from 'next/router' import { createContext, useContext, useEffect, useState } from 'react' import { useHotkeys } from 'react-hotkeys-hook' import { FaBell, FaBookmark, FaGlobe, FaHouse, FaList, FaStar, FaUsers, FaHashtag } from 'react-icons/fa6' import { useIntl } from 'react-intl' import Jump from '../Jump' import { useUnreads } from '@/provider/unreads' type Context = { reloadMenu: () => Promise } const TimelinesContext = createContext({ reloadMenu: async () => {} }) TimelinesContext.displayName = 'TimelinesContext' export const useTimelines = () => { return useContext(TimelinesContext) } 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 [followedTags, setFollowedTags] = useState>([]) const [openJump, setOpenJump] = useState(false) const [client, setClient] = useState() 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') setClient(c) const f = async () => { const res = await c.getLists() setLists(res.data) } f() const g = async () => { const res = await c.getFollowedTags() setFollowedTags(res.data) } g() }, [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` } ] const reloadMenu = async () => { const res = await client.getFollowedTags() setFollowedTags(res.data) } return (
setOpenJump(false)} timelines={pages} />

{account?.username}

@{account?.domain}

{pages.map(page => ( router.push(page.path)} className="sidebar-menu-item theme-text-primary 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 theme-text-primary overflow-hidden whitespace-nowrap" title={list.title} >
{list.title}
))} {followedTags.map(tag => ( router.push({ pathname: `/accounts/${router.query.id}/tag_${tag.name}` })} className="sidebar-menu-item theme-text-primary overflow-hidden whitespace-nowrap" title={tag.name} >
{tag.name}
))}
{children}
) }