Reducers: TypeScript

Signed-off-by: marcin mikołajczak <git@mkljczk.pl>
This commit is contained in:
marcin mikołajczak
2022-06-04 09:22:36 +02:00
parent 666c2dd0ce
commit 65dff4e6a1
50 changed files with 473 additions and 370 deletions

View File

@@ -52,7 +52,7 @@ const ActionButton: React.FC<IActionButton> = ({ account, actionType, small }) =
const me = useAppSelector((state) => state.me);
const handleFollow = () => {
if (account.getIn(['relationship', 'following']) || account.getIn(['relationship', 'requested'])) {
if (account.relationship?.following || account.relationship?.requested) {
dispatch(unfollowAccount(account.id));
} else {
dispatch(followAccount(account.id));
@@ -60,7 +60,7 @@ const ActionButton: React.FC<IActionButton> = ({ account, actionType, small }) =
};
const handleBlock = () => {
if (account.getIn(['relationship', 'blocking'])) {
if (account.relationship?.blocking) {
dispatch(unblockAccount(account.id));
} else {
dispatch(blockAccount(account.id));
@@ -68,7 +68,7 @@ const ActionButton: React.FC<IActionButton> = ({ account, actionType, small }) =
};
const handleMute = () => {
if (account.getIn(['relationship', 'muting'])) {
if (account.relationship?.muting) {
dispatch(unmuteAccount(account.id));
} else {
dispatch(muteAccount(account.id));
@@ -85,7 +85,7 @@ const ActionButton: React.FC<IActionButton> = ({ account, actionType, small }) =
/** Handles actionType='muting' */
const mutingAction = () => {
const isMuted = account.getIn(['relationship', 'muting']);
const isMuted = account.relationship?.muting;
const messageKey = isMuted ? messages.unmute : messages.mute;
const text = intl.formatMessage(messageKey, { name: account.username });
@@ -101,7 +101,7 @@ const ActionButton: React.FC<IActionButton> = ({ account, actionType, small }) =
/** Handles actionType='blocking' */
const blockingAction = () => {
const isBlocked = account.getIn(['relationship', 'blocking']);
const isBlocked = account.relationship?.blocking;
const messageKey = isBlocked ? messages.unblock : messages.block;
const text = intl.formatMessage(messageKey, { name: account.username });
@@ -154,8 +154,8 @@ const ActionButton: React.FC<IActionButton> = ({ account, actionType, small }) =
}
if (me !== account.id) {
const isFollowing = account.getIn(['relationship', 'following']);
const blockedBy = account.getIn(['relationship', 'blocked_by']) as boolean;
const isFollowing = account.relationship?.following;
const blockedBy = account.relationship?.blocked_by as boolean;
if (actionType) {
if (actionType === 'muting') {
@@ -165,10 +165,10 @@ const ActionButton: React.FC<IActionButton> = ({ account, actionType, small }) =
}
}
if (account.relationship.isEmpty()) {
if (!account.relationship) {
// Wait until the relationship is loaded
return null;
} else if (account.getIn(['relationship', 'requested'])) {
} else if (account.relationship?.requested) {
// Awaiting acceptance
return (
<Button
@@ -178,7 +178,7 @@ const ActionButton: React.FC<IActionButton> = ({ account, actionType, small }) =
onClick={handleFollow}
/>
);
} else if (!account.getIn(['relationship', 'blocking']) && !account.getIn(['relationship', 'muting'])) {
} else if (!account.relationship?.blocking && !account.relationship?.muting) {
// Follow & Unfollow
return (
<Button
@@ -195,7 +195,7 @@ const ActionButton: React.FC<IActionButton> = ({ account, actionType, small }) =
)}
</Button>
);
} else if (account.getIn(['relationship', 'blocking'])) {
} else if (account.relationship?.blocking) {
// Unblock
return (
<Button

View File

@@ -47,9 +47,9 @@ const SelectedStatus = ({ statusId }: { statusId: string }) => {
return (
<Stack space={2} className='p-4 rounded-lg bg-gray-100 dark:bg-slate-700'>
<AccountContainer
id={status.get('account') as any}
id={status.account as any}
showProfileHoverCard={false}
timestamp={status.get('created_at')}
timestamp={status.created_at}
hideActions
/>
@@ -59,10 +59,10 @@ const SelectedStatus = ({ statusId }: { statusId: string }) => {
collapsable
/>
{status.get('media_attachments').size > 0 && (
{status.media_attachments.size > 0 && (
<AttachmentThumbs
media={status.get('media_attachments')}
sensitive={status.get('sensitive')}
media={status.media_attachments}
sensitive={status.sensitive}
/>
)}
</Stack>

View File

@@ -29,14 +29,14 @@ const mapStateToProps = state => {
const mapDispatchToProps = (dispatch) => ({
onSubscriptionToggle(account) {
if (account.getIn(['relationship', 'subscribing'])) {
if (account.relationship?.subscribing) {
dispatch(unsubscribeAccount(account.get('id')));
} else {
dispatch(subscribeAccount(account.get('id')));
}
},
onNotifyToggle(account) {
if (account.getIn(['relationship', 'notifying'])) {
if (account.relationship?.notifying) {
dispatch(followAccount(account.get('id'), { notify: false }));
} else {
dispatch(followAccount(account.get('id'), { notify: true }));
@@ -60,9 +60,9 @@ class SubscriptionButton extends ImmutablePureComponent {
render() {
const { account, intl, features } = this.props;
const subscribing = features.accountNotifies ? account.getIn(['relationship', 'notifying']) : account.getIn(['relationship', 'subscribing']);
const following = account.getIn(['relationship', 'following']);
const requested = account.getIn(['relationship', 'requested']);
const subscribing = features.accountNotifies ? account.relationship?.notifying : account.relationship?.subscribing;
const following = account.relationship?.following;
const requested = account.relationship?.requested;
if (requested || following) {
return (