Fix navigating back through search results
This commit is contained in:
parent
1b9d23279c
commit
27b9d844b7
6 changed files with 50 additions and 29 deletions
|
@ -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))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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) {
|
|||
})
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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) } ))
|
||||
})
|
||||
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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':
|
||||
|
|
|
@ -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("&")
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue