import { Avatar } from 'flowbite-react' import { Entity, MegalodonInterface } from 'megalodon' import dayjs from 'dayjs' import Body from './Body' import Media from './Media' import emojify from '@/utils/emojify' import Card from './Card' import Poll from './Poll' import { FormattedMessage } from 'react-intl' import Actions from './Actions' import { useRouter } from 'next/router' import { MouseEventHandler, useState } from 'react' import { findLink } from '@/utils/statusParser' type Props = { status: Entity.Status client: MegalodonInterface onRefresh: (status: Entity.Status) => void openMedia: (media: Entity.Attachment) => void } export default function Status(props: Props) { const status = originalStatus(props.status) const [spoilered, setSpoilered] = useState(status.spoiler_text.length > 0) const router = useRouter() const onRefresh = async () => { const res = await props.client.getStatus(status.id) props.onRefresh(res.data) } const openStatus = () => { router.push({ query: { id: router.query.id, timeline: router.query.timeline, status_id: status.id, detail: true } }) } const openUser = (id: string) => { router.push({ query: { id: router.query.id, timeline: router.query.timeline, user_id: id, detail: true } }) } const statusClicked: MouseEventHandler = async e => { const url = findLink(e.target as HTMLElement, 'status-body') if (url) { global.ipc.invoke('open-browser', url) e.preventDefault() e.stopPropagation() } } return (
{rebloggedHeader(props.status)}
openUser(status.account.id)} />
openUser(status.account.id)}> @{status.account.acct}
{!spoilered && ( <> {status.poll && } {status.card && } )}
) } const originalStatus = (status: Entity.Status) => { if (status.reblog && !status.quote) { return status.reblog } else { return status } } const rebloggedHeader = (status: Entity.Status) => { if (status.reblog && !status.quote) { return (
) } else { return null } }