2017-06-06 23:19:12 +02:00
|
|
|
import { createSelector } from "reselect";
|
2017-07-17 08:06:04 +02:00
|
|
|
import { parseQueryParams, toQueryString } from "util/query_params";
|
2017-08-18 19:09:40 +02:00
|
|
|
import * as settings from "constants/settings.js";
|
2017-06-27 20:15:37 +02:00
|
|
|
import lbry from "lbry";
|
2017-06-06 23:19:12 +02:00
|
|
|
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
|
|
|
|
2017-04-24 09:25:27 +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-04-24 09:25:27 +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-04-24 09:25:27 +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
|
|
|
|
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) {
|
2017-06-06 23:19:12 +02:00
|
|
|
case "settings":
|
2017-06-22 01:15:24 +02:00
|
|
|
return __("Settings");
|
2017-06-06 23:19:12 +02:00
|
|
|
case "report":
|
2017-06-22 01:15:24 +02:00
|
|
|
return __("Report");
|
2017-06-06 23:19:12 +02:00
|
|
|
case "wallet":
|
2017-06-22 01:15:24 +02:00
|
|
|
return __("Wallet");
|
2017-06-06 23:19:12 +02:00
|
|
|
case "send":
|
2017-06-22 01:15:24 +02:00
|
|
|
return __("Send");
|
2017-06-06 23:19:12 +02:00
|
|
|
case "receive":
|
2017-06-22 01:15:24 +02:00
|
|
|
return __("Receive");
|
2017-08-09 21:12:02 +02:00
|
|
|
case "backup":
|
|
|
|
return __("Backup");
|
2017-06-06 23:19:12 +02:00
|
|
|
case "rewards":
|
2017-06-22 01:15:24 +02:00
|
|
|
return __("Rewards");
|
2017-06-06 23:19:12 +02:00
|
|
|
case "start":
|
2017-06-22 01:15:24 +02:00
|
|
|
return __("Start");
|
2017-06-06 23:19:12 +02:00
|
|
|
case "publish":
|
2017-06-22 01:15:24 +02:00
|
|
|
return __("Publish");
|
2017-06-06 23:19:12 +02:00
|
|
|
case "help":
|
2017-06-22 01:15:24 +02:00
|
|
|
return __("Help");
|
2017-06-06 23:19:12 +02:00
|
|
|
case "developer":
|
2017-06-22 01:15:24 +02:00
|
|
|
return __("Developer");
|
2017-06-06 23:19:12 +02:00
|
|
|
case "search":
|
|
|
|
return params.query
|
|
|
|
? __("Search results for %s", params.query)
|
|
|
|
: __("Search");
|
2017-07-17 08:06:04 +02:00
|
|
|
case "show": {
|
|
|
|
const parts = [lbryuri.normalize(params.uri)];
|
|
|
|
// If the params has any keys other than "uri"
|
|
|
|
if (Object.keys(params).length > 1) {
|
|
|
|
parts.push(toQueryString(Object.assign({}, params, { uri: null })));
|
|
|
|
}
|
|
|
|
return parts.join("?");
|
|
|
|
}
|
2017-06-06 23:19:12 +02:00
|
|
|
case "downloaded":
|
|
|
|
return __("Downloads & Purchases");
|
|
|
|
case "published":
|
|
|
|
return __("Publishes");
|
|
|
|
case "discover":
|
|
|
|
return __("Home");
|
2017-04-30 18:01:43 +02:00
|
|
|
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":
|
2017-06-01 08:52:17 +02:00
|
|
|
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":
|
2017-06-01 08:52:17 +02:00
|
|
|
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-08-09 21:12:02 +02:00
|
|
|
// This contains intentional fall throughs
|
2017-06-06 23:19:12 +02:00
|
|
|
switch (page) {
|
|
|
|
case "wallet":
|
|
|
|
case "send":
|
|
|
|
case "receive":
|
|
|
|
case "rewards":
|
2017-08-09 21:12:02 +02:00
|
|
|
case "backup":
|
2017-06-06 23:19:12 +02:00
|
|
|
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
|
|
|
|
2017-06-01 08:51:16 +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
|
|
|
);
|
2017-04-29 11:50:29 +02:00
|
|
|
|
2017-07-19 23:05:08 +02:00
|
|
|
export const selectDaemonVersionMatched = createSelector(
|
|
|
|
_selectState,
|
|
|
|
state => state.daemonVersionMatched
|
|
|
|
);
|
|
|
|
|
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
|
|
|
);
|
2017-06-24 10:57:37 +02:00
|
|
|
|
2017-08-18 19:09:40 +02:00
|
|
|
export const selectCreditsIntroAcknowledged = createSelector(
|
|
|
|
_selectState,
|
|
|
|
state => lbry.getClientSetting(settings.CREDIT_INTRO_ACKNOWLEDGED)
|
|
|
|
);
|
|
|
|
|
2017-07-15 20:44:50 +02:00
|
|
|
export const selectWelcomeModalAcknowledged = createSelector(
|
|
|
|
_selectState,
|
2017-08-18 19:09:40 +02:00
|
|
|
state => lbry.getClientSetting(settings.FIRST_RUN_ACKNOWLEDGED)
|
2017-07-15 20:44:50 +02:00
|
|
|
);
|
|
|
|
|
2017-06-24 10:57:37 +02:00
|
|
|
export const selectBadgeNumber = createSelector(
|
|
|
|
_selectState,
|
|
|
|
state => state.badgeNumber
|
|
|
|
);
|
2017-07-07 15:15:45 +02:00
|
|
|
|
|
|
|
export const selectCurrentLanguage = createSelector(
|
|
|
|
_selectState,
|
2017-08-19 20:03:51 +02:00
|
|
|
() => app.i18n.getLocale() || "en"
|
2017-08-08 11:36:14 +02:00
|
|
|
);
|
|
|
|
|
2017-07-19 17:09:40 +02:00
|
|
|
export const selectPathAfterAuth = createSelector(
|
|
|
|
_selectState,
|
|
|
|
state => state.pathAfterAuth
|
2017-07-07 15:26:03 +02:00
|
|
|
);
|
2017-08-16 01:29:55 +02:00
|
|
|
|
|
|
|
export const selectIsBackDisabled = createSelector(
|
|
|
|
_selectState,
|
|
|
|
state => state.isBackDisabled
|
|
|
|
);
|
|
|
|
|
|
|
|
export const selectIsForwardDisabled = createSelector(
|
|
|
|
_selectState,
|
|
|
|
state => state.isForwardDisabled
|
|
|
|
);
|
2017-08-16 23:24:04 +02:00
|
|
|
|
|
|
|
export const selectHistoryBack = createSelector(_selectState, state => {
|
|
|
|
const { history } = state;
|
|
|
|
const index = history.index - 1;
|
|
|
|
|
|
|
|
// Check if page exists
|
|
|
|
if (index > -1) {
|
|
|
|
// Get back history
|
|
|
|
return history.stack[index];
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
export const selectHistoryForward = createSelector(_selectState, state => {
|
|
|
|
const { history } = state;
|
|
|
|
const index = history.index + 1;
|
|
|
|
|
|
|
|
// Check if page exists
|
|
|
|
if (index <= history.stack.length) {
|
|
|
|
// Get forward history
|
|
|
|
return history.stack[index];
|
|
|
|
}
|
|
|
|
});
|