ActionButton: remove most calls to .get, fix relationship loading bug

This commit is contained in:
Alex Gleason 2022-05-14 11:44:31 -05:00
parent 3d898957e3
commit 9e09823f80
No known key found for this signature in database
GPG Key ID: 7211D1F99744FBB7
1 changed files with 14 additions and 14 deletions

View File

@ -30,13 +30,13 @@ const messages = defineMessages({
unmute: { id: 'account.unmute', defaultMessage: 'Unmute @{name}' }, unmute: { id: 'account.unmute', defaultMessage: 'Unmute @{name}' },
}); });
interface iActionButton { interface IActionButton {
account: AccountEntity account: AccountEntity
actionType?: 'muting' | 'blocking' actionType?: 'muting' | 'blocking'
small?: boolean small?: boolean
} }
const ActionButton = ({ account, actionType, small }: iActionButton) => { const ActionButton: React.FC<IActionButton> = ({ account, actionType, small }) => {
const dispatch = useDispatch(); const dispatch = useDispatch();
const features = useFeatures(); const features = useFeatures();
const intl = useIntl(); const intl = useIntl();
@ -45,40 +45,40 @@ const ActionButton = ({ account, actionType, small }: iActionButton) => {
const handleFollow = () => { const handleFollow = () => {
if (account.getIn(['relationship', 'following']) || account.getIn(['relationship', 'requested'])) { if (account.getIn(['relationship', 'following']) || account.getIn(['relationship', 'requested'])) {
dispatch(unfollowAccount(account.get('id'))); dispatch(unfollowAccount(account.id));
} else { } else {
dispatch(followAccount(account.get('id'))); dispatch(followAccount(account.id));
} }
}; };
const handleBlock = () => { const handleBlock = () => {
if (account.getIn(['relationship', 'blocking'])) { if (account.getIn(['relationship', 'blocking'])) {
dispatch(unblockAccount(account.get('id'))); dispatch(unblockAccount(account.id));
} else { } else {
dispatch(blockAccount(account.get('id'))); dispatch(blockAccount(account.id));
} }
}; };
const handleMute = () => { const handleMute = () => {
if (account.getIn(['relationship', 'muting'])) { if (account.getIn(['relationship', 'muting'])) {
dispatch(unmuteAccount(account.get('id'))); dispatch(unmuteAccount(account.id));
} else { } else {
dispatch(muteAccount(account.get('id'))); dispatch(muteAccount(account.id));
} }
}; };
const handleRemoteFollow = () => { const handleRemoteFollow = () => {
dispatch(openModal('UNAUTHORIZED', { dispatch(openModal('UNAUTHORIZED', {
action: 'FOLLOW', action: 'FOLLOW',
account: account.get('id'), account: account.id,
ap_id: account.get('url'), ap_id: account.url,
})); }));
}; };
const mutingAction = () => { const mutingAction = () => {
const isMuted = account.getIn(['relationship', 'muting']); const isMuted = account.getIn(['relationship', 'muting']);
const messageKey = isMuted ? messages.unmute : messages.mute; const messageKey = isMuted ? messages.unmute : messages.mute;
const text = intl.formatMessage(messageKey, { name: account.get('username') }); const text = intl.formatMessage(messageKey, { name: account.username });
return ( return (
<Button <Button
@ -93,7 +93,7 @@ const ActionButton = ({ account, actionType, small }: iActionButton) => {
const blockingAction = () => { const blockingAction = () => {
const isBlocked = account.getIn(['relationship', 'blocking']); const isBlocked = account.getIn(['relationship', 'blocking']);
const messageKey = isBlocked ? messages.unblock : messages.block; const messageKey = isBlocked ? messages.unblock : messages.block;
const text = intl.formatMessage(messageKey, { name: account.get('username') }); const text = intl.formatMessage(messageKey, { name: account.username });
return ( return (
<Button <Button
@ -157,7 +157,7 @@ const ActionButton = ({ account, actionType, small }: iActionButton) => {
} }
} }
if (!account.get('relationship')) { if (account.relationship.isEmpty()) {
// Wait until the relationship is loaded // Wait until the relationship is loaded
return empty; return empty;
} else if (account.getIn(['relationship', 'requested'])) { } else if (account.getIn(['relationship', 'requested'])) {
@ -193,7 +193,7 @@ const ActionButton = ({ account, actionType, small }: iActionButton) => {
<Button <Button
theme='danger' theme='danger'
size='sm' size='sm'
text={intl.formatMessage(messages.unblock, { name: account.get('username') })} text={intl.formatMessage(messages.unblock, { name: account.username })}
onClick={handleBlock} onClick={handleBlock}
/> />
); );