Merge pull request #363 from lbryio/new-notifications

* move to new notification logic
* updates to handle the updated notification implementation in lbry-redux
This commit is contained in:
Akinwale Ariwodola 2018-11-24 14:45:58 +01:00 committed by GitHub
commit e11e1a0d5b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
25 changed files with 79 additions and 89 deletions

30
app/package-lock.json generated
View file

@ -3982,19 +3982,37 @@
}
},
"lbry-redux": {
"version": "github:lbryio/lbry-redux#30af6b5483fd74d66082316c621b761853d1419a",
"from": "github:lbryio/lbry-redux#pre-notification-update",
"version": "github:lbryio/lbry-redux#1ed2ea8b2de99bbcba652aa7b00478d02df4a290",
"from": "github:lbryio/lbry-redux",
"requires": {
"proxy-polyfill": "0.1.6",
"reselect": "^3.0.0"
"reselect": "^3.0.0",
"uuid": "^3.3.2"
},
"dependencies": {
"uuid": {
"version": "3.3.2",
"resolved": "https://registry.npmjs.org/uuid/-/uuid-3.3.2.tgz",
"integrity": "sha512-yXJmeNaw3DnnKAOKJE51sL/ZaYfWJRl1pK9dr19YFCu0ObS231AB1/LbqTKRAQ5kw8A90rA6fr4riOUpTZvQZA=="
}
}
},
"lbryinc": {
"version": "github:lbryio/lbryinc#ef0fd224a2ed2863a8b512207d46f149747d3e68",
"from": "github:lbryio/lbryinc#daemon-0.30.1-rc",
"version": "github:lbryio/lbryinc#82308ece97188747adbf6d71d55b6e7a6fa0bd95",
"from": "github:lbryio/lbryinc",
"requires": {
"lbry-redux": "github:lbryio/lbry-redux#30af6b5483fd74d66082316c621b761853d1419a",
"lbry-redux": "github:lbryio/lbry-redux#2375860d6269d0369418879c2531b1d48c4e47f2",
"reselect": "^3.0.0"
},
"dependencies": {
"lbry-redux": {
"version": "github:lbryio/lbry-redux#2375860d6269d0369418879c2531b1d48c4e47f2",
"from": "github:lbryio/lbry-redux#2375860d6269d0369418879c2531b1d48c4e47f2",
"requires": {
"proxy-polyfill": "0.1.6",
"reselect": "^3.0.0"
}
}
}
},
"lcid": {

View file

@ -7,8 +7,8 @@
},
"dependencies": {
"base-64": "^0.1.0",
"lbry-redux": "lbryio/lbry-redux#pre-notification-update",
"lbryinc": "lbryio/lbryinc#daemon-0.30.1-rc",
"lbry-redux": "lbryio/lbry-redux",
"lbryinc": "lbryio/lbryinc",
"moment": "^2.22.1",
"react": "16.2.0",
"react-native": "0.55.3",

View file

@ -33,7 +33,7 @@ import {
ToastAndroid
} from 'react-native';
import { doDeleteCompleteBlobs } from '../redux/actions/file';
import { SETTINGS, doHideNotification, doNotify, selectNotification } from 'lbry-redux';
import { SETTINGS, doDismissToast, doToast, selectToast } from 'lbry-redux';
import {
doUserEmailVerify,
doUserEmailVerifyFailure,
@ -240,28 +240,16 @@ class AppWithNavigationState extends React.Component {
componentWillUpdate(nextProps) {
const { dispatch } = this.props;
const {
notification,
toast,
emailToVerify,
emailVerifyPending,
emailVerifyErrorMessage,
user
} = nextProps;
if (notification) {
const { displayType, message } = notification;
if (toast) {
const { message } = toast;
let currentDisplayType;
if (displayType && displayType.length) {
for (let i = 0; i < displayType.length; i++) {
const type = displayType[i];
if (AppWithNavigationState.supportedDisplayTypes.indexOf(type) > -1) {
currentDisplayType = type;
break;
}
}
} else if (AppWithNavigationState.supportedDisplayTypes.indexOf(displayType) > -1) {
currentDisplayType = displayType;
}
if (!currentDisplayType && message) {
// default to toast if no display type set and there is a message specified
currentDisplayType = 'toast';
@ -271,7 +259,7 @@ class AppWithNavigationState extends React.Component {
ToastAndroid.show(message, ToastAndroid.LONG);
}
dispatch(doHideNotification());
dispatch(doDismissToast());
}
if (user &&
@ -287,7 +275,7 @@ class AppWithNavigationState extends React.Component {
AsyncStorage.removeItem(Constants.KEY_FIRST_RUN_EMAIL);
}
AsyncStorage.removeItem(Constants.KEY_SHOULD_VERIFY_EMAIL);
dispatch(doNotify({ message, displayType: ['toast'] }));
dispatch(doToast({ message }));
}
});
}
@ -340,12 +328,11 @@ class AppWithNavigationState extends React.Component {
} catch (error) {
const message = 'Invalid Verification Token';
dispatch(doUserEmailVerifyFailure(message));
dispatch(doNotify({ message, displayType: ['toast'] }));
dispatch(doToast({ message }));
}
} else {
dispatch(doNotify({
dispatch(doToast({
message: 'Invalid Verification URI',
displayType: ['toast'],
}));
}
} else {
@ -363,7 +350,7 @@ const mapStateToProps = state => ({
backgroundPlayEnabled: makeSelectClientSetting(SETTINGS.BACKGROUND_PLAY_ENABLED)(state),
keepDaemonRunning: makeSelectClientSetting(SETTINGS.KEEP_DAEMON_RUNNING)(state),
nav: state.nav,
notification: selectNotification(state),
toast: selectToast(state),
emailToVerify: selectEmailToVerify(state),
emailVerifyPending: selectEmailVerifyIsPending(state),
emailVerifyErrorMessage: selectEmailVerifyErrorMessage(state),

View file

@ -1,7 +1,7 @@
import { connect } from 'react-redux';
import { doNotify } from 'lbry-redux';
import { doToast } from 'lbry-redux';
import Address from './view';
export default connect(null, {
doNotify,
doToast,
})(Address);

View file

@ -6,21 +6,20 @@ import walletStyle from '../../styles/wallet';
type Props = {
address: string,
doNotify: ({ message: string, displayType: Array<string> }) => void,
doToast: ({ message: string }) => void,
};
export default class Address extends React.PureComponent<Props> {
render() {
const { address, doNotify, style } = this.props;
const { address, doToast, style } = this.props;
return (
<View style={[walletStyle.row, style]}>
<Text selectable={true} numberOfLines={1} style={walletStyle.address}>{address || ''}</Text>
<Button icon={'clipboard'} style={walletStyle.button} onPress={() => {
Clipboard.setString(address);
doNotify({
doToast({
message: 'Address copied',
displayType: ['toast'],
});
}} />
</View>

View file

@ -5,7 +5,7 @@ import {
selectEmailNewIsPending,
selectEmailToVerify
} from 'lbryinc';
import { doNotify } from 'lbry-redux';
import { doToast } from 'lbry-redux';
import EmailRewardSubcard from './view';
const select = state => ({
@ -16,7 +16,7 @@ const select = state => ({
const perform = dispatch => ({
addUserEmail: email => dispatch(doUserEmailNew(email)),
notify: data => dispatch(doNotify(data))
notify: data => dispatch(doToast(data))
});
export default connect(select, perform)(EmailRewardSubcard);
export default connect(select, perform)(EmailRewardSubcard);

View file

@ -38,12 +38,11 @@ class EmailRewardSubcard extends React.PureComponent {
if (this.state.verifyStarted && !emailNewPending) {
if (emailNewErrorMessage) {
notify({ message: String(emailNewErrorMessage), displayType: ['toast']});
notify({ message: String(emailNewErrorMessage), isError: true });
this.setState({ verifyStarted: false });
} else {
notify({
message: 'Please follow the instructions in the email sent to your address to continue.',
displayType: ['toast']
});
}
}
@ -65,7 +64,6 @@ class EmailRewardSubcard extends React.PureComponent {
if (!email || email.trim().length === 0 || email.indexOf('@') === -1) {
return notify({
message: 'Please provide a valid email address to continue.',
displayType: ['toast'],
});
}

View file

@ -1,9 +1,9 @@
import { connect } from 'react-redux';
import { doNotify } from 'lbry-redux';
import { doToast } from 'lbry-redux';
import Link from './view';
const perform = dispatch => ({
notify: (data) => dispatch(doNotify(data))
notify: (data) => dispatch(doToast(data))
});
export default connect(null, perform)(Link);

View file

@ -21,7 +21,7 @@ export default class Link extends React.PureComponent {
Linking.openURL(href)
.then(() => setTimeout(() => { this.setState({ tappedStyle: false }); }, 2000))
.catch(err => {
notify({ message: error, displayType: ['toast']})
notify({ message: error, isError: true })
this.setState({tappedStyle: false})
}
);

View file

@ -1,5 +1,5 @@
import { connect } from 'react-redux';
import { doNotify } from 'lbry-redux';
import { doToast } from 'lbry-redux';
import {
doUserPhoneNew,
doUserPhoneVerify,
@ -22,7 +22,7 @@ const select = state => ({
const perform = dispatch => ({
addUserPhone: (phone, country_code) => dispatch(doUserPhoneNew(phone, country_code)),
verifyPhone: (verificationCode) => dispatch(doUserPhoneVerify(verificationCode)),
notify: data => dispatch(doNotify(data)),
notify: data => dispatch(doToast(data)),
});
export default connect(select, perform)(PhoneNumberRewardSubcard);
export default connect(select, perform)(PhoneNumberRewardSubcard);

View file

@ -70,17 +70,17 @@ class PhoneNumberRewardSubcard extends React.PureComponent {
if (!phoneNewIsPending && (phoneNewIsPending !== prevProps.phoneNewIsPending)) {
if (phoneNewErrorMessage) {
notify({ message: String(phoneNewErrorMessage), displayType: ['toast'] });
notify({ message: String(phoneNewErrorMessage) });
} else {
this.setState({ newPhoneAdded: true });
}
}
if (!phoneVerifyIsPending && (phoneVerifyIsPending !== prevProps.phoneVerifyIsPending)) {
if (phoneVerifyErrorMessage) {
notify({ message: String(phoneVerifyErrorMessage), displayType: ['toast'] });
notify({ message: String(phoneVerifyErrorMessage) });
this.setState({ codeVerifyStarted: false });
} else {
notify({ message: 'Your phone number was successfully verified.', displayType: ['toast'] });
notify({ message: 'Your phone number was successfully verified.' });
this.setState({ codeVerifySuccessful: true });
if (onPhoneVerifySuccessful) {
onPhoneVerifySuccessful();
@ -107,7 +107,6 @@ class PhoneNumberRewardSubcard extends React.PureComponent {
if (!NativeModules.UtilityModule) {
return notify({
message: 'The required permission could not be obtained due to a missing module.',
displayType: ['toast']
});
}
@ -120,7 +119,6 @@ class PhoneNumberRewardSubcard extends React.PureComponent {
if (!this.phoneInput.isValidNumber()) {
return notify({
message: 'Please provide a valid telephone number.',
displayType: ['toast']
});
}

View file

@ -1,5 +1,5 @@
import { connect } from 'react-redux';
import { doNotify } from 'lbry-redux';
import { doToast } from 'lbry-redux';
import {
doClaimRewardType,
doClaimRewardClearError,
@ -23,7 +23,7 @@ const makeSelect = () => {
const perform = dispatch => ({
claimReward: reward => dispatch(doClaimRewardType(reward.reward_type, true)),
clearError: reward => dispatch(doClaimRewardClearError(reward)),
notify: data => dispatch(doNotify(data))
notify: data => dispatch(doToast(data))
});
export default connect(makeSelect, perform)(RewardCard);

View file

@ -30,10 +30,10 @@ class RewardCard extends React.PureComponent<Props> {
const { clearError, notify, reward } = this.props;
if (this.state.claimStarted && !isPending) {
if (errorMessage && errorMessage.trim().length > 0) {
notify({ message: errorMessage, displayType: ['toast'] });
notify({ message: errorMessage });
clearError(reward);
} else {
notify({ message: 'Reward successfully claimed!', displayType: ['toast'] });
notify({ message: 'Reward successfully claimed!' });
}
this.setState({ claimStarted: false });
}
@ -48,7 +48,7 @@ class RewardCard extends React.PureComponent<Props> {
} = this.props;
if (!canClaim) {
notify({ message: 'Unfortunately, you are not eligible to claim this reward at this time.', displayType: ['toast'] });
notify({ message: 'Unfortunately, you are not eligible to claim this reward at this time.' });
return;
}

View file

@ -1,5 +1,5 @@
import { connect } from 'react-redux';
import { doNotify } from 'lbry-redux';
import { doToast } from 'lbry-redux';
import { doRewardList, selectUnclaimedRewardValue, selectFetchingRewards, selectUser } from 'lbryinc';
import RewardSummary from './view';
@ -11,7 +11,7 @@ const select = state => ({
const perform = dispatch => ({
fetchRewards: () => dispatch(doRewardList()),
notify: data => dispatch(doNotify(data))
notify: data => dispatch(doToast(data))
});
export default connect(select, perform)(RewardSummary);

View file

@ -38,7 +38,6 @@ class RewardSummary extends React.Component {
this.setState({ dismissed: true });
this.props.notify({
message: 'You can always claim your rewards from the Rewards page.',
displayType: ['toast']
});
}

View file

@ -1,6 +1,6 @@
import { connect } from 'react-redux';
import {
doNotify,
doToast,
doSendDraftTransaction,
selectDraftTransaction,
selectDraftTransactionError,
@ -10,7 +10,7 @@ import WalletSend from './view';
const perform = dispatch => ({
sendToAddress: (address, amount) => dispatch(doSendDraftTransaction(address, amount)),
notify: (data) => dispatch(doNotify(data))
notify: (data) => dispatch(doToast(data))
});
const select = state => ({

View file

@ -38,7 +38,6 @@ class WalletSend extends React.PureComponent<Props> {
if (address && !regexAddress.test(address)) {
notify({
message: 'The recipient address is not a valid LBRY address.',
displayType: ['toast']
});
return;
}
@ -46,7 +45,6 @@ class WalletSend extends React.PureComponent<Props> {
if (amount > balance) {
notify({
message: 'Insufficient credits',
displayType: ['toast']
});
return;
}
@ -71,7 +69,6 @@ class WalletSend extends React.PureComponent<Props> {
const { notify } = this.props;
notify({
message: 'The recipient address is not a valid LBRY address.',
displayType: ['toast']
});
}
}

View file

@ -3,7 +3,7 @@ import {
doFetchFileInfo,
doFetchCostInfoForUri,
doResolveUri,
doNotify,
doToast,
makeSelectIsUriResolving,
makeSelectCostInfoForUri,
makeSelectFileInfoForUri,
@ -38,7 +38,7 @@ const perform = dispatch => ({
},
fetchFileInfo: uri => dispatch(doFetchFileInfo(uri)),
fetchCostInfo: uri => dispatch(doFetchCostInfoForUri(uri)),
notify: data => dispatch(doNotify(data)),
notify: data => dispatch(doToast(data)),
resolveUri: uri => dispatch(doResolveUri(uri)),
stopDownload: (uri, fileInfo) => dispatch(doStopDownloadingFile(uri, fileInfo)),
});

View file

@ -189,7 +189,6 @@ class FilePage extends React.PureComponent {
// after the file_set_status and file_delete operations, so let the user know
notify({
message: 'The download will stop momentarily. You do not need to wait to discover something else.',
displayType: ['toast']
});
}}
],

View file

@ -1,5 +1,5 @@
import { connect } from 'react-redux';
import { doNotify } from 'lbry-redux';
import { doToast } from 'lbry-redux';
import {
doGenerateAuthToken,
doUserEmailNew,
@ -22,7 +22,7 @@ const select = (state) => ({
const perform = dispatch => ({
addUserEmail: email => dispatch(doUserEmailNew(email)),
generateAuthToken: installationId => dispatch(doGenerateAuthToken(installationId)),
notify: data => dispatch(doNotify(data))
notify: data => dispatch(doToast(data))
});
export default connect(select, perform)(FirstRun);
export default connect(select, perform)(FirstRun);

View file

@ -61,7 +61,7 @@ class FirstRunScreen extends React.PureComponent {
if (this.state.emailSubmitted && !emailNewPending) {
this.setState({ emailSubmitted: false });
if (emailNewErrorMessage) {
notify ({ message: String(emailNewErrorMessage), displayType: ['toast']});
notify ({ message: String(emailNewErrorMessage), isError: true });
} else {
// Request successful. Navigate to discover.
this.closeFinalPage();
@ -115,7 +115,6 @@ class FirstRunScreen extends React.PureComponent {
if (email.indexOf('@') === -1) {
return notify({
message: 'Please provide a valid email address to continue.',
displayType: ['toast'],
});
}

View file

@ -8,7 +8,7 @@ import {
selectClaimedRewards,
selectUser,
} from 'lbryinc';
import { doNotify } from 'lbry-redux';
import { doToast } from 'lbry-redux';
import RewardsPage from './view';
const select = state => ({
@ -22,7 +22,7 @@ const select = state => ({
const perform = dispatch => ({
fetchRewards: () => dispatch(doRewardList()),
notify: data => dispatch(doNotify(data)),
notify: data => dispatch(doToast(data)),
});
export default connect(select, perform)(RewardsPage);
export default connect(select, perform)(RewardsPage);

View file

@ -1,5 +1,5 @@
import { connect } from 'react-redux';
import { doBalanceSubscribe, doBlackListedOutpointsSubscribe, doNotify } from 'lbry-redux';
import { doBalanceSubscribe, doBlackListedOutpointsSubscribe, doToast } from 'lbry-redux';
import {
doAuthenticate,
doFetchRewardedContent,
@ -23,7 +23,7 @@ const perform = dispatch => ({
blacklistedOutpointsSubscribe: () => dispatch(doBlackListedOutpointsSubscribe()),
deleteCompleteBlobs: () => dispatch(doDeleteCompleteBlobs()),
fetchRewardedContent: () => dispatch(doFetchRewardedContent()),
notify: data => dispatch(doNotify(data)),
notify: data => dispatch(doToast(data)),
setEmailToVerify: email => dispatch(doUserEmailToVerify(email)),
verifyUserEmail: (token, recaptcha) => dispatch(doUserEmailVerify(token, recaptcha)),
verifyUserEmailFailure: error => dispatch(doUserEmailVerifyFailure(error)),

View file

@ -102,12 +102,11 @@ class SplashScreen extends React.PureComponent {
} catch (error) {
const message = 'Invalid Verification Token';
verifyUserEmailFailure(message);
notify({ message, displayType: ['toast'] });
notify({ message });
}
} else {
notify({
message: 'Invalid Verification URI',
displayType: ['toast'],
});
}
} else {

View file

@ -1,7 +1,7 @@
import {
ACTIONS,
Lbry,
doNotify,
doToast,
formatCredits,
selectBalance,
makeSelectCostInfoForUri,
@ -190,9 +190,8 @@ export function doLoadVideo(uri, failureCallback) {
data: { uri },
});
dispatch(doNotify({
dispatch(doToast({
message: `File timeout for uri ${uri}`,
displayType: ['toast']
}));
if (failureCallback) {
@ -209,9 +208,8 @@ export function doLoadVideo(uri, failureCallback) {
data: { uri },
});
dispatch(doNotify({
dispatch(doToast({
message: `Failed to download ${uri}, please try again. If this problem persists, visit https://lbry.io/faq/support for support.`,
displayType: ['toast']
}));
if (failureCallback) {
@ -270,9 +268,8 @@ export function doPurchaseUri(uri, specificCostInfo, failureCallback) {
if (cost > balance) {
dispatch(doSetPlayingUri(null));
dispatch(doNotify({
dispatch(doToast({
message: 'Insufficient credits',
displayType: ['toast']
}));
if (failureCallback) {
failureCallback();