From f3316160fbd97413162d2b1bda016ef780196a8f Mon Sep 17 00:00:00 2001 From: Akinwale Ariwodola Date: Sat, 1 Dec 2018 23:56:33 +0100 Subject: [PATCH] add support for special links (#369) --- app/src/constants.js | 5 +++++ app/src/utils/helper.js | 26 ++++++++++++++++++++++++++ 2 files changed, 31 insertions(+) diff --git a/app/src/constants.js b/app/src/constants.js index 003ec2d..4764520 100644 --- a/app/src/constants.js +++ b/app/src/constants.js @@ -6,6 +6,11 @@ const Constants = { ACTION_DELETE_COMPLETED_BLOBS: "DELETE_COMPLETED_BLOBS", ACTION_FIRST_RUN_PAGE_CHANGED: "FIRST_RUN_PAGE_CHANGED", + + PAGE_REWARDS: 'rewards', + PAGE_SETTINGS: 'settings', + PAGE_TRENDING: 'trending', + PAGE_WALLET: 'wallet' }; export default Constants; diff --git a/app/src/utils/helper.js b/app/src/utils/helper.js index 2807e1a..126b9c8 100644 --- a/app/src/utils/helper.js +++ b/app/src/utils/helper.js @@ -1,6 +1,27 @@ import { NavigationActions, StackActions } from 'react-navigation'; +import Constants from '../constants'; + +function getRouteForSpecialUri(uri) { + let targetRoute; + const page = uri.substring(8).trim(); // 'lbry://?'.length == 8 + + switch (page) { + case Constants.PAGE_REWARDS: targetRoute = 'Rewards'; break; + case Constants.PAGE_SETTINGS: targetRoute = 'Settings'; break; + case Constants.PAGE_TRENDING: targetRoute = 'TrendingStack'; break; + case Constants.PAGE_WALLET: targetRoute = 'WalletStack'; break; + default: targetRoute = 'DiscoverStack'; break; + } + + return targetRoute; +} export function dispatchNavigateToUri(dispatch, nav, uri) { + if (uri.startsWith('lbry://?')) { + dispatch(NavigationActions.navigate({ routeName: getRouteForSpecialUri(uri) })); + return; + } + const params = { uri }; if (nav && nav.routes && nav.routes.length > 0 && 'Main' === nav.routes[0].routeName) { const mainRoute = nav.routes[0]; @@ -48,6 +69,11 @@ export function navigateToUri(navigation, uri, additionalParams) { return; } + if (uri.startsWith('lbry://?')) { + navigation.navigate({ routeName: getRouteForSpecialUri(uri) }); + return; + } + const params = Object.assign({ uri }, additionalParams); if ('File' === navigation.state.routeName) { const stackAction = StackActions.replace({ routeName: 'File', newKey: uri, params });