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

50 lines
1.1 KiB
JavaScript
Raw Normal View History

2017-04-24 16:17:36 +02:00
import { createSelector } from 'reselect'
2017-05-07 14:50:32 +02:00
import {
selectCurrentParams,
selectDaemonReady,
selectSearchQuery,
} from 'selectors/app'
2017-04-24 16:17:36 +02:00
export const _selectState = state => state.search || {}
export const selectIsSearching = createSelector(
_selectState,
(state) => !!state.searching
)
export const selectSearchResults = createSelector(
_selectState,
(state) => state.results || {}
)
export const selectSearchResultsByQuery = createSelector(
selectSearchResults,
(results) => results.byQuery || {}
)
export const selectCurrentSearchResults = createSelector(
selectSearchQuery,
selectSearchResultsByQuery,
(query, byQuery) => byQuery[query] || []
)
export const selectSearchActivated = createSelector(
_selectState,
(state) => !!state.activated
)
2017-05-07 14:50:32 +02:00
export const shouldSearch = createSelector(
selectDaemonReady,
selectSearchQuery,
selectIsSearching,
selectSearchResultsByQuery,
(daemonReady, query, isSearching, resultsByQuery) => {
if (!daemonReady) return false
if (!query) return false
if (isSearching) return false
if (Object.keys(resultsByQuery).indexOf(query) != -1) return false
return true
}
)