diff --git a/.eslintrc.json b/.eslintrc.json index 9ac4855..f900d96 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -10,6 +10,7 @@ "__": true }, "rules": { + "no-console": 2, "no-multi-spaces": 0, "new-cap": 0, "prefer-promise-reject-errors": 0, diff --git a/src/index.js b/src/index.js index 68a7c79..8f8e560 100644 --- a/src/index.js +++ b/src/index.js @@ -95,6 +95,7 @@ const compressor = createCompressor(); const authFilter = createFilter('auth', ['authToken']); const blockedFilter = createFilter('blocked', ['blockedChannels']); const contentFilter = createFilter('content', ['positions']); +const drawerFilter = createFilter('drawer', ['lastRouteInStack']); const saveClaimsFilter = createFilter('claims', ['claimsByUri']); const subscriptionsFilter = createFilter('subscriptions', ['enabledChannelNotifications', 'subscriptions', 'latest']); const settingsFilter = createFilter('settings', ['clientSettings']); @@ -102,12 +103,13 @@ const tagsFilter = createFilter('tags', ['followedTags']); const walletFilter = createFilter('wallet', ['receiveAddress']); const v4PersistOptions = { - whitelist: ['auth', 'blocked', 'claims', 'content', 'subscriptions', 'settings', 'tags', 'wallet'], + whitelist: ['auth', 'blocked', 'claims', 'drawer', 'content', 'subscriptions', 'settings', 'tags', 'wallet'], // Order is important. Needs to be compressed last or other transforms can't // read the data transforms: [ authFilter, blockedFilter, + drawerFilter, saveClaimsFilter, subscriptionsFilter, settingsFilter, diff --git a/src/page/splash/index.js b/src/page/splash/index.js index 225f925..0f632e5 100644 --- a/src/page/splash/index.js +++ b/src/page/splash/index.js @@ -14,11 +14,13 @@ import { selectEmailToVerify, } from 'lbryinc'; import { doSetClientSetting } from 'redux/actions/settings'; +import { selectLastRouteInStack } from 'redux/selectors/drawer'; import SplashScreen from './view'; const select = state => ({ user: selectUser(state), emailToVerify: selectEmailToVerify(state), + lastRouteInStack: selectLastRouteInStack(state), }); const perform = dispatch => ({ diff --git a/src/page/splash/view.js b/src/page/splash/view.js index fc9b9b3..7819f88 100644 --- a/src/page/splash/view.js +++ b/src/page/splash/view.js @@ -1,5 +1,5 @@ import React from 'react'; -import { Lbry, doPreferenceGet } from 'lbry-redux'; +import { Lbry, doPreferenceGet, isURIValid } from 'lbry-redux'; import { Lbryio } from 'lbryinc'; import { ActivityIndicator, DeviceEventEmitter, Linking, NativeModules, Platform, Text, View } from 'react-native'; import { NavigationActions, StackActions } from 'react-navigation'; @@ -11,7 +11,7 @@ import Button from 'component/button'; import ProgressBar from 'component/progressBar'; import PropTypes from 'prop-types'; import Colors from 'styles/colors'; -import Constants from 'constants'; // eslint-disable-line node/no-deprecated-api +import Constants, { DrawerRoutes } from 'constants'; // eslint-disable-line node/no-deprecated-api import splashStyle from 'styles/splash'; import RNFS from 'react-native-fs'; @@ -43,7 +43,7 @@ class SplashScreen extends React.PureComponent { } navigateToMain = () => { - const { navigation, notify, verifyUserEmail, verifyUserEmailFailure } = this.props; + const { lastRouteInStack, navigation, notify, verifyUserEmail, verifyUserEmailFailure } = this.props; const resetAction = StackActions.reset({ index: 0, actions: [NavigationActions.navigate({ routeName: 'Main' })], @@ -55,29 +55,14 @@ class SplashScreen extends React.PureComponent { ? navigation.state.params.launchUrl : this.state.launchUrl; if (launchUrl) { - if (launchUrl.startsWith('lbry://?verify=')) { - let verification = {}; - try { - verification = JSON.parse(atob(launchUrl.substring(15))); - } catch (error) { - console.log(error); - } - if (verification.token && verification.recaptcha) { - AsyncStorage.setItem(Constants.KEY_SHOULD_VERIFY_EMAIL, 'true'); - try { - verifyUserEmail(verification.token, verification.recaptcha); - } catch (error) { - const message = __('Invalid Verification Token'); - verifyUserEmailFailure(message); - notify({ message }); - } - } else { - notify({ - message: __('Invalid Verification URI'), - }); - } + navigateToUri(navigation, transformUrl(launchUrl)); + } else if (lastRouteInStack) { + // no launch url, check if there's a last route in stack to navigate to. + const { route, params } = lastRouteInStack; + if (!DrawerRoutes.includes(route) && isURIValid(route)) { + navigateToUri(navigation, route); } else { - navigateToUri(navigation, transformUrl(launchUrl)); + navigation.navigate({ routeName: route, params }); } } }; diff --git a/src/redux/reducers/drawer.js b/src/redux/reducers/drawer.js index 70b49d0..84173b0 100644 --- a/src/redux/reducers/drawer.js +++ b/src/redux/reducers/drawer.js @@ -3,6 +3,7 @@ import Constants from 'constants'; // eslint-disable-line node/no-deprecated-api const reducers = {}; const defaultState = { stack: [{ route: Constants.DRAWER_ROUTE_DISCOVER, params: {} }], // Discover is always the first drawer route + lastRouteInStack: {}, playerVisible: false, playerVisibleByUri: {}, currentRoute: null, @@ -42,23 +43,30 @@ reducers[Constants.ACTION_PUSH_DRAWER_STACK] = (state, action) => { canPushStack = false; } + let lastRouteInStack; if (canPushStack) { newStack.push({ route: routeName, params }); + + // save the route + lastRouteInStack = { route: routeName, params }; } return { ...state, stack: newStack, + lastRouteInStack, }; }; reducers[Constants.ACTION_POP_DRAWER_STACK] = (state, action) => { // We don't want to pop the Discover route, since it's always expected to be the first const newStack = state.stack.length === 1 ? state.stack.slice() : state.stack.slice(0, state.stack.length - 1); + const lastRouteInStack = newStack && newStack.length > 0 ? newStack[newStack.length - 1] : null; return { ...state, stack: newStack, + lastRouteInStack, }; }; diff --git a/src/redux/selectors/drawer.js b/src/redux/selectors/drawer.js index f58bfba..5cb7dc1 100644 --- a/src/redux/selectors/drawer.js +++ b/src/redux/selectors/drawer.js @@ -34,6 +34,11 @@ export const selectLastDrawerRoute = createSelector( }, ); +export const selectLastRouteInStack = createSelector( + selectState, + state => state.lastRouteInStack, +); + export const selectCurrentRoute = createSelector( selectState, state => state.currentRoute,