2019-01-27 01:23:47 +01:00
|
|
|
import * as SETTINGS from 'constants/settings';
|
|
|
|
import * as PAGES from 'constants/pages';
|
|
|
|
import * as ICONS from 'constants/icons';
|
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';
|
2019-01-27 01:23:47 +01:00
|
|
|
import { makeSelectClientSetting } from 'redux/selectors/settings';
|
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
|
|
|
|
2019-01-11 17:34:36 +01:00
|
|
|
export const selectPlatform = createSelector(selectState, state => state.platform);
|
|
|
|
|
|
|
|
export const selectUpdateUrl = createSelector(selectPlatform, platform => {
|
|
|
|
switch (platform) {
|
|
|
|
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';
|
|
|
|
default:
|
|
|
|
throw Error('Unknown platform');
|
2017-04-07 07:15:22 +02:00
|
|
|
}
|
2019-01-11 17:34:36 +01: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
|
|
|
|
2019-01-11 17:34:36 +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
|
|
|
);
|
|
|
|
|
2019-01-11 17:34:36 +01:00
|
|
|
export const selectIsUpgradeSkipped = createSelector(selectState, state => state.isUpgradeSkipped);
|
2017-04-07 07:15:22 +02:00
|
|
|
|
2019-01-11 17:34:36 +01:00
|
|
|
export const selectUpgradeDownloadPath = createSelector(selectState, state => state.downloadPath);
|
2017-04-07 07:15:22 +02:00
|
|
|
|
2019-01-11 17:34:36 +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
|
|
|
|
);
|
|
|
|
|
2019-01-11 17:34:36 +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
|
|
|
|
2019-01-11 17:34:36 +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
|
|
|
);
|
|
|
|
|
2019-01-11 17:34:36 +01:00
|
|
|
export const selectVolume = createSelector(selectState, state => state.volume);
|
2018-08-06 19:25:30 +02:00
|
|
|
|
2019-01-11 17:34:36 +01:00
|
|
|
export const selectUpgradeTimer = createSelector(selectState, state => state.checkUpgradeTimer);
|
2018-09-04 19:23:18 +02:00
|
|
|
|
|
|
|
export const selectNavLinks = createSelector(
|
|
|
|
selectCurrentPage,
|
|
|
|
selectHistoryStack,
|
2019-01-27 01:23:47 +01:00
|
|
|
makeSelectClientSetting(SETTINGS.FIRST_RUN_COMPLETED),
|
|
|
|
makeSelectClientSetting(SETTINGS.INVITE_ACKNOWLEDGED),
|
|
|
|
(currentPage, historyStack, firstRunCompleted, inviteAcknowledged) => {
|
|
|
|
// Determine if any links should show a tooltip for a guided tour
|
|
|
|
// It will only show one at a time, in the order they are set.
|
|
|
|
const guidedTourItem = [
|
|
|
|
{
|
|
|
|
page: PAGES.INVITE,
|
|
|
|
hasBeenCompleted: inviteAcknowledged,
|
|
|
|
guide: 'Check this out!',
|
|
|
|
},
|
|
|
|
// Add more items below for tooltip guides that will happen after a user has completed the invite guide
|
|
|
|
].filter(({ hasBeenCompleted }) => !hasBeenCompleted)[0];
|
|
|
|
|
2018-09-04 19:23:18 +02:00
|
|
|
const isWalletPage = page =>
|
2019-01-27 01:23:47 +01:00
|
|
|
page === PAGES.WALLET ||
|
|
|
|
page === PAGES.SEND ||
|
|
|
|
page === PAGES.GET_CREDITS ||
|
|
|
|
page === PAGES.REWARDS ||
|
|
|
|
page === PAGES.HISTORY ||
|
|
|
|
page === PAGES.BACKUP;
|
2018-09-04 19:23:18 +02:00
|
|
|
|
2019-01-27 01:23:47 +01:00
|
|
|
const isCurrentlyWalletPage = isWalletPage(currentPage);
|
2018-09-04 19:23:18 +02:00
|
|
|
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 => {
|
2019-01-27 01:23:47 +01:00
|
|
|
if (category === PAGES.WALLET) {
|
2018-09-04 19:23:18 +02:00
|
|
|
const previousPath = getPreviousSubLinkPath(isWalletPage);
|
2019-01-27 01:23:47 +01:00
|
|
|
return previousPath || `/${PAGES.WALLET}`;
|
2018-09-04 19:23:18 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return undefined;
|
|
|
|
};
|
|
|
|
|
2019-01-27 01:23:47 +01:00
|
|
|
// Is this path the first unacknowledged item in the guided tour list
|
|
|
|
const getGuideIfNecessary = page => {
|
|
|
|
if (!firstRunCompleted) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
return guidedTourItem && guidedTourItem.page === page ? guidedTourItem.guide : null;
|
|
|
|
};
|
|
|
|
|
|
|
|
const buildLink = (label, page) => ({
|
|
|
|
label,
|
|
|
|
path: `/${page}`,
|
|
|
|
active: currentPage === page,
|
|
|
|
guide: getGuideIfNecessary(page),
|
|
|
|
});
|
2018-09-04 19:23:18 +02:00
|
|
|
|
|
|
|
const walletSubLinks = [
|
|
|
|
{
|
2019-01-27 01:23:47 +01:00
|
|
|
...buildLink('Overview', PAGES.WALLET),
|
2018-09-04 19:23:18 +02:00
|
|
|
},
|
|
|
|
{
|
2019-01-27 01:23:47 +01:00
|
|
|
...buildLink('Send & Receive', PAGES.SEND),
|
2018-09-04 19:23:18 +02:00
|
|
|
},
|
|
|
|
{
|
2019-01-27 01:23:47 +01:00
|
|
|
...buildLink('Transactions', PAGES.HISTORY),
|
2018-09-04 19:23:18 +02:00
|
|
|
},
|
|
|
|
{
|
2019-01-27 01:23:47 +01:00
|
|
|
...buildLink('Get Credits', PAGES.GET_CREDITS),
|
2018-09-04 19:23:18 +02:00
|
|
|
},
|
|
|
|
{
|
2019-01-27 01:23:47 +01:00
|
|
|
...buildLink('Rewards', PAGES.REWARDS),
|
2018-09-04 19:23:18 +02:00
|
|
|
},
|
|
|
|
{
|
2019-01-27 01:23:47 +01:00
|
|
|
...buildLink('Backup', PAGES.BACKUP),
|
2018-09-04 19:23:18 +02:00
|
|
|
},
|
|
|
|
];
|
|
|
|
|
|
|
|
const navLinks = {
|
|
|
|
primary: [
|
|
|
|
{
|
2019-01-27 01:23:47 +01:00
|
|
|
...buildLink('Explore', PAGES.DISCOVER),
|
|
|
|
icon: ICONS.HOME,
|
2018-09-04 19:23:18 +02:00
|
|
|
},
|
|
|
|
{
|
2019-01-27 01:23:47 +01:00
|
|
|
...buildLink('Subscriptions', PAGES.SUBSCRIPTIONS),
|
|
|
|
icon: ICONS.SUBSCRIPTION,
|
2018-09-04 19:23:18 +02:00
|
|
|
},
|
|
|
|
],
|
|
|
|
secondary: [
|
|
|
|
{
|
|
|
|
label: 'Wallet',
|
2019-01-27 01:23:47 +01:00
|
|
|
icon: ICONS.WALLET,
|
2018-09-04 19:23:18 +02:00
|
|
|
subLinks: walletSubLinks,
|
2019-01-27 01:23:47 +01:00
|
|
|
path: isCurrentlyWalletPage ? `/${PAGES.WALLET}` : getActiveSublink(PAGES.WALLET),
|
2018-09-04 19:23:18 +02:00
|
|
|
active: isWalletPage(currentPage),
|
|
|
|
},
|
2019-01-11 17:34:36 +01:00
|
|
|
{
|
2019-01-27 01:23:47 +01:00
|
|
|
...buildLink('Invite', PAGES.INVITE),
|
|
|
|
icon: ICONS.INVITE,
|
2019-01-11 17:34:36 +01:00
|
|
|
},
|
2018-09-04 19:23:18 +02:00
|
|
|
{
|
2019-01-27 01:23:47 +01:00
|
|
|
...buildLink('Downloads', PAGES.DOWNLOADED),
|
|
|
|
icon: ICONS.LOCAL,
|
2019-01-23 18:15:50 +01:00
|
|
|
},
|
|
|
|
{
|
2019-01-27 01:23:47 +01:00
|
|
|
...buildLink('Publishes', PAGES.PUBLISHED),
|
|
|
|
icon: ICONS.PUBLISHED,
|
2019-01-23 18:15:50 +01:00
|
|
|
},
|
|
|
|
{
|
2019-01-27 01:23:47 +01:00
|
|
|
...buildLink('History', PAGES.USER_HISTORY),
|
|
|
|
icon: ICONS.HISTORY,
|
2018-09-04 19:23:18 +02:00
|
|
|
},
|
|
|
|
{
|
2019-01-27 01:23:47 +01:00
|
|
|
...buildLink('Settings', PAGES.SETTINGS),
|
|
|
|
icon: ICONS.SETTINGS,
|
2018-09-04 19:23:18 +02:00
|
|
|
},
|
|
|
|
{
|
2019-01-27 01:23:47 +01:00
|
|
|
...buildLink('Help', PAGES.HELP),
|
|
|
|
icon: ICONS.HELP,
|
2018-09-04 19:23:18 +02:00
|
|
|
},
|
|
|
|
],
|
|
|
|
};
|
|
|
|
|
|
|
|
return navLinks;
|
|
|
|
}
|
|
|
|
);
|
2018-10-29 18:23:53 +01:00
|
|
|
|
2019-01-11 17:34:36 +01:00
|
|
|
export const selectModal = createSelector(selectState, state => {
|
|
|
|
if (!state.modal) {
|
|
|
|
return null;
|
|
|
|
}
|
2018-10-29 18:23:53 +01:00
|
|
|
|
|
|
|
return {
|
|
|
|
id: state.modal,
|
|
|
|
modalProps: state.modalProps,
|
2019-01-11 17:34:36 +01:00
|
|
|
};
|
|
|
|
});
|
2019-01-23 16:38:40 +01:00
|
|
|
|
|
|
|
export const selectEnhancedLayout = createSelector(selectState, state => state.enhancedLayout);
|