pleroma/app/soapbox/features/followers/index.tsx

70 lines
1.7 KiB
TypeScript
Raw Normal View History

2023-06-25 14:21:27 -07:00
import React from 'react';
2022-09-10 09:56:02 -07:00
import { defineMessages, FormattedMessage, useIntl } from 'react-intl';
import { useAccountLookup, useFollowers } from 'soapbox/api/hooks';
2023-06-25 14:21:27 -07:00
import Account from 'soapbox/components/account';
2022-11-15 08:00:49 -08:00
import MissingIndicator from 'soapbox/components/missing-indicator';
import ScrollableList from 'soapbox/components/scrollable-list';
2022-11-30 09:19:16 -08:00
import { Column, Spinner } from 'soapbox/components/ui';
2022-09-10 09:56:02 -07:00
const messages = defineMessages({
heading: { id: 'column.followers', defaultMessage: 'Followers' },
});
interface IFollowers {
params?: {
username?: string
2022-09-10 09:56:02 -07:00
}
}
/** Displays a list of accounts who follow the given account. */
2023-06-25 14:21:27 -07:00
const Followers: React.FC<IFollowers> = ({ params }) => {
2022-09-10 09:56:02 -07:00
const intl = useIntl();
2023-06-25 14:21:27 -07:00
const { account, isUnavailable } = useAccountLookup(params?.username);
2022-09-10 09:56:02 -07:00
2023-06-25 14:21:27 -07:00
const {
accounts,
hasNextPage,
fetchNextPage,
isLoading,
} = useFollowers(account?.id);
2022-09-10 09:56:02 -07:00
2023-06-25 14:21:27 -07:00
if (isLoading) {
2022-09-10 09:56:02 -07:00
return (
<Spinner />
);
}
if (!account) {
return (
<MissingIndicator />
);
}
if (isUnavailable) {
2022-09-10 09:56:02 -07:00
return (
<div className='empty-column-indicator'>
<FormattedMessage id='empty_column.account_unavailable' defaultMessage='Profile unavailable' />
</div>
);
}
return (
<Column label={intl.formatMessage(messages.heading)} transparent>
<ScrollableList
scrollKey='followers'
2023-06-25 14:21:27 -07:00
hasMore={hasNextPage}
onLoadMore={fetchNextPage}
2022-09-10 09:56:02 -07:00
emptyMessage={<FormattedMessage id='account.followers.empty' defaultMessage='No one follows this user yet.' />}
itemClassName='pb-4'
>
2023-06-25 14:21:27 -07:00
{accounts.map((account) =>
<Account key={account.id} account={account} />,
2022-09-10 09:56:02 -07:00
)}
</ScrollableList>
</Column>
);
};
export default Followers;