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

111 lines
4.4 KiB
JavaScript
Raw Normal View History

import { createSelector } from 'reselect';
2021-11-10 16:30:58 +01:00
import { selectClaimWithId, selectMyChannelClaims, selectStakedLevelForChannelUri } from 'redux/selectors/claims';
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 = (state) => selectState(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 = (state) => selectState(state).hasClickedComment;
export const selectRemoteVersion = (state) => selectState(state).remoteVersion;
export const selectIsUpgradeAvailable = (state) => selectState(state).isUpgradeAvailable;
export const selectIsReloadRequired = (state) => selectState(state).isReloadRequired;
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 = (state) => selectState(state).downloadProgress;
export const selectDownloadComplete = (state) => selectState(state).upgradeDownloadCompleted;
export const selectIsUpgradeSkipped = (state) => selectState(state).isUpgradeSkipped;
export const selectUpgradeDownloadPath = (state) => selectState(state).downloadPath;
export const selectUpgradeDownloadItem = (state) => selectState(state).downloadItem;
export const selectAutoUpdateDownloaded = (state) => selectState(state).autoUpdateDownloaded;
export const selectAutoUpdateDeclined = (state) => selectState(state).autoUpdateDeclined;
export const selectDaemonVersionMatched = (state) => selectState(state).daemonVersionMatched;
export const selectVolume = (state) => selectState(state).volume;
export const selectMute = (state) => selectState(state).muted;
export const selectUpgradeTimer = (state) => selectState(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 = (state) => selectState(state).searchOptionsExpanded;
export const selectWelcomeVersion = (state) => selectState(state).welcomeVersion;
export const selectHasNavigated = (state) => selectState(state).hasNavigated;
export const selectAllowAnalytics = (state) => selectState(state).allowAnalytics;
export const selectScrollStartingPosition = (state) => selectState(state).currentScroll;
export const selectIsPasswordSaved = (state) => selectState(state).isPasswordSaved;
export const selectInterestedInYoutubeSync = (state) => selectState(state).interestedInYoutubeSync;
export const selectSplashAnimationEnabled = (state) => selectState(state).splashAnimationEnabled;
export const selectActiveChannelId = (state) => selectState(state).activeChannel;
export const selectActiveChannelClaim = createSelector(
(state) => selectClaimWithId(state, selectActiveChannelId(state)), // i.e. 'byId[activeChannelId]' specifically, instead of just 'byId'.
selectMyChannelClaims,
(activeChannelClaim, myChannelClaims) => {
if (!activeChannelClaim || !myChannelClaims || !myChannelClaims.length) {
return undefined;
}
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];
}
);
2021-11-10 16:30:58 +01:00
export const selectActiveChannelStakedLevel = (state) => {
const activeChannelClaim = selectActiveChannelClaim(state);
if (!activeChannelClaim) {
return 0;
}
2021-11-10 16:30:58 +01:00
const uri = activeChannelClaim.permanent_url;
return selectStakedLevelForChannelUri(state, uri);
};
export const selectIncognito = (state) => selectState(state).incognito;