Add 'dispatchToast' wrapper

Just to shorten code, and easier to know what the parameters are if it's a function call (instead of an object).
This commit is contained in:
infinite-persistence 2022-05-06 13:31:21 +08:00
parent 6cc85cd39d
commit 2698cc7001
No known key found for this signature in database
GPG key ID: B9C3252EDC3D0AA0
2 changed files with 14 additions and 15 deletions

View file

@ -6,7 +6,7 @@ import { SORT_BY, BLOCK_LEVEL } from 'constants/comment';
import Lbry from 'lbry';
import { resolveApiMessage } from 'util/api-message';
import { parseURI, buildURI, isURIEqual } from 'util/lbryURI';
import { devToast, doFailedSignatureToast } from 'util/toast-wrappers';
import { devToast, dispatchToast, doFailedSignatureToast } from 'util/toast-wrappers';
import { selectClaimForUri, selectClaimsByUri, selectMyChannelClaims } from 'redux/selectors/claims';
import { doResolveUris, doClaimSearch, doResolveClaimIds } from 'redux/actions/claims';
import { doToast, doSeeNotifications } from 'redux/actions/notifications';
@ -704,7 +704,7 @@ export function doCommentCreate(uri: string, livestream: boolean, params: Commen
})
.catch((error) => {
dispatch({ type: ACTIONS.COMMENT_CREATE_FAILED, data: error });
dispatch(doToast({ message: resolveApiMessage(error.message), isError: true }));
dispatchToast(dispatch, resolveApiMessage(error.message));
return Promise.reject(error);
});
};
@ -754,12 +754,7 @@ export function doCommentPin(commentId: string, claimId: string, remove: boolean
type: ACTIONS.COMMENT_PIN_FAILED,
data: error,
});
dispatch(
doToast({
message: 'Unable to pin this comment, please try again later.',
isError: true,
})
);
dispatchToast(dispatch, __('Unable to pin this comment, please try again later.'));
});
};
}

View file

@ -1,14 +1,18 @@
// @flow
import { doToast } from 'redux/actions/notifications';
export function dispatchToast(
dispatch: Dispatch,
message: string,
subMessage: string = '',
duration: 'default' | 'long' = 'default',
isError: boolean = true
) {
return dispatch(doToast({ message, subMessage: subMessage || undefined, duration: duration, isError }));
}
export function doFailedSignatureToast(dispatch: Dispatch, channelName: string) {
dispatch(
doToast({
message: __('Unable to verify signature.'),
subMessage: channelName,
isError: true,
})
);
return dispatchToast(dispatch, __('Unable to verify signature.'), channelName);
}
export function devToast(dispatch: Dispatch, msg: string) {