Fix navigating back through search results

This commit is contained in:
6ea86b96 2017-05-23 12:46:52 +04:00
parent 1b9d23279c
commit 27b9d844b7
No known key found for this signature in database
GPG key ID: B282D183E4931E8F
6 changed files with 50 additions and 29 deletions

View file

@ -6,7 +6,12 @@ import {
selectUpgradeDownloadItem,
selectUpgradeFilename,
selectPageTitle,
selectCurrentPage,
selectCurrentParams,
} from 'selectors/app'
import {
doSearch,
} from 'actions/search'
const {remote, ipcRenderer, shell} = require('electron');
const path = require('path');
@ -47,6 +52,12 @@ export function doChangePath(path) {
const state = getState()
const pageTitle = selectPageTitle(state)
window.document.title = pageTitle
const currentPage = selectCurrentPage(state)
if (currentPage === 'search') {
const params = selectCurrentParams(state)
dispatch(doSearch(params.query))
}
}
}

View file

@ -31,9 +31,6 @@ export function doSearch(query) {
if(page != 'search') {
dispatch(doNavigate('search', { query: query }))
} else {
dispatch(doHistoryPush({ query }, "Search for " + query, '/search'))
}
lighthouse.search(query).then(results => {
results.forEach(result => {
const uri = lbryuri.build({
@ -53,4 +50,5 @@ export function doSearch(query) {
})
})
}
}
}

View file

@ -7,9 +7,6 @@ import {
selectWunderBarAddress,
selectWunderBarIcon
} from 'selectors/search'
import {
doSearch,
} from 'actions/search'
import {
doNavigate,
} from 'actions/app'
@ -21,7 +18,7 @@ const select = (state) => ({
})
const perform = (dispatch) => ({
onSearch: (query) => dispatch(doSearch(query)),
onSearch: (query) => dispatch(doNavigate('/search', { query, })),
onSubmit: (query) => dispatch(doNavigate('/show', { uri: lbryuri.normalize(query) } ))
})

View file

@ -22,7 +22,9 @@ import {
import {
doFileList
} from 'actions/file_info'
import parseQueryParams from 'util/query_params'
import {
toQueryString,
} from 'util/query_params'
const {remote, ipcRenderer, shell} = require('electron');
const contextMenu = remote.require('./menu/context-menu');
@ -37,15 +39,16 @@ window.addEventListener('contextmenu', (event) => {
});
window.addEventListener('popstate', (event, param) => {
const queryString = document.location.search
const params = event.state
const pathParts = document.location.pathname.split('/')
const route = '/' + pathParts[pathParts.length - 1]
const queryString = toQueryString(params)
let action
if (route.match(/html$/)) {
action = doChangePath('/discover')
} else {
action = doChangePath(`${route}${queryString}`)
action = doChangePath(`${route}?${queryString}`)
}
app.store.dispatch(action)

View file

@ -1,5 +1,7 @@
import {createSelector} from 'reselect'
import parseQueryParams from 'util/query_params'
import {
parseQueryParams,
} from 'util/query_params'
import lbryuri from 'lbryuri'
export const _selectState = state => state.app || {}
@ -37,7 +39,7 @@ export const selectPageTitle = createSelector(
(page, params) => {
switch (page) {
case 'search':
return 'Search'
return params.query ? `Search results for ${params.query}` : 'Search'
case 'settings':
return 'Settings'
case 'help':

View file

@ -1,4 +1,4 @@
function parseQueryParams(queryString) {
export function parseQueryParams(queryString) {
if (queryString === '') return {};
const parts = queryString
.split('?')
@ -13,4 +13,14 @@ function parseQueryParams(queryString) {
return params;
}
export default parseQueryParams
export function toQueryString(params) {
if (!params) return ""
const parts = []
for (const key in params) {
if (params.hasOwnProperty(key) && params[key]) {
parts.push(encodeURIComponent(key) + "=" + encodeURIComponent(params[key]))
}
}
return parts.join("&")
}