import { useEffect } from 'react'; import type { FC } from 'react'; import { defineMessage, FormattedMessage } from 'react-intl'; import { useDebouncedCallback } from 'use-debounce'; import { expandFollowers, fetchFollowers, } from '@/flavours/glitch/actions/accounts'; import { useAccount } from '@/flavours/glitch/hooks/useAccount'; import { useAccountId } from '@/flavours/glitch/hooks/useAccountId'; import { useRelationship } from '@/flavours/glitch/hooks/useRelationship'; import { selectUserListWithoutMe } from '@/flavours/glitch/selectors/user_lists'; import { useAppDispatch, useAppSelector } from '@/flavours/glitch/store'; import type { EmptyMessageProps } from './components/empty'; import { BaseEmptyMessage } from './components/empty'; import { AccountListHeader } from './components/header'; import { AccountList } from './components/list'; const titleText = defineMessage({ id: 'followers.title', defaultMessage: 'Following {name}', }); const Followers: FC = () => { const accountId = useAccountId(); const account = useAccount(accountId); const currentAccountId = useAppSelector( (state) => (state.meta.get('me') as string | null) ?? null, ); const followerList = useAppSelector((state) => selectUserListWithoutMe(state, 'followers', accountId), ); const dispatch = useAppDispatch(); useEffect(() => { if (!followerList && accountId) { dispatch(fetchFollowers(accountId)); } }, [accountId, dispatch, followerList]); const loadMore = useDebouncedCallback( () => { if (accountId) { dispatch(expandFollowers(accountId)); } }, 300, { leading: true }, ); const relationship = useRelationship(accountId); const followerId = relationship?.following ? currentAccountId : null; const followersExceptMeHidden = !!( account?.hide_collections && followerList?.items.length === 0 && followerId ); const footer = followersExceptMeHidden && (