2017-08-30 14:48:32 +02:00
|
|
|
import { createSelector } from "reselect";
|
|
|
|
import { parseQueryParams, toQueryString } from "util/query_params";
|
|
|
|
import * as settings from "constants/settings.js";
|
|
|
|
import lbryuri from "lbryuri";
|
|
|
|
|
|
|
|
export const _selectState = state => state.navigation || {};
|
|
|
|
|
|
|
|
export const selectCurrentPath = createSelector(
|
|
|
|
_selectState,
|
|
|
|
state => state.currentPath
|
|
|
|
);
|
|
|
|
|
2017-09-17 20:26:55 +02:00
|
|
|
export const computePageFromPath = path =>
|
|
|
|
path.replace(/^\//, "").split("?")[0];
|
|
|
|
|
2017-12-13 22:36:30 +01:00
|
|
|
export const selectCurrentPage = createSelector(selectCurrentPath, path =>
|
|
|
|
computePageFromPath(path)
|
|
|
|
);
|
2017-08-30 14:48:32 +02:00
|
|
|
|
|
|
|
export const selectCurrentParams = createSelector(selectCurrentPath, path => {
|
|
|
|
if (path === undefined) return {};
|
|
|
|
if (!path.match(/\?/)) return {};
|
|
|
|
|
|
|
|
return parseQueryParams(path.split("?")[1]);
|
|
|
|
});
|
|
|
|
|
2017-12-13 22:36:30 +01:00
|
|
|
export const makeSelectCurrentParam = param =>
|
|
|
|
createSelector(
|
2017-09-07 23:18:33 +02:00
|
|
|
selectCurrentParams,
|
|
|
|
params => (params ? params[param] : undefined)
|
|
|
|
);
|
|
|
|
|
2017-08-30 14:48:32 +02:00
|
|
|
export const selectHeaderLinks = createSelector(selectCurrentPage, page => {
|
|
|
|
// This contains intentional fall throughs
|
|
|
|
switch (page) {
|
|
|
|
case "wallet":
|
2017-08-30 20:39:20 +02:00
|
|
|
case "history":
|
2017-08-30 14:48:32 +02:00
|
|
|
case "send":
|
2017-12-07 19:07:30 +01:00
|
|
|
case "getcredits":
|
2017-08-30 20:39:20 +02:00
|
|
|
case "invite":
|
2017-08-30 14:48:32 +02:00
|
|
|
case "rewards":
|
|
|
|
case "backup":
|
|
|
|
return {
|
|
|
|
wallet: __("Overview"),
|
2017-12-07 19:07:30 +01:00
|
|
|
getcredits: __("Get Credits"),
|
|
|
|
send: __("Send / Receive"),
|
2017-08-30 14:48:32 +02:00
|
|
|
rewards: __("Rewards"),
|
2017-08-30 20:39:20 +02:00
|
|
|
invite: __("Invites"),
|
2017-12-07 19:07:30 +01:00
|
|
|
history: __("History"),
|
2017-08-30 14:48:32 +02:00
|
|
|
};
|
|
|
|
case "downloaded":
|
|
|
|
case "published":
|
|
|
|
return {
|
|
|
|
downloaded: __("Downloaded"),
|
|
|
|
published: __("Published"),
|
|
|
|
};
|
|
|
|
case "settings":
|
|
|
|
case "help":
|
|
|
|
return {
|
|
|
|
settings: __("Settings"),
|
|
|
|
help: __("Help"),
|
|
|
|
};
|
2017-12-08 21:14:35 +01:00
|
|
|
case "discover":
|
|
|
|
case "subscriptions":
|
|
|
|
return {
|
2017-12-08 22:07:12 +01:00
|
|
|
discover: __("Discover"),
|
2017-12-08 21:14:35 +01:00
|
|
|
subscriptions: __("Subscriptions"),
|
|
|
|
};
|
2017-08-30 14:48:32 +02:00
|
|
|
default:
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
export const selectPageTitle = createSelector(
|
|
|
|
selectCurrentPage,
|
|
|
|
selectCurrentParams,
|
|
|
|
(page, params) => {
|
|
|
|
switch (page) {
|
|
|
|
case "settings":
|
|
|
|
return __("Settings");
|
|
|
|
case "report":
|
|
|
|
return __("Report");
|
|
|
|
case "wallet":
|
|
|
|
return __("Wallet");
|
|
|
|
case "send":
|
2017-12-07 19:07:30 +01:00
|
|
|
return __("Send or Receive LBRY Credits");
|
|
|
|
case "getcredits":
|
2017-12-01 04:51:55 +01:00
|
|
|
return __("Get LBRY Credits");
|
2017-08-30 14:48:32 +02:00
|
|
|
case "backup":
|
2017-08-30 20:39:20 +02:00
|
|
|
return __("Backup Your Wallet");
|
2017-08-30 14:48:32 +02:00
|
|
|
case "rewards":
|
|
|
|
return __("Rewards");
|
2017-08-30 20:39:20 +02:00
|
|
|
case "invite":
|
|
|
|
return __("Invites");
|
|
|
|
case "start":
|
|
|
|
return __("Start");
|
2017-08-30 14:48:32 +02:00
|
|
|
case "publish":
|
2017-09-17 03:50:44 +02:00
|
|
|
return params.id ? __("Edit") : __("Publish");
|
2017-08-30 14:48:32 +02:00
|
|
|
case "help":
|
|
|
|
return __("Help");
|
|
|
|
case "developer":
|
|
|
|
return __("Developer");
|
|
|
|
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("?");
|
|
|
|
}
|
|
|
|
case "downloaded":
|
|
|
|
return __("Downloads & Purchases");
|
|
|
|
case "published":
|
|
|
|
return __("Publishes");
|
2017-09-26 08:45:49 +02:00
|
|
|
case "search":
|
|
|
|
return params.query
|
|
|
|
? __("Search results for %s", params.query)
|
|
|
|
: __("Search");
|
2017-12-08 21:14:35 +01:00
|
|
|
case "subscriptions":
|
|
|
|
return __("Your Subscriptions");
|
2017-11-13 21:47:10 +01:00
|
|
|
case "discover":
|
2017-08-30 20:39:20 +02:00
|
|
|
case false:
|
|
|
|
case null:
|
|
|
|
case "":
|
2017-08-30 14:48:32 +02:00
|
|
|
return "";
|
2017-08-30 20:39:20 +02:00
|
|
|
default:
|
|
|
|
return page[0].toUpperCase() + (page.length > 0 ? page.substr(1) : "");
|
2017-08-30 14:48:32 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
|
|
|
export const selectPathAfterAuth = createSelector(
|
|
|
|
_selectState,
|
|
|
|
state => state.pathAfterAuth
|
|
|
|
);
|
|
|
|
|
|
|
|
export const selectIsBackDisabled = createSelector(
|
|
|
|
_selectState,
|
|
|
|
state => state.index === 0
|
|
|
|
);
|
|
|
|
|
|
|
|
export const selectIsForwardDisabled = createSelector(
|
|
|
|
_selectState,
|
|
|
|
state => state.index === state.stack.length - 1
|
|
|
|
);
|
|
|
|
|
|
|
|
export const selectHistoryIndex = createSelector(
|
|
|
|
_selectState,
|
|
|
|
state => state.index
|
|
|
|
);
|
|
|
|
|
|
|
|
export const selectHistoryStack = createSelector(
|
|
|
|
_selectState,
|
|
|
|
state => state.stack
|
|
|
|
);
|
2017-11-17 22:27:35 +01:00
|
|
|
|
|
|
|
// returns current page attributes (scrollY, path)
|
|
|
|
export const selectActiveHistoryEntry = createSelector(
|
|
|
|
_selectState,
|
|
|
|
state => state.stack[state.index]
|
|
|
|
);
|