import { Entity, MegalodonInterface } from 'megalodon' import { useRouter } from 'next/router' import { useEffect, useState } from 'react' import { FormattedMessage } from 'react-intl' import User from './followRequests/User' import Detail from '../detail/Detail' import { Account } from '@/db' import { useUnreads } from '@/provider/unreads' type Props = { client: MegalodonInterface account: Account openMedia: (media: Array, index: number) => void } export default function FollowRequests(props: Props) { const router = useRouter() const { setUnreads } = useUnreads() const [requests, setRequests] = useState>([]) useEffect(() => { refreshRequests() }, []) const refreshRequests = async () => { const res = await props.client.getFollowRequests() setRequests(res.data) return res.data } const updateUnreads = (length: number) => { setUnreads(current => Object.assign({}, current, { [`${props.account.id?.toString()}_follow_requests`]: length }) ) } const timelineClass = () => { if (router.query.detail) { return 'timeline-with-drawer' } return 'timeline' } return ( <>
{requests.map(r => ( <> { const data = await refreshRequests() updateUnreads(data.length) }} /> ))}
) }