lbry-desktop/ui/redux/selectors/app.js

144 lines
5.2 KiB
JavaScript
Raw Normal View History

import { createSelector } from 'reselect';
import { selectClaimsById, selectMyChannelClaims, selectTotalStakedAmountForChannelUri } from 'redux/selectors/claims';
import * as MODALS from 'constants/modal_types';
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);
2020-04-14 01:48:11 +02:00
export const selectUpdateUrl = createSelector(selectPlatform, (platform) => {
2020-04-14 01:48:11 +02:00
switch (platform) {
case 'darwin':
return 'https://lbry.com/get/lbry.dmg';
case 'linux':
return 'https://lbry.com/get/lbry.deb';
case 'win32':
return 'https://lbry.com/get/lbry.exe';
default:
throw Error('Unknown platform');
2017-04-07 07:15:22 +02:00
}
2020-04-14 01:48:11 +02:00
});
export const selectHasClickedComment = createSelector(selectState, (state) => state.hasClickedComment);
2020-04-14 01:48:11 +02:00
export const selectRemoteVersion = createSelector(selectState, (state) => state.remoteVersion);
2020-04-14 01:48:11 +02:00
export const selectIsUpgradeAvailable = createSelector(selectState, (state) => state.isUpgradeAvailable);
2020-04-14 01:48:11 +02:00
export const selectUpgradeFilename = createSelector(selectPlatform, selectRemoteVersion, (platform, version) => {
switch (platform) {
case 'darwin':
return `LBRY_${version}.dmg`;
case 'linux':
return `LBRY_${version}.deb`;
case 'win32':
return `LBRY_${version}.exe`;
default:
throw Error('Unknown platform');
2017-04-07 07:15:22 +02:00
}
2020-04-14 01:48:11 +02:00
});
export const selectDownloadProgress = createSelector(selectState, (state) => state.downloadProgress);
2020-04-14 01:48:11 +02:00
export const selectDownloadComplete = createSelector(selectState, (state) => state.upgradeDownloadCompleted);
2020-04-14 01:48:11 +02:00
export const selectIsUpgradeSkipped = createSelector(selectState, (state) => state.isUpgradeSkipped);
2020-04-14 01:48:11 +02:00
export const selectUpgradeDownloadPath = createSelector(selectState, (state) => state.downloadPath);
2020-04-14 01:48:11 +02:00
export const selectUpgradeDownloadItem = createSelector(selectState, (state) => state.downloadItem);
2020-04-14 01:48:11 +02:00
export const selectAutoUpdateDownloaded = createSelector(selectState, (state) => state.autoUpdateDownloaded);
2020-04-14 01:48:11 +02:00
export const selectAutoUpdateDeclined = createSelector(selectState, (state) => state.autoUpdateDeclined);
2020-04-14 01:48:11 +02:00
2022-02-21 14:08:17 +01:00
export const selectIsUpdateModalDisplayed = createSelector(selectState, (state) => {
return [MODALS.AUTO_UPDATE_DOWNLOADED, MODALS.UPGRADE, MODALS.DOWNLOADING].includes(state.modal);
});
export const selectDaemonVersionMatched = createSelector(selectState, (state) => state.daemonVersionMatched);
2020-04-14 01:48:11 +02:00
export const selectVolume = createSelector(selectState, (state) => state.volume);
2020-04-14 01:48:11 +02:00
export const selectMute = createSelector(selectState, (state) => state.muted);
2020-04-14 01:48:11 +02:00
export const selectUpgradeTimer = createSelector(selectState, (state) => state.checkUpgradeTimer);
2020-04-14 01:48:11 +02:00
export const selectModal = createSelector(selectState, (state) => {
2020-04-14 01:48:11 +02:00
if (!state.modal) {
return null;
2019-03-05 05:46:57 +01:00
}
2020-04-14 01:48:11 +02:00
return {
id: state.modal,
modalProps: state.modalProps,
};
});
export const selectSearchOptionsExpanded = createSelector(selectState, (state) => state.searchOptionsExpanded);
2020-04-14 01:48:11 +02:00
export const selectWelcomeVersion = createSelector(selectState, (state) => state.welcomeVersion);
2020-04-14 01:48:11 +02:00
export const selectHasNavigated = createSelector(selectState, (state) => state.hasNavigated);
export const selectAllowAnalytics = createSelector(selectState, (state) => state.allowAnalytics);
2020-04-14 01:48:11 +02:00
export const selectScrollStartingPosition = createSelector(selectState, (state) => state.currentScroll);
2020-04-14 01:48:11 +02:00
export const selectIsPasswordSaved = createSelector(selectState, (state) => state.isPasswordSaved);
2020-09-04 17:02:30 +02:00
export const selectInterestedInYoutubeSync = createSelector(selectState, (state) => state.interestedInYoutubeSync);
2020-11-09 18:22:38 +01:00
export const selectSplashAnimationEnabled = createSelector(selectState, (state) => state.splashAnimationEnabled);
export const selectActiveChannelId = createSelector(selectState, (state) => state.activeChannel);
export const selectActiveChannelClaim = createSelector(
selectActiveChannelId,
selectClaimsById,
selectMyChannelClaims,
(activeChannelClaimId, claimsById, myChannelClaims) => {
if (!activeChannelClaimId || !claimsById || !myChannelClaims || !myChannelClaims.length) {
return undefined;
}
const activeChannelClaim = claimsById[activeChannelClaimId];
if (activeChannelClaim) {
return activeChannelClaim;
}
const myChannelClaimsByEffectiveAmount = myChannelClaims.slice().sort((a, b) => {
const effectiveAmountA = (a.meta && Number(a.meta.effective_amount)) || 0;
const effectiveAmountB = (b.meta && Number(b.meta.effective_amount)) || 0;
if (effectiveAmountA === effectiveAmountB) {
return 0;
} else if (effectiveAmountA > effectiveAmountB) {
return -1;
} else {
return 1;
}
});
return myChannelClaimsByEffectiveAmount[0];
}
);
export const selectActiveChannelStakedLevel = createSelector(
(state) => state,
selectActiveChannelClaim,
(state, activeChannelClaim) => {
if (!activeChannelClaim) {
return 0;
}
const uri = activeChannelClaim.permanent_url;
2022-01-04 16:13:15 +01:00
const stakedLevel = selectTotalStakedAmountForChannelUri(state, uri);
return stakedLevel;
}
);
export const selectIncognito = createSelector(selectState, (state) => state.incognito);
2022-02-25 21:01:14 +01:00
export const selectDiskSpace = createSelector(selectState, (state) => state.diskSpace);