import emojify from '@/utils/emojify' import { Entity, MegalodonInterface } from 'megalodon' import { MouseEventHandler, useEffect, useState } from 'react' import { FaEllipsisVertical } from 'react-icons/fa6' import { FormattedMessage, useIntl } from 'react-intl' import Timeline from './profile/Timeline' import Followings from './profile/Followings' import Followers from './profile/Followers' import { findLink } from '@/utils/statusParser' import { Account } from '@/db' import { Avatar, Button, IconButton, List, ListItem, Popover, PopoverContent, PopoverHandler, Tab, TabPanel, Tabs, TabsBody, TabsHeader } from '@material-tailwind/react' import { domainFromAcct } from '@/utils/domain' import { invoke } from '@/utils/invoke' type Props = { client: MegalodonInterface account: Account user_id: string openMedia: (media: Array, index: number) => void } export default function Profile(props: Props) { const [user, setUser] = useState(null) const [relationship, setRelationship] = useState(null) const [popoverDetail, setPopoverDetail] = useState(false) const [domain, setDomain] = useState(null) const { formatMessage } = useIntl() useEffect(() => { const f = async () => { if (props.user_id) { const res = await props.client.getAccount(props.user_id) setUser(res.data) setDomain(domainFromAcct(res.data.acct)) await refresh() } } f() }, [props.user_id, props.client]) const refresh = async () => { const rel = await props.client.getRelationship(props.user_id) setRelationship(rel.data) } const follow = async (id: string) => { const rel = await props.client.followAccount(id) setRelationship(rel.data) } const unfollow = async (id: string) => { const rel = await props.client.unfollowAccount(id) setRelationship(rel.data) } const openOriginal = async (url: string) => { invoke('open-browser', url) } const block = async () => { if (user) { await props.client.blockAccount(user.id) await refresh() } } const unblock = async () => { if (user) { await props.client.unblockAccount(user.id) await refresh() } } const mute = async () => { if (user) { await props.client.muteAccount(user.id, false) await refresh() } } const unmute = async () => { if (user) { await props.client.unmuteAccount(user.id) await refresh() } } const blockDomain = async () => { if (user && domain) { await props.client.blockDomain(domain) await refresh() } } const unblockDomain = async () => { if (user && domain) { await props.client.unblockDomain(domain) await refresh() } } const profileClicked: MouseEventHandler = async e => { const url = findLink(e.target as HTMLElement, 'profile') if (url) { invoke('open-browser', url) e.preventDefault() e.stopPropagation() } } return (
{user && relationship && ( <>
{formatMessage({
{relationship.following ? ( ) : ( )} { openOriginal(user.url) setPopoverDetail(false) }} > {relationship.blocking ? ( { unblock() setPopoverDetail(false) }} > ) : ( { block() setPopoverDetail(false) }} > )} {relationship.muting ? ( { unmute() setPopoverDetail(false) }} > ) : ( { mute() setPopoverDetail(false) }} > )} {relationship.domain_blocking ? ( { blockDomain() setPopoverDetail(false) }} > ) : ( { unblockDomain() setPopoverDetail(false) }} > )}
@{user.acct}
{user.fields.map((data, index) => (
{data.name}
))}
)}
) }