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

73 lines
1.7 KiB
JavaScript
Raw Normal View History

2017-06-06 23:19:12 +02:00
import { createSelector } from "reselect";
import { selectPageTitle, selectCurrentPage } from "selectors/app";
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-05-12 01:28:43 +02:00
_selectState,
2017-06-06 23:19:12 +02:00
state => state.query
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 selectSearchResults = createSelector(
_selectState,
2017-06-06 23:19:12 +02:00
state => state.results || {}
2017-06-06 06:21:55 +02:00
);
2017-04-24 16:17:36 +02:00
export const selectSearchResultsByQuery = createSelector(
selectSearchResults,
2017-06-06 23:19:12 +02:00
results => results.byQuery || {}
2017-06-06 06:21:55 +02:00
);
2017-04-24 16:17:36 +02:00
export const selectCurrentSearchResults = createSelector(
selectSearchQuery,
selectSearchResultsByQuery,
(query, byQuery) => byQuery[query]
2017-06-06 06:21:55 +02:00
);
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
2017-06-06 06:21:55 +02:00
export const selectWunderBarIcon = createSelector(selectCurrentPage, page => {
2017-06-06 23:19:12 +02:00
switch (page) {
case "search":
return "icon-search";
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 "start":
return "icon-file";
case "rewards":
return "icon-bank";
case "wallet":
case "send":
case "receive":
return "icon-bank";
case "show":
return "icon-file";
case "publish":
return "icon-upload";
case "developer":
return "icon-file";
case "developer":
return "icon-code";
case "discover":
return "icon-home";
2017-05-07 14:50:32 +02:00
}
2017-06-06 06:21:55 +02:00
});