2022-06-21 15:29:17 -07:00
|
|
|
|
import { OrderedSet as ImmutableOrderedSet } from 'immutable';
|
2022-05-28 09:02:04 -07:00
|
|
|
|
import React, { useEffect } from 'react';
|
|
|
|
|
import { FormattedMessage } from 'react-intl';
|
|
|
|
|
|
|
|
|
|
import { fetchPinnedAccounts } from 'soapbox/actions/accounts';
|
|
|
|
|
import { Widget } from 'soapbox/components/ui';
|
2022-11-15 08:13:54 -08:00
|
|
|
|
import AccountContainer from 'soapbox/containers/account-container';
|
2022-11-16 05:32:32 -08:00
|
|
|
|
import BundleContainer from 'soapbox/features/ui/containers/bundle-container';
|
2022-07-21 12:37:14 -07:00
|
|
|
|
import { WhoToFollowPanel } from 'soapbox/features/ui/util/async-components';
|
2022-05-28 09:02:04 -07:00
|
|
|
|
import { useAppDispatch, useAppSelector } from 'soapbox/hooks';
|
|
|
|
|
|
|
|
|
|
import type { Account } from 'soapbox/types/entities';
|
|
|
|
|
|
|
|
|
|
interface IPinnedAccountsPanel {
|
2023-02-15 13:26:27 -08:00
|
|
|
|
account: Account
|
|
|
|
|
limit: number
|
2022-05-28 09:02:04 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const PinnedAccountsPanel: React.FC<IPinnedAccountsPanel> = ({ account, limit }) => {
|
|
|
|
|
const dispatch = useAppDispatch();
|
2022-06-21 15:29:17 -07:00
|
|
|
|
const pinned = useAppSelector((state) => state.user_lists.pinned.get(account.id)?.items || ImmutableOrderedSet<string>()).slice(0, limit);
|
2022-05-28 09:02:04 -07:00
|
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
|
dispatch(fetchPinnedAccounts(account.id));
|
|
|
|
|
}, []);
|
|
|
|
|
|
|
|
|
|
if (pinned.isEmpty()) {
|
2022-07-21 12:37:14 -07:00
|
|
|
|
return (
|
|
|
|
|
<BundleContainer fetchComponent={WhoToFollowPanel}>
|
|
|
|
|
{Component => <Component limit={limit} />}
|
|
|
|
|
</BundleContainer>
|
|
|
|
|
);
|
2022-05-28 09:02:04 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<Widget
|
|
|
|
|
title={<FormattedMessage
|
|
|
|
|
id='pinned_accounts.title'
|
|
|
|
|
defaultMessage='{name}’s choices'
|
|
|
|
|
values={{
|
2022-07-22 04:29:00 -07:00
|
|
|
|
name: <span dangerouslySetInnerHTML={{ __html: account.display_name_html }} />,
|
2022-05-28 09:02:04 -07:00
|
|
|
|
}}
|
|
|
|
|
/>}
|
|
|
|
|
>
|
2022-06-21 15:29:17 -07:00
|
|
|
|
{pinned && pinned.map((suggestion) => (
|
2022-05-28 09:02:04 -07:00
|
|
|
|
<AccountContainer
|
|
|
|
|
key={suggestion}
|
|
|
|
|
id={suggestion}
|
|
|
|
|
withRelationship={false}
|
|
|
|
|
/>
|
|
|
|
|
))}
|
|
|
|
|
</Widget>
|
|
|
|
|
);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export default PinnedAccountsPanel;
|