2017-06-06 23:19:12 +02:00
|
|
|
import { createSelector } from "reselect";
|
2017-09-17 03:50:44 +02:00
|
|
|
import {
|
|
|
|
selectPageTitle,
|
|
|
|
selectCurrentPage,
|
|
|
|
selectCurrentParams,
|
|
|
|
} from "selectors/navigation";
|
2017-04-24 16:17:36 +02:00
|
|
|
|
2017-06-06 06:21:55 +02:00
|
|
|
export const _selectState = state => state.search || {};
|
2017-04-24 16:17:36 +02:00
|
|
|
|
2017-05-11 02:59:47 +02:00
|
|
|
export const selectSearchQuery = createSelector(
|
2017-09-17 20:26:55 +02:00
|
|
|
selectCurrentPage,
|
|
|
|
selectCurrentParams,
|
|
|
|
(page, params) => (page === "search" ? params && params.query : null)
|
2017-06-06 06:21:55 +02:00
|
|
|
);
|
2017-05-11 02:59:47 +02:00
|
|
|
|
2017-04-24 16:17:36 +02:00
|
|
|
export const selectIsSearching = createSelector(
|
|
|
|
_selectState,
|
2017-06-06 23:19:12 +02:00
|
|
|
state => !!state.searching
|
2017-06-06 06:21:55 +02:00
|
|
|
);
|
2017-04-24 16:17:36 +02:00
|
|
|
|
2017-10-06 23:46:41 +02:00
|
|
|
export const selectSearchUrisByQuery = createSelector(
|
2017-04-24 16:17:36 +02:00
|
|
|
_selectState,
|
2017-10-06 23:46:41 +02:00
|
|
|
state => state.urisByQuery
|
2017-06-06 06:21:55 +02:00
|
|
|
);
|
2017-04-24 16:17:36 +02:00
|
|
|
|
2017-10-06 23:46:41 +02:00
|
|
|
export const makeSelectSearchUris = query => {
|
2017-10-12 15:37:24 +02:00
|
|
|
//replace statement below is kind of ugly, and repeated in doSearch action
|
|
|
|
return createSelector(
|
|
|
|
selectSearchUrisByQuery,
|
2017-10-13 15:32:49 +02:00
|
|
|
byQuery => byQuery[query ? query.replace(/^lbry:\/\//i, "") : query]
|
2017-10-12 15:37:24 +02:00
|
|
|
);
|
2017-10-06 23:46:41 +02:00
|
|
|
};
|
2017-05-07 14:50:32 +02:00
|
|
|
|
2017-05-11 02:59:47 +02:00
|
|
|
export const selectWunderBarAddress = createSelector(
|
2017-05-12 01:28:43 +02:00
|
|
|
selectCurrentPage,
|
2017-05-11 02:59:47 +02:00
|
|
|
selectPageTitle,
|
2017-05-07 14:50:32 +02:00
|
|
|
selectSearchQuery,
|
2017-06-06 23:19:12 +02:00
|
|
|
(page, title, query) => (page != "search" ? title : query ? query : title)
|
2017-06-06 06:21:55 +02:00
|
|
|
);
|
2017-05-07 14:50:32 +02:00
|
|
|
|
2017-09-17 03:50:44 +02:00
|
|
|
export const selectWunderBarIcon = createSelector(
|
|
|
|
selectCurrentPage,
|
|
|
|
selectCurrentParams,
|
|
|
|
(page, params) => {
|
|
|
|
switch (page) {
|
|
|
|
case "auth":
|
|
|
|
return "icon-user";
|
|
|
|
case "settings":
|
|
|
|
return "icon-gear";
|
|
|
|
case "help":
|
|
|
|
return "icon-question";
|
|
|
|
case "report":
|
|
|
|
return "icon-file";
|
|
|
|
case "downloaded":
|
|
|
|
return "icon-folder";
|
|
|
|
case "published":
|
|
|
|
return "icon-folder";
|
|
|
|
case "history":
|
|
|
|
return "icon-history";
|
|
|
|
case "send":
|
|
|
|
return "icon-send";
|
|
|
|
case "rewards":
|
|
|
|
return "icon-rocket";
|
|
|
|
case "invite":
|
|
|
|
return "icon-envelope-open";
|
|
|
|
case "address":
|
|
|
|
case "receive":
|
|
|
|
return "icon-address-book";
|
|
|
|
case "wallet":
|
|
|
|
case "backup":
|
|
|
|
return "icon-bank";
|
|
|
|
case "show":
|
|
|
|
return "icon-file";
|
|
|
|
case "publish":
|
|
|
|
return params.id ? __("icon-pencil") : __("icon-upload");
|
|
|
|
case "developer":
|
|
|
|
return "icon-code";
|
|
|
|
case "discover":
|
2017-09-26 08:45:49 +02:00
|
|
|
case "search":
|
|
|
|
return "icon-search";
|
2017-09-17 03:50:44 +02:00
|
|
|
default:
|
|
|
|
return "icon-file";
|
|
|
|
}
|
2017-05-07 14:50:32 +02:00
|
|
|
}
|
2017-09-17 03:50:44 +02:00
|
|
|
);
|