import clsx from 'clsx' import Link from 'next/link' import {useEffect, useMemo, useState} from 'react' import toast from 'react-hot-toast' import {Button} from 'web/components/buttons/button' import {Col} from 'web/components/layout/col' import {Modal, MODAL_CLASS, SCROLLABLE_MODAL_CLASS} from 'web/components/layout/modal' import {Row} from 'web/components/layout/row' import {Avatar} from 'web/components/widgets/avatar' import {Title} from 'web/components/widgets/title' import {useHiddenProfiles} from 'web/hooks/use-hidden-profiles' import {api} from 'web/lib/api' import {useT} from 'web/lib/locale' export function HiddenProfilesModal(props: {open: boolean; setOpen: (open: boolean) => void}) { const {open, setOpen} = props const t = useT() const [busyIds, setBusyIds] = useState>({}) const {hiddenProfiles, refreshHiddenProfiles} = useHiddenProfiles() const empty = useMemo( () => (hiddenProfiles ? hiddenProfiles.length === 0 : false), [hiddenProfiles], ) useEffect(() => { if (!open) return refreshHiddenProfiles() }, [open]) const unhide = async (userId: string) => { if (busyIds[userId]) return setBusyIds((b) => ({...b, [userId]: true})) try { await api('unhide-profile', {hiddenUserId: userId}) refreshHiddenProfiles() } catch (e) { console.error('Failed to unhide profile', e) toast.error(t('settings.hidden_profiles.unhide_failed', 'Failed to unhide')) } finally { // setBusyIds((b) => ({...b, [userId]: false})) } } return ( {t('settings.hidden_profiles.title', "Profiles you've hidden")} {hiddenProfiles && hiddenProfiles.length > 0 && ( {hiddenProfiles.map((u) => (
{u.name}
@{u.username}
))} )} {empty && (
{t('settings.hidden_profiles.empty', "You haven't hidden any profiles.")}
)}
) } export default HiddenProfilesModal