import { useRouter } from 'next/router' import { HTMLAttributes, useEffect, useState } from 'react' import { FaChevronLeft, FaUserPlus, FaUserXmark, FaX } from 'react-icons/fa6' import Thread from './Thread' import { Entity, MegalodonInterface } from 'megalodon' import Reply from './Reply' import Profile from './Profile' import Tag from './Tag' import { Account } from '@/db' import { useIntl } from 'react-intl' import { useTimelines } from '../layouts/timelines' type Props = { client: MegalodonInterface account: Account openMedia: (media: Array, index: number) => void } & HTMLAttributes export default function Detail(props: Props) { const [target, setTarget] = useState<'status' | 'reply' | 'profile' | 'tag' | null>(null) const router = useRouter() const { formatMessage } = useIntl() const [tagFollowing, setTagFollowing] = useState(false) const { reloadMenu } = useTimelines() useEffect(() => { if (router.query.status_id) { setTarget('status') } else if (router.query.reply_target_id) { setTarget('reply') } else if (router.query.user_id) { setTarget('profile') } else if (router.query.tag) { setTarget('tag') } else { setTarget(null) } }, [router.query]) useEffect(() => { if (router.query.tag) { refreshFollowing(router.query.tag as string) } else { setTagFollowing(false) } }, [router.query.tag]) const refreshFollowing = async (tag: string) => { const res = await props.client.getTag(tag) if (res.data.following) { setTagFollowing(true) } else { setTagFollowing(false) } } const back = () => { router.back() } const close = () => { router.push({ query: { id: router.query.id, timeline: router.query.timeline } }) } const followTag = async (tag: string) => { await props.client.followTag(tag) await refreshFollowing(tag) await reloadMenu() } const unfollowTag = async (tag: string) => { await props.client.unfollowTag(tag) await refreshFollowing(tag) await reloadMenu() } return ( <> {target && (
{target === 'tag' && `#${router.query.tag}`}
{target === 'tag' && ( <> {tagFollowing ? ( ) : ( )} )}
{target === 'status' && ( )} {target === 'reply' && ( )} {target === 'profile' && ( )} {target === 'tag' && ( )}
)} ) }