Support 'actionType' prop in ActionButton

api-accept
Justin 2022-05-03 13:22:06 -04:00
rodzic 8dc7cc8794
commit c758c5c2f9
4 zmienionych plików z 52 dodań i 18 usunięć

Wyświetl plik

@ -46,6 +46,8 @@ interface IAccount {
actionAlignment?: 'center' | 'top', actionAlignment?: 'center' | 'top',
actionIcon?: string, actionIcon?: string,
actionTitle?: string, actionTitle?: string,
/** Override other actions for specificity like mute/unmute. */
actionType?: 'muting' | 'blocking',
avatarSize?: number, avatarSize?: number,
hidden?: boolean, hidden?: boolean,
hideActions?: boolean, hideActions?: boolean,
@ -60,6 +62,7 @@ interface IAccount {
const Account = ({ const Account = ({
account, account,
actionType,
action, action,
actionIcon, actionIcon,
actionTitle, actionTitle,
@ -111,7 +114,7 @@ const Account = ({
} }
if (account.id !== me) { if (account.id !== me) {
return <ActionButton account={account} />; return <ActionButton account={account} actionType={actionType} />;
} }
return null; return null;

Wyświetl plik

@ -48,7 +48,7 @@ const Blocks: React.FC = () => {
itemClassName='pb-4' itemClassName='pb-4'
> >
{accountIds.map((id: string) => {accountIds.map((id: string) =>
<AccountContainer key={id} id={id} />, <AccountContainer key={id} id={id} actionType='blocking' />,
)} )}
</ScrollableList> </ScrollableList>
</Column> </Column>

Wyświetl plik

@ -48,7 +48,7 @@ const Mutes: React.FC = () => {
itemClassName='pb-4' itemClassName='pb-4'
> >
{accountIds.map((id: string) => {accountIds.map((id: string) =>
<AccountContainer key={id} id={id} />, <AccountContainer key={id} id={id} actionType='muting' />,
)} )}
</ScrollableList> </ScrollableList>
</Column> </Column>

Wyświetl plik

@ -17,23 +17,26 @@ import { useAppSelector, useFeatures } from 'soapbox/hooks';
import type { Account as AccountEntity } from 'soapbox/types/entities'; import type { Account as AccountEntity } from 'soapbox/types/entities';
const messages = defineMessages({ const messages = defineMessages({
unfollow: { id: 'account.unfollow', defaultMessage: 'Unfollow' }, block: { id: 'account.block', defaultMessage: 'Block @{name}' },
blocked: { id: 'account.blocked', defaultMessage: 'Blocked' },
edit_profile: { id: 'account.edit_profile', defaultMessage: 'Edit profile' },
follow: { id: 'account.follow', defaultMessage: 'Follow' }, follow: { id: 'account.follow', defaultMessage: 'Follow' },
mute: { id: 'account.mute', defaultMessage: 'Mute @{name}' },
remote_follow: { id: 'account.remote_follow', defaultMessage: 'Remote follow' }, remote_follow: { id: 'account.remote_follow', defaultMessage: 'Remote follow' },
requested: { id: 'account.requested', defaultMessage: 'Awaiting approval. Click to cancel follow request' }, requested: { id: 'account.requested', defaultMessage: 'Awaiting approval. Click to cancel follow request' },
requested_small: { id: 'account.requested_small', defaultMessage: 'Awaiting approval' }, requested_small: { id: 'account.requested_small', defaultMessage: 'Awaiting approval' },
unblock: { id: 'account.unblock', defaultMessage: 'Unblock @{name}' }, unblock: { id: 'account.unblock', defaultMessage: 'Unblock @{name}' },
unfollow: { id: 'account.unfollow', defaultMessage: 'Unfollow' },
unmute: { id: 'account.unmute', defaultMessage: 'Unmute @{name}' }, unmute: { id: 'account.unmute', defaultMessage: 'Unmute @{name}' },
edit_profile: { id: 'account.edit_profile', defaultMessage: 'Edit profile' },
blocked: { id: 'account.blocked', defaultMessage: 'Blocked' },
}); });
interface IAccount { interface iActionButton {
account: AccountEntity account: AccountEntity
actionType?: 'muting' | 'blocking'
small?: boolean small?: boolean
} }
const ActionButton = ({ account, small }: IAccount) => { const ActionButton = ({ account, actionType, small }: iActionButton) => {
const dispatch = useDispatch(); const dispatch = useDispatch();
const features = useFeatures(); const features = useFeatures();
const intl = useIntl(); const intl = useIntl();
@ -72,6 +75,36 @@ const ActionButton = ({ account, small }: IAccount) => {
})); }));
}; };
const mutingAction = () => {
const isMuted = account.getIn(['relationship', 'muting']);
const messageKey = isMuted ? messages.unmute : messages.mute;
const text = intl.formatMessage(messageKey, { name: account.get('username') });
return (
<Button
theme={isMuted ? 'danger' : 'secondary'}
size='sm'
text={text}
onClick={handleMute}
/>
);
};
const blockingAction = () => {
const isBlocked = account.getIn(['relationship', 'blocking']);
const messageKey = isBlocked ? messages.unblock : messages.block;
const text = intl.formatMessage(messageKey, { name: account.get('username') });
return (
<Button
theme={isBlocked ? 'danger' : 'secondary'}
size='sm'
text={text}
onClick={handleBlock}
/>
);
};
const empty = <></>; const empty = <></>;
if (!me) { if (!me) {
@ -99,6 +132,14 @@ const ActionButton = ({ account, small }: IAccount) => {
const isFollowing = account.getIn(['relationship', 'following']); const isFollowing = account.getIn(['relationship', 'following']);
const blockedBy = account.getIn(['relationship', 'blocked_by']) as boolean; const blockedBy = account.getIn(['relationship', 'blocked_by']) as boolean;
if (actionType) {
if (actionType === 'muting') {
return mutingAction();
} else if (actionType === 'blocking') {
return blockingAction();
}
}
if (!account.get('relationship')) { if (!account.get('relationship')) {
// Wait until the relationship is loaded // Wait until the relationship is loaded
return empty; return empty;
@ -139,16 +180,6 @@ const ActionButton = ({ account, small }: IAccount) => {
onClick={handleBlock} onClick={handleBlock}
/> />
); );
} else if (account.getIn(['relationship', 'muting'])) {
// Unmute
return (
<Button
theme='danger'
size='sm'
text={intl.formatMessage(messages.unmute, { name: account.get('username') })}
onClick={handleMute}
/>
);
} }
} else { } else {
// Edit profile // Edit profile