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

187 lines
4.2 KiB
JavaScript
Raw Normal View History

2017-06-06 23:19:12 +02:00
import { createSelector } from "reselect";
import { parseQueryParams } from "util/query_params";
import lbryuri from "lbryuri";
2017-04-07 07:15:22 +02:00
2017-06-06 06:21:55 +02:00
export const _selectState = state => state.app || {};
2017-04-07 07:15:22 +02:00
export const selectIsLoaded = createSelector(
_selectState,
2017-06-06 23:19:12 +02:00
state => state.isLoaded
2017-06-06 06:21:55 +02:00
);
2017-04-07 07:15:22 +02:00
export const selectCurrentPath = createSelector(
2017-04-07 07:15:22 +02:00
_selectState,
2017-06-06 23:19:12 +02:00
state => state.currentPath
2017-06-06 06:21:55 +02:00
);
2017-06-06 06:21:55 +02:00
export const selectCurrentPage = createSelector(selectCurrentPath, path => {
2017-06-06 23:19:12 +02:00
return path.replace(/^\//, "").split("?")[0];
2017-06-06 06:21:55 +02:00
});
2017-06-06 06:21:55 +02:00
export const selectCurrentParams = createSelector(selectCurrentPath, path => {
2017-06-06 23:19:12 +02:00
if (path === undefined) return {};
if (!path.match(/\?/)) return {};
2017-05-07 14:50:32 +02:00
2017-06-06 23:19:12 +02:00
return parseQueryParams(path.split("?")[1]);
2017-06-06 06:21:55 +02:00
});
2017-05-07 14:50:32 +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) {
2017-06-06 23:19:12 +02:00
case "settings":
case "help":
case "report":
case "wallet":
case "send":
case "receive":
case "rewards":
case "start":
case "publish":
case "help":
case "developer":
return __(page.charAt(0).toUpperCase() + page.slice(1));
case "search":
return params.query
? __("Search results for %s", params.query)
: __("Search");
case "show":
return lbryuri.normalize(params.uri);
case "downloaded":
return __("Downloads & Purchases");
case "published":
return __("Publishes");
case "discover":
return __("Home");
2017-06-03 01:09:52 +02:00
case 'account-verification':
return __('Early Access Verification')
default:
2017-06-06 23:19:12 +02:00
return "";
2017-05-04 05:44:08 +02:00
}
}
2017-06-06 06:21:55 +02:00
);
2017-05-04 05:44:08 +02:00
2017-04-07 07:15:22 +02:00
export const selectPlatform = createSelector(
_selectState,
2017-06-06 23:19:12 +02:00
state => state.platform
2017-06-06 06:21:55 +02:00
);
export const selectUpdateUrl = createSelector(selectPlatform, platform => {
2017-06-06 23:19:12 +02:00
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";
2017-04-07 07:15:22 +02:00
}
2017-06-06 06:21:55 +02:00
});
2017-04-07 07:15:22 +02:00
2017-06-06 06:21:55 +02:00
export const selectVersion = createSelector(_selectState, state => {
2017-06-06 23:19:12 +02:00
return state.version;
2017-06-06 06:21:55 +02:00
});
2017-04-07 07:15:22 +02:00
export const selectUpgradeFilename = createSelector(
selectPlatform,
selectVersion,
(platform, version) => {
switch (platform) {
2017-06-06 23:19:12 +02:00
case "darwin":
return `LBRY_${version}.dmg`;
2017-06-06 23:19:12 +02:00
case "linux":
2017-04-07 07:15:22 +02:00
return `LBRY_${version}_amd64.deb`;
2017-06-06 23:19:12 +02:00
case "win32":
return `LBRY_${version}.exe`;
2017-04-07 07:15:22 +02:00
default:
2017-06-06 23:19:12 +02:00
throw "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 selectCurrentModal = createSelector(
_selectState,
2017-06-06 23:19:12 +02:00
state => state.modal
2017-06-06 06:21:55 +02:00
);
2017-04-07 07:15:22 +02:00
export const selectDownloadProgress = createSelector(
_selectState,
2017-06-06 23:19:12 +02:00
state => state.downloadProgress
2017-06-06 06:21:55 +02:00
);
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 selectHeaderLinks = createSelector(selectCurrentPage, page => {
2017-06-06 23:19:12 +02:00
switch (page) {
case "wallet":
case "send":
case "receive":
case "rewards":
return {
wallet: __("Overview"),
send: __("Send"),
receive: __("Receive"),
rewards: __("Rewards"),
};
case "downloaded":
case "published":
return {
downloaded: __("Downloaded"),
published: __("Published"),
};
case "settings":
case "help":
return {
settings: __("Settings"),
help: __("Help"),
};
default:
return null;
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 selectUpgradeSkipped = createSelector(
_selectState,
2017-06-06 23:19:12 +02:00
state => state.upgradeSkipped
2017-06-06 06:21:55 +02:00
);
2017-04-07 07:15:22 +02:00
export const selectUpgradeDownloadPath = createSelector(
2017-04-07 07:15:22 +02:00
_selectState,
2017-06-06 23:19:12 +02:00
state => state.downloadPath
2017-06-06 06:21:55 +02:00
);
2017-04-07 07:15:22 +02:00
export const selectUpgradeDownloadItem = createSelector(
_selectState,
2017-06-06 23:19:12 +02:00
state => state.downloadItem
2017-06-06 06:21:55 +02:00
);
2017-04-07 07:15:22 +02:00
2017-05-24 23:53:03 +02:00
export const selectModalExtraContent = createSelector(
2017-04-07 07:15:22 +02:00
_selectState,
2017-06-06 23:19:12 +02:00
state => state.modalExtraContent
2017-06-06 06:21:55 +02:00
);
2017-04-22 15:17:01 +02:00
export const selectDaemonReady = createSelector(
_selectState,
2017-06-06 23:19:12 +02:00
state => state.daemonReady
2017-06-06 06:21:55 +02:00
);
export const selectObscureNsfw = createSelector(
_selectState,
2017-06-06 23:19:12 +02:00
state => !!state.obscureNsfw
2017-06-06 06:21:55 +02:00
);
2017-05-23 09:21:21 +02:00
export const selectSnackBar = createSelector(
_selectState,
2017-06-06 23:19:12 +02:00
state => state.snackBar || {}
2017-06-06 06:21:55 +02:00
);
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
);