bigbuffet-rw/app/soapbox/features/ui/components/pinned_accounts_panel.tsx
marcin mikołajczak 1e74c6d3d7 TypeScript, FC, styles and fixes
Signed-off-by: marcin mikołajczak <git@mkljczk.pl>
2022-05-28 18:03:19 +02:00

50 lines
1.4 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import { List as ImmutableList } from 'immutable';
import React, { useEffect } from 'react';
import { FormattedMessage } from 'react-intl';
import { fetchPinnedAccounts } from 'soapbox/actions/accounts';
import { Widget } from 'soapbox/components/ui';
import AccountContainer from 'soapbox/containers/account_container';
import { useAppDispatch, useAppSelector } from 'soapbox/hooks';
import type { Account } from 'soapbox/types/entities';
interface IPinnedAccountsPanel {
account: Account,
limit: number,
}
const PinnedAccountsPanel: React.FC<IPinnedAccountsPanel> = ({ account, limit }) => {
const dispatch = useAppDispatch();
const pinned = useAppSelector((state) => state.user_lists.getIn(['pinned', account.id, 'items'], ImmutableList())).slice(0, limit);
useEffect(() => {
dispatch(fetchPinnedAccounts(account.id));
}, []);
if (pinned.isEmpty()) {
return null;
}
return (
<Widget
title={<FormattedMessage
id='pinned_accounts.title'
defaultMessage='{name}s choices'
values={{
name: <span className='display-name__html' dangerouslySetInnerHTML={{ __html: account.display_name_html }} />,
}}
/>}
>
{pinned && pinned.map((suggestion: string) => (
<AccountContainer
key={suggestion}
id={suggestion}
withRelationship={false}
/>
))}
</Widget>
);
};
export default PinnedAccountsPanel;