even smarter search

This commit is contained in:
6ea86b96 2017-04-30 10:31:20 +07:00 committed by Jeremy Kauffman
parent 21818c57a8
commit 12f965f473

View file

@ -9,10 +9,18 @@ import {
import { import {
doResolveUri, doResolveUri,
} from 'actions/content' } from 'actions/content'
import {
doNavigate,
} from 'actions/app'
import {
selectCurrentPage,
} from 'selectors/app'
export function doSearchContent(query) { export function doSearchContent(query) {
return function(dispatch, getState) { return function(dispatch, getState) {
const state = getState() const state = getState()
const page = selectCurrentPage(state)
if (!query) { if (!query) {
return dispatch({ return dispatch({
@ -25,6 +33,8 @@ export function doSearchContent(query) {
data: { query } data: { query }
}) })
if(page != 'discover' && query != undefined) dispatch(doNavigate('discover'))
lighthouse.search(query).then(results => { lighthouse.search(query).then(results => {
results.forEach(result => { results.forEach(result => {
const uri = lbryuri.build({ const uri = lbryuri.build({
@ -47,8 +57,16 @@ export function doSearchContent(query) {
} }
export function doActivateSearch() { export function doActivateSearch() {
return { return function(dispatch, getState) {
type: types.ACTIVATE_SEARCH, const state = getState()
const page = selectCurrentPage(state)
const query = selectSearchQuery(state)
if(page != 'discover' && query != undefined) dispatch(doNavigate('discover'))
dispatch({
type: types.ACTIVATE_SEARCH,
})
} }
} }