2017-12-21 18:32:51 +01:00
|
|
|
import { createSelector } from 'reselect';
|
2018-09-04 19:23:18 +02:00
|
|
|
import { selectCurrentPage, selectHistoryStack } from 'lbry-redux';
|
2018-10-19 22:38:07 +02:00
|
|
|
import * as icons from 'constants/icons';
|
2017-04-07 07:15:22 +02:00
|
|
|
|
2017-12-21 18:32:51 +01:00
|
|
|
export const selectState = state => state.app || {};
|
2017-04-07 07:15:22 +02:00
|
|
|
|
2017-12-21 18:32:51 +01:00
|
|
|
export const selectPlatform = createSelector(selectState, state => state.platform);
|
2017-06-06 06:21:55 +02:00
|
|
|
|
|
|
|
export const selectUpdateUrl = createSelector(selectPlatform, platform => {
|
2017-06-06 23:19:12 +02:00
|
|
|
switch (platform) {
|
2017-12-21 18:32:51 +01:00
|
|
|
case 'darwin':
|
|
|
|
return 'https://lbry.io/get/lbry.dmg';
|
|
|
|
case 'linux':
|
|
|
|
return 'https://lbry.io/get/lbry.deb';
|
|
|
|
case 'win32':
|
|
|
|
return 'https://lbry.io/get/lbry.exe';
|
2017-06-06 23:19:12 +02:00
|
|
|
default:
|
2017-12-21 18:32:51 +01:00
|
|
|
throw Error('Unknown platform');
|
2017-04-07 07:15:22 +02:00
|
|
|
}
|
2017-06-06 06:21:55 +02:00
|
|
|
});
|
2017-04-07 07:15:22 +02:00
|
|
|
|
2018-11-07 23:44:38 +01:00
|
|
|
export const selectHasClickedComment = createSelector(
|
|
|
|
selectState,
|
|
|
|
state => state.hasClickedComment
|
|
|
|
);
|
|
|
|
|
2017-12-21 18:32:51 +01:00
|
|
|
export const selectRemoteVersion = createSelector(selectState, state => state.remoteVersion);
|
2017-11-15 02:50:21 +01:00
|
|
|
|
|
|
|
export const selectIsUpgradeAvailable = createSelector(
|
2017-12-21 18:32:51 +01:00
|
|
|
selectState,
|
2017-11-15 02:50:21 +01:00
|
|
|
state => state.isUpgradeAvailable
|
|
|
|
);
|
2017-04-07 07:15:22 +02:00
|
|
|
|
|
|
|
export const selectUpgradeFilename = createSelector(
|
|
|
|
selectPlatform,
|
2017-11-15 02:50:21 +01:00
|
|
|
selectRemoteVersion,
|
2017-04-07 07:15:22 +02:00
|
|
|
(platform, version) => {
|
|
|
|
switch (platform) {
|
2017-12-21 18:32:51 +01:00
|
|
|
case 'darwin':
|
2017-06-01 08:52:17 +02:00
|
|
|
return `LBRY_${version}.dmg`;
|
2017-12-21 18:32:51 +01:00
|
|
|
case 'linux':
|
2018-06-20 01:02:23 +02:00
|
|
|
return `LBRY_${version}.deb`;
|
2017-12-21 18:32:51 +01:00
|
|
|
case 'win32':
|
2017-06-01 08:52:17 +02:00
|
|
|
return `LBRY_${version}.exe`;
|
2017-04-07 07:15:22 +02:00
|
|
|
default:
|
2017-12-21 18:32:51 +01:00
|
|
|
throw Error('Unknown platform');
|
2017-04-07 07:15:22 +02:00
|
|
|
}
|
|
|
|
}
|
2017-06-06 06:21:55 +02:00
|
|
|
);
|
2017-04-07 07:15:22 +02:00
|
|
|
|
2017-12-21 18:32:51 +01:00
|
|
|
export const selectDownloadProgress = createSelector(selectState, state => state.downloadProgress);
|
2017-04-07 07:15:22 +02:00
|
|
|
|
|
|
|
export const selectDownloadComplete = createSelector(
|
2017-12-21 18:32:51 +01:00
|
|
|
selectState,
|
2017-06-06 23:19:12 +02:00
|
|
|
state => state.upgradeDownloadCompleted
|
2017-06-06 06:21:55 +02:00
|
|
|
);
|
|
|
|
|
2017-12-21 18:32:51 +01:00
|
|
|
export const selectIsUpgradeSkipped = createSelector(selectState, state => state.isUpgradeSkipped);
|
2017-04-07 07:15:22 +02:00
|
|
|
|
2017-12-21 18:32:51 +01:00
|
|
|
export const selectUpgradeDownloadPath = createSelector(selectState, state => state.downloadPath);
|
2017-04-07 07:15:22 +02:00
|
|
|
|
2017-12-21 18:32:51 +01:00
|
|
|
export const selectUpgradeDownloadItem = createSelector(selectState, state => state.downloadItem);
|
2017-04-07 07:15:22 +02:00
|
|
|
|
2018-02-24 01:24:00 +01:00
|
|
|
export const selectAutoUpdateDownloaded = createSelector(
|
|
|
|
selectState,
|
|
|
|
state => state.autoUpdateDownloaded
|
|
|
|
);
|
2018-01-16 06:38:23 +01:00
|
|
|
|
2018-02-24 01:24:00 +01:00
|
|
|
export const selectAutoUpdateDeclined = createSelector(
|
|
|
|
selectState,
|
|
|
|
state => state.autoUpdateDeclined
|
|
|
|
);
|
2018-01-17 11:50:02 +01:00
|
|
|
|
2017-07-19 23:05:08 +02:00
|
|
|
export const selectDaemonVersionMatched = createSelector(
|
2017-12-21 18:32:51 +01:00
|
|
|
selectState,
|
2017-07-19 23:05:08 +02:00
|
|
|
state => state.daemonVersionMatched
|
|
|
|
);
|
|
|
|
|
2017-12-21 18:32:51 +01:00
|
|
|
export const selectSnackBar = createSelector(selectState, state => state.snackBar || {});
|
2017-05-23 09:21:21 +02:00
|
|
|
|
|
|
|
export const selectSnackBarSnacks = createSelector(
|
|
|
|
selectSnackBar,
|
2017-06-06 23:19:12 +02:00
|
|
|
snackBar => snackBar.snacks || []
|
2017-06-06 06:21:55 +02:00
|
|
|
);
|
2017-06-24 10:57:37 +02:00
|
|
|
|
2017-12-21 18:32:51 +01:00
|
|
|
export const selectBadgeNumber = createSelector(selectState, state => state.badgeNumber);
|
2017-07-07 15:15:45 +02:00
|
|
|
|
|
|
|
export const selectCurrentLanguage = createSelector(
|
2017-12-21 18:32:51 +01:00
|
|
|
selectState,
|
|
|
|
() => app.i18n.getLocale() || 'en'
|
2017-08-08 11:36:14 +02:00
|
|
|
);
|
|
|
|
|
2017-12-21 18:32:51 +01:00
|
|
|
export const selectVolume = createSelector(selectState, state => state.volume);
|
2018-08-06 19:25:30 +02:00
|
|
|
|
|
|
|
export const selectUpgradeTimer = createSelector(selectState, state => state.checkUpgradeTimer);
|
2018-09-04 19:23:18 +02:00
|
|
|
|
|
|
|
export const selectNavLinks = createSelector(
|
|
|
|
selectCurrentPage,
|
|
|
|
selectHistoryStack,
|
|
|
|
(currentPage, historyStack) => {
|
|
|
|
const isWalletPage = page =>
|
|
|
|
page === 'wallet' ||
|
|
|
|
page === 'send' ||
|
|
|
|
page === 'getcredits' ||
|
|
|
|
page === 'rewards' ||
|
|
|
|
page === 'history' ||
|
|
|
|
page === 'invite' ||
|
|
|
|
page === 'backup';
|
|
|
|
|
|
|
|
const isMyLbryPage = page =>
|
|
|
|
page === 'downloaded' || page === 'published' || page === 'user_history';
|
|
|
|
|
|
|
|
const previousStack = historyStack.slice().reverse();
|
|
|
|
|
|
|
|
const getPreviousSubLinkPath = checkIfValidPage => {
|
|
|
|
for (let i = 0; i < previousStack.length; i += 1) {
|
|
|
|
const currentStackItem = previousStack[i];
|
|
|
|
|
|
|
|
// Trim off the "/" from the path
|
|
|
|
const pageInStack = currentStackItem.path.slice(1);
|
|
|
|
if (checkIfValidPage(pageInStack)) {
|
|
|
|
return currentStackItem.path;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return undefined;
|
|
|
|
};
|
|
|
|
|
|
|
|
// Gets the last active sublink in a section
|
|
|
|
const getActiveSublink = category => {
|
|
|
|
if (category === 'wallet') {
|
|
|
|
const previousPath = getPreviousSubLinkPath(isWalletPage);
|
|
|
|
return previousPath || '/wallet';
|
|
|
|
} else if (category === 'myLbry') {
|
|
|
|
const previousPath = getPreviousSubLinkPath(isMyLbryPage);
|
|
|
|
return previousPath || '/downloaded';
|
|
|
|
}
|
|
|
|
|
|
|
|
return undefined;
|
|
|
|
};
|
|
|
|
|
|
|
|
const isCurrentlyWalletPage = isWalletPage(currentPage);
|
|
|
|
const isCurrentlyMyLbryPage = isMyLbryPage(currentPage);
|
|
|
|
|
|
|
|
const walletSubLinks = [
|
|
|
|
{
|
|
|
|
label: 'Overview',
|
|
|
|
path: '/wallet',
|
|
|
|
active: currentPage === 'wallet',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
label: 'Send & Receive',
|
|
|
|
path: '/send',
|
|
|
|
active: currentPage === 'send',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
label: 'Transactions',
|
|
|
|
path: '/history',
|
|
|
|
active: currentPage === 'history',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
label: 'Get Credits',
|
|
|
|
path: '/getcredits',
|
|
|
|
active: currentPage === 'getcredits',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
label: 'Rewards',
|
|
|
|
path: '/rewards',
|
|
|
|
active: currentPage === 'rewards',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
label: 'Invites',
|
|
|
|
path: '/invite',
|
|
|
|
active: currentPage === 'invite',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
label: 'Backup',
|
|
|
|
path: '/backup',
|
|
|
|
active: currentPage === 'backup',
|
|
|
|
},
|
|
|
|
];
|
|
|
|
|
|
|
|
const myLbrySubLinks = [
|
|
|
|
{
|
|
|
|
label: 'Downloads',
|
|
|
|
path: '/downloaded',
|
|
|
|
active: currentPage === 'downloaded',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
label: 'Publishes',
|
|
|
|
path: '/published',
|
|
|
|
active: currentPage === 'published',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
label: 'History',
|
|
|
|
path: '/user_history',
|
|
|
|
active: currentPage === 'user_history',
|
|
|
|
},
|
|
|
|
];
|
|
|
|
|
|
|
|
const navLinks = {
|
|
|
|
primary: [
|
|
|
|
{
|
|
|
|
label: 'Explore',
|
|
|
|
path: '/discover',
|
|
|
|
active: currentPage === 'discover',
|
2018-10-19 22:38:07 +02:00
|
|
|
icon: icons.COMPASS,
|
2018-09-04 19:23:18 +02:00
|
|
|
},
|
|
|
|
{
|
|
|
|
label: 'Subscriptions',
|
|
|
|
path: '/subscriptions',
|
|
|
|
active: currentPage === 'subscriptions',
|
2018-10-19 22:38:07 +02:00
|
|
|
icon: icons.HEART,
|
2018-09-04 19:23:18 +02:00
|
|
|
},
|
|
|
|
],
|
|
|
|
secondary: [
|
|
|
|
{
|
|
|
|
label: 'Wallet',
|
2018-10-19 22:38:07 +02:00
|
|
|
icon: icons.CREDIT_CARD,
|
2018-09-04 19:23:18 +02:00
|
|
|
subLinks: walletSubLinks,
|
|
|
|
path: isCurrentlyWalletPage ? '/wallet' : getActiveSublink('wallet'),
|
|
|
|
active: isWalletPage(currentPage),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
label: 'My LBRY',
|
2018-10-19 22:38:07 +02:00
|
|
|
icon: icons.LOCAL,
|
2018-09-04 19:23:18 +02:00
|
|
|
subLinks: myLbrySubLinks,
|
|
|
|
path: isCurrentlyMyLbryPage ? '/downloaded' : getActiveSublink('myLbry'),
|
|
|
|
active: isMyLbryPage(currentPage),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
label: 'Publish',
|
2018-10-19 22:38:07 +02:00
|
|
|
icon: icons.UPLOAD,
|
2018-09-04 19:23:18 +02:00
|
|
|
path: '/publish',
|
|
|
|
active: currentPage === 'publish',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
label: 'Settings',
|
2018-10-19 22:38:07 +02:00
|
|
|
icon: icons.SETTINGS,
|
2018-09-04 19:23:18 +02:00
|
|
|
path: '/settings',
|
|
|
|
active: currentPage === 'settings',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
label: 'Help',
|
|
|
|
path: '/help',
|
2018-10-19 22:38:07 +02:00
|
|
|
icon: icons.HELP,
|
2018-09-04 19:23:18 +02:00
|
|
|
active: currentPage === 'help',
|
|
|
|
},
|
|
|
|
],
|
|
|
|
};
|
|
|
|
|
|
|
|
return navLinks;
|
|
|
|
}
|
|
|
|
);
|