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:
parent
6cc85cd39d
commit
2698cc7001
2 changed files with 14 additions and 15 deletions
|
@ -6,7 +6,7 @@ import { SORT_BY, BLOCK_LEVEL } from 'constants/comment';
|
||||||
import Lbry from 'lbry';
|
import Lbry from 'lbry';
|
||||||
import { resolveApiMessage } from 'util/api-message';
|
import { resolveApiMessage } from 'util/api-message';
|
||||||
import { parseURI, buildURI, isURIEqual } from 'util/lbryURI';
|
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 { selectClaimForUri, selectClaimsByUri, selectMyChannelClaims } from 'redux/selectors/claims';
|
||||||
import { doResolveUris, doClaimSearch, doResolveClaimIds } from 'redux/actions/claims';
|
import { doResolveUris, doClaimSearch, doResolveClaimIds } from 'redux/actions/claims';
|
||||||
import { doToast, doSeeNotifications } from 'redux/actions/notifications';
|
import { doToast, doSeeNotifications } from 'redux/actions/notifications';
|
||||||
|
@ -704,7 +704,7 @@ export function doCommentCreate(uri: string, livestream: boolean, params: Commen
|
||||||
})
|
})
|
||||||
.catch((error) => {
|
.catch((error) => {
|
||||||
dispatch({ type: ACTIONS.COMMENT_CREATE_FAILED, data: 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);
|
return Promise.reject(error);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
@ -754,12 +754,7 @@ export function doCommentPin(commentId: string, claimId: string, remove: boolean
|
||||||
type: ACTIONS.COMMENT_PIN_FAILED,
|
type: ACTIONS.COMMENT_PIN_FAILED,
|
||||||
data: error,
|
data: error,
|
||||||
});
|
});
|
||||||
dispatch(
|
dispatchToast(dispatch, __('Unable to pin this comment, please try again later.'));
|
||||||
doToast({
|
|
||||||
message: 'Unable to pin this comment, please try again later.',
|
|
||||||
isError: true,
|
|
||||||
})
|
|
||||||
);
|
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,14 +1,18 @@
|
||||||
// @flow
|
// @flow
|
||||||
import { doToast } from 'redux/actions/notifications';
|
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) {
|
export function doFailedSignatureToast(dispatch: Dispatch, channelName: string) {
|
||||||
dispatch(
|
return dispatchToast(dispatch, __('Unable to verify signature.'), channelName);
|
||||||
doToast({
|
|
||||||
message: __('Unable to verify signature.'),
|
|
||||||
subMessage: channelName,
|
|
||||||
isError: true,
|
|
||||||
})
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export function devToast(dispatch: Dispatch, msg: string) {
|
export function devToast(dispatch: Dispatch, msg: string) {
|
||||||
|
|
Loading…
Reference in a new issue