lbry-desktop/src/renderer/redux/selectors/app.js

250 lines
6.9 KiB
JavaScript
Raw Normal View History

import * as SETTINGS from 'constants/settings';
import * as PAGES from 'constants/pages';
import * as ICONS from 'constants/icons';
import { createSelector } from 'reselect';
import { selectCurrentPage, selectHistoryStack } from 'lbry-redux';
import { makeSelectClientSetting } from 'redux/selectors/settings';
2017-04-07 07:15:22 +02:00
export const selectState = state => state.app || {};
2017-04-07 07:15:22 +02: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
}
});
2017-04-07 07:15:22 +02:00
2018-11-07 23:44:38 +01:00
export const selectHasClickedComment = createSelector(
selectState,
state => state.hasClickedComment
);
export const selectRemoteVersion = createSelector(selectState, state => state.remoteVersion);
export const selectIsUpgradeAvailable = createSelector(
selectState,
state => state.isUpgradeAvailable
);
2017-04-07 07:15:22 +02:00
export const selectUpgradeFilename = createSelector(
selectPlatform,
selectRemoteVersion,
2017-04-07 07:15:22 +02:00
(platform, version) => {
switch (platform) {
case 'darwin':
return `LBRY_${version}.dmg`;
case 'linux':
return `LBRY_${version}.deb`;
case 'win32':
return `LBRY_${version}.exe`;
2017-04-07 07:15:22 +02:00
default:
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
export const selectDownloadProgress = createSelector(selectState, state => state.downloadProgress);
2017-04-07 07:15:22 +02:00
export const selectDownloadComplete = createSelector(
selectState,
2017-06-06 23:19:12 +02:00
state => state.upgradeDownloadCompleted
2017-06-06 06:21:55 +02:00
);
export const selectIsUpgradeSkipped = createSelector(selectState, state => state.isUpgradeSkipped);
2017-04-07 07:15:22 +02:00
export const selectUpgradeDownloadPath = createSelector(selectState, state => state.downloadPath);
2017-04-07 07:15:22 +02: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-02-24 01:24:00 +01:00
export const selectAutoUpdateDeclined = createSelector(
selectState,
state => state.autoUpdateDeclined
);
export const selectDaemonVersionMatched = createSelector(
selectState,
state => state.daemonVersionMatched
);
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
);
export const selectBadgeNumber = createSelector(selectState, state => state.badgeNumber);
2017-07-07 15:15:45 +02:00
export const selectCurrentLanguage = createSelector(
selectState,
() => app.i18n.getLocale() || 'en'
2017-08-08 11:36:14 +02:00
);
export const selectVolume = createSelector(selectState, state => state.volume);
export const selectUpgradeTimer = createSelector(selectState, state => state.checkUpgradeTimer);
export const selectNavLinks = createSelector(
selectCurrentPage,
selectHistoryStack,
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];
const isWalletPage = page =>
page === PAGES.WALLET ||
page === PAGES.SEND ||
page === PAGES.GET_CREDITS ||
page === PAGES.REWARDS ||
page === PAGES.HISTORY ||
page === PAGES.BACKUP;
const isCurrentlyWalletPage = isWalletPage(currentPage);
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 === PAGES.WALLET) {
const previousPath = getPreviousSubLinkPath(isWalletPage);
return previousPath || `/${PAGES.WALLET}`;
}
return undefined;
};
// 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),
});
const walletSubLinks = [
{
...buildLink('Overview', PAGES.WALLET),
},
{
...buildLink('Send & Receive', PAGES.SEND),
},
{
...buildLink('Transactions', PAGES.HISTORY),
},
{
...buildLink('Get Credits', PAGES.GET_CREDITS),
},
{
...buildLink('Rewards', PAGES.REWARDS),
},
{
...buildLink('Backup', PAGES.BACKUP),
},
];
const navLinks = {
primary: [
{
...buildLink('Explore', PAGES.DISCOVER),
icon: ICONS.HOME,
},
{
...buildLink('Subscriptions', PAGES.SUBSCRIPTIONS),
icon: ICONS.SUBSCRIPTION,
},
],
secondary: [
{
label: 'Wallet',
icon: ICONS.WALLET,
subLinks: walletSubLinks,
path: isCurrentlyWalletPage ? `/${PAGES.WALLET}` : getActiveSublink(PAGES.WALLET),
active: isWalletPage(currentPage),
},
{
...buildLink('Invite', PAGES.INVITE),
icon: ICONS.INVITE,
},
{
...buildLink('Downloads', PAGES.DOWNLOADED),
icon: ICONS.LOCAL,
},
{
...buildLink('Publishes', PAGES.PUBLISHED),
icon: ICONS.PUBLISHED,
},
{
...buildLink('History', PAGES.USER_HISTORY),
icon: ICONS.HISTORY,
},
{
...buildLink('Settings', PAGES.SETTINGS),
icon: ICONS.SETTINGS,
},
{
...buildLink('Help', PAGES.HELP),
icon: ICONS.HELP,
},
],
};
return navLinks;
}
);
export const selectModal = createSelector(selectState, state => {
if (!state.modal) {
return null;
}
return {
id: state.modal,
modalProps: state.modalProps,
};
});
2019-01-23 16:38:40 +01:00
export const selectEnhancedLayout = createSelector(selectState, state => state.enhancedLayout);