2017-05-04 05:44:08 +02:00
|
|
|
import {createSelector} from 'reselect'
|
2017-05-23 10:46:52 +02:00
|
|
|
import {
|
|
|
|
parseQueryParams,
|
|
|
|
} from 'util/query_params'
|
2017-05-06 19:57:34 +02:00
|
|
|
import lbryuri from 'lbryuri'
|
2017-04-07 07:15:22 +02:00
|
|
|
|
|
|
|
export const _selectState = state => state.app || {}
|
|
|
|
|
|
|
|
export const selectIsLoaded = createSelector(
|
|
|
|
_selectState,
|
2017-04-24 09:25:27 +02:00
|
|
|
(state) => state.isLoaded
|
2017-04-07 07:15:22 +02:00
|
|
|
)
|
|
|
|
|
2017-04-24 09:25:27 +02:00
|
|
|
export const selectCurrentPath = createSelector(
|
2017-04-07 07:15:22 +02:00
|
|
|
_selectState,
|
2017-04-24 09:25:27 +02:00
|
|
|
(state) => state.currentPath
|
|
|
|
)
|
|
|
|
|
|
|
|
export const selectCurrentPage = createSelector(
|
|
|
|
selectCurrentPath,
|
2017-05-07 14:50:32 +02:00
|
|
|
(path) => {
|
2017-05-06 18:31:47 +02:00
|
|
|
return path.replace(/^\//, '').split('?')[0]
|
2017-05-05 10:01:16 +02:00
|
|
|
}
|
2017-04-24 09:25:27 +02:00
|
|
|
)
|
|
|
|
|
2017-05-07 14:50:32 +02:00
|
|
|
export const selectCurrentParams = createSelector(
|
|
|
|
selectCurrentPath,
|
|
|
|
(path) => {
|
|
|
|
if (path === undefined) return {}
|
|
|
|
if (!path.match(/\?/)) return {}
|
|
|
|
|
|
|
|
return parseQueryParams(path.split('?')[1])
|
|
|
|
}
|
|
|
|
)
|
|
|
|
|
2017-04-30 18:01:43 +02:00
|
|
|
export const selectPageTitle = createSelector(
|
|
|
|
selectCurrentPage,
|
2017-05-15 05:50:59 +02:00
|
|
|
selectCurrentParams,
|
|
|
|
(page, params) => {
|
2017-05-04 05:44:08 +02:00
|
|
|
switch (page) {
|
|
|
|
case 'search':
|
2017-05-26 02:16:25 +02:00
|
|
|
return params.query ? __("Search results for %s", params.query) : __('Search')
|
2017-05-04 05:44:08 +02:00
|
|
|
case 'settings':
|
2017-05-26 02:16:25 +02:00
|
|
|
return __('Settings')
|
2017-05-04 05:44:08 +02:00
|
|
|
case 'help':
|
2017-05-26 02:16:25 +02:00
|
|
|
return __('Help')
|
2017-05-04 05:44:08 +02:00
|
|
|
case 'report':
|
2017-05-26 02:16:25 +02:00
|
|
|
return __('Report')
|
2017-04-30 18:01:43 +02:00
|
|
|
case 'wallet':
|
|
|
|
case 'send':
|
|
|
|
case 'receive':
|
2017-05-02 07:31:51 +02:00
|
|
|
case 'rewards':
|
2017-05-04 05:44:08 +02:00
|
|
|
return page.charAt(0).toUpperCase() + page.slice(1)
|
|
|
|
case 'show':
|
2017-05-15 05:50:59 +02:00
|
|
|
return lbryuri.normalize(params.uri)
|
2017-04-30 18:01:43 +02:00
|
|
|
case 'downloaded':
|
2017-05-26 02:16:25 +02:00
|
|
|
return __('Downloads & Purchases')
|
2017-04-30 18:01:43 +02:00
|
|
|
case 'published':
|
2017-05-26 02:16:25 +02:00
|
|
|
return __('Publishes')
|
2017-05-04 05:44:08 +02:00
|
|
|
case 'start':
|
2017-05-26 02:16:25 +02:00
|
|
|
return __('Start')
|
2017-04-30 18:01:43 +02:00
|
|
|
case 'publish':
|
2017-05-26 02:16:25 +02:00
|
|
|
return __('Publish')
|
2017-04-30 18:01:43 +02:00
|
|
|
case 'help':
|
2017-05-26 02:16:25 +02:00
|
|
|
return __('Help')
|
2017-05-04 05:44:08 +02:00
|
|
|
case 'developer':
|
2017-05-26 02:16:25 +02:00
|
|
|
return __('Developer')
|
2017-05-04 05:44:08 +02:00
|
|
|
case 'discover':
|
2017-05-26 02:16:25 +02:00
|
|
|
return __('Home')
|
2017-04-30 18:01:43 +02:00
|
|
|
default:
|
2017-05-04 05:44:08 +02:00
|
|
|
return '';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
)
|
|
|
|
|
2017-04-07 07:15:22 +02:00
|
|
|
export const selectPlatform = createSelector(
|
|
|
|
_selectState,
|
2017-04-24 09:25:27 +02:00
|
|
|
(state) => state.platform
|
2017-04-07 07:15:22 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
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 'Unknown platform';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
)
|
|
|
|
|
|
|
|
export const selectVersion = createSelector(
|
|
|
|
_selectState,
|
|
|
|
(state) => {
|
|
|
|
return state.version
|
|
|
|
}
|
|
|
|
)
|
|
|
|
|
|
|
|
export const selectUpgradeFilename = createSelector(
|
|
|
|
selectPlatform,
|
|
|
|
selectVersion,
|
|
|
|
(platform, version) => {
|
|
|
|
switch (platform) {
|
|
|
|
case 'darwin':
|
|
|
|
return `LBRY-${version}.dmg`;
|
|
|
|
case 'linux':
|
|
|
|
return `LBRY_${version}_amd64.deb`;
|
|
|
|
case 'windows':
|
|
|
|
return `LBRY.Setup.${version}.exe`;
|
|
|
|
default:
|
|
|
|
throw 'Unknown platform';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
)
|
|
|
|
|
|
|
|
export const selectCurrentModal = createSelector(
|
|
|
|
_selectState,
|
|
|
|
(state) => state.modal
|
|
|
|
)
|
|
|
|
|
|
|
|
export const selectDownloadProgress = createSelector(
|
|
|
|
_selectState,
|
|
|
|
(state) => state.downloadProgress
|
|
|
|
)
|
|
|
|
|
|
|
|
export const selectDownloadComplete = createSelector(
|
|
|
|
_selectState,
|
|
|
|
(state) => state.upgradeDownloadCompleted
|
|
|
|
)
|
|
|
|
|
|
|
|
export const selectHeaderLinks = createSelector(
|
|
|
|
selectCurrentPage,
|
|
|
|
(page) => {
|
2017-05-04 05:44:08 +02:00
|
|
|
switch (page) {
|
2017-04-07 07:15:22 +02:00
|
|
|
case 'wallet':
|
|
|
|
case 'send':
|
|
|
|
case 'receive':
|
2017-05-02 07:31:51 +02:00
|
|
|
case 'rewards':
|
2017-04-07 07:15:22 +02:00
|
|
|
return {
|
2017-05-26 02:16:25 +02:00
|
|
|
'wallet': __('Overview'),
|
|
|
|
'send': __('Send'),
|
|
|
|
'receive': __('Receive'),
|
|
|
|
'rewards': __('Rewards'),
|
2017-04-07 07:15:22 +02:00
|
|
|
};
|
|
|
|
case 'downloaded':
|
|
|
|
case 'published':
|
|
|
|
return {
|
2017-05-26 02:16:25 +02:00
|
|
|
'downloaded': __('Downloaded'),
|
|
|
|
'published': __('Published'),
|
2017-04-07 07:15:22 +02:00
|
|
|
};
|
2017-05-05 07:28:28 +02:00
|
|
|
case 'settings':
|
|
|
|
case 'help':
|
|
|
|
return {
|
2017-05-26 02:16:25 +02:00
|
|
|
'settings': __('Settings'),
|
|
|
|
'help': __('Help'),
|
2017-05-05 07:28:28 +02:00
|
|
|
}
|
2017-04-07 07:15:22 +02:00
|
|
|
default:
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
)
|
|
|
|
|
|
|
|
export const selectUpgradeSkipped = createSelector(
|
|
|
|
_selectState,
|
|
|
|
(state) => state.upgradeSkipped
|
|
|
|
)
|
|
|
|
|
|
|
|
export const selectUpgradeDownloadDir = createSelector(
|
|
|
|
_selectState,
|
|
|
|
(state) => state.downloadDir
|
|
|
|
)
|
|
|
|
|
|
|
|
export const selectUpgradeDownloadItem = createSelector(
|
|
|
|
_selectState,
|
|
|
|
(state) => state.downloadItem
|
|
|
|
)
|
|
|
|
|
2017-05-24 23:53:03 +02:00
|
|
|
export const selectModalExtraContent = createSelector(
|
2017-04-07 07:15:22 +02:00
|
|
|
_selectState,
|
2017-05-24 23:53:03 +02:00
|
|
|
(state) => state.modalExtraContent
|
2017-04-07 07:15:22 +02:00
|
|
|
)
|
2017-04-22 15:17:01 +02:00
|
|
|
|
|
|
|
export const selectDaemonReady = createSelector(
|
|
|
|
_selectState,
|
|
|
|
(state) => state.daemonReady
|
|
|
|
)
|
2017-04-29 11:50:29 +02:00
|
|
|
|
|
|
|
export const selectObscureNsfw = createSelector(
|
|
|
|
_selectState,
|
|
|
|
(state) => !!state.obscureNsfw
|
2017-05-23 09:21:21 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
export const selectSnackBar = createSelector(
|
|
|
|
_selectState,
|
|
|
|
(state) => state.snackBar || {}
|
|
|
|
)
|
|
|
|
|
|
|
|
export const selectSnackBarSnacks = createSelector(
|
|
|
|
selectSnackBar,
|
|
|
|
(snackBar) => snackBar.snacks || []
|
2017-05-26 02:16:25 +02:00
|
|
|
)
|