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

86 lines
2.1 KiB
JavaScript
Raw Normal View History

2017-06-06 23:19:12 +02:00
import { createSelector } from "reselect";
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
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-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
export const selectSearchUrisByQuery = createSelector(
2017-04-24 16:17:36 +02:00
_selectState,
state => state.urisByQuery
2017-06-06 06:21:55 +02:00
);
2017-04-24 16:17:36 +02:00
export const makeSelectSearchUris = query => {
//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-05-07 14:50:32 +02:00
export const selectWunderBarAddress = createSelector(
2017-05-12 01:28:43 +02:00
selectCurrentPage,
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
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":
case "search":
return "icon-search";
default:
return "icon-file";
}
2017-05-07 14:50:32 +02:00
}
);