import {useCallback, useEffect, useState} from 'react'; import {Link} from 'react-router-dom'; import {useTranslation} from 'react-i18next'; import {Users} from 'lucide-react'; import {toast} from 'sonner'; import {Button} from '@/components/ui/button'; import {Card, CardContent, CardHeader, CardTitle} from '@/components/ui/card'; import {fetchFollows, removeFollow} from '../utils/follows.js'; import {profileHref} from '../utils/people.js'; export default function FollowsCard() { const {t} = useTranslation(); const [follows, setFollows] = useState(null); const [failed, setFailed] = useState(false); const load = useCallback(async () => { const {ok, data} = await fetchFollows(); setFailed(!ok); if (ok) setFollows(data); }, []); useEffect(() => { load(); }, [load]); const end = async (id) => { const {ok, status} = await removeFollow(id); if (!ok && status !== 401) toast.error(t('FOLLOW.ERROR')); await load(); }; const link = (displayName) => ( {displayName} ); return ( {t('FOLLOW.TITLE')} {failed &&

{t('FOLLOW.LOAD_ERROR')}

} {follows && ( <>

{t('FOLLOW.FOLLOWING')}

{follows.following.length === 0 &&

{t('FOLLOW.NO_FOLLOWING')}

}
    {follows.following.map((entry) => (
  • {link(entry.displayName)}
  • ))}

{t('FOLLOW.FOLLOWERS')}

{follows.followers.length === 0 &&

{t('FOLLOW.NO_FOLLOWERS')}

}
    {follows.followers.map((entry) => (
  • {entry.displayName ? link(entry.displayName) : {t('FOLLOW.PRIVATE_USER')}}
  • ))}
)}
); }