mirror of
https://github.com/LBRYFoundation/lbry-desktop.git
synced 2025-09-08 03:29:46 +00:00
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,
|
selectUpgradeDownloadItem,
|
||||||
selectUpgradeFilename,
|
selectUpgradeFilename,
|
||||||
selectPageTitle,
|
selectPageTitle,
|
||||||
|
selectCurrentPage,
|
||||||
|
selectCurrentParams,
|
||||||
} from 'selectors/app'
|
} from 'selectors/app'
|
||||||
|
import {
|
||||||
|
doSearch,
|
||||||
|
} from 'actions/search'
|
||||||
|
|
||||||
const {remote, ipcRenderer, shell} = require('electron');
|
const {remote, ipcRenderer, shell} = require('electron');
|
||||||
const path = require('path');
|
const path = require('path');
|
||||||
|
@ -47,6 +52,12 @@ export function doChangePath(path) {
|
||||||
const state = getState()
|
const state = getState()
|
||||||
const pageTitle = selectPageTitle(state)
|
const pageTitle = selectPageTitle(state)
|
||||||
window.document.title = pageTitle
|
window.document.title = pageTitle
|
||||||
|
|
||||||
|
const currentPage = selectCurrentPage(state)
|
||||||
|
if (currentPage === 'search') {
|
||||||
|
const params = selectCurrentParams(state)
|
||||||
|
dispatch(doSearch(params.query))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -31,26 +31,24 @@ export function doSearch(query) {
|
||||||
if(page != 'search') {
|
if(page != 'search') {
|
||||||
dispatch(doNavigate('search', { query: query }))
|
dispatch(doNavigate('search', { query: query }))
|
||||||
} else {
|
} else {
|
||||||
dispatch(doHistoryPush({ query }, "Search for " + query, '/search'))
|
lighthouse.search(query).then(results => {
|
||||||
}
|
results.forEach(result => {
|
||||||
|
const uri = lbryuri.build({
|
||||||
lighthouse.search(query).then(results => {
|
channelName: result.channel_name,
|
||||||
results.forEach(result => {
|
contentName: result.name,
|
||||||
const uri = lbryuri.build({
|
claimId: result.channel_id || result.claim_id,
|
||||||
channelName: result.channel_name,
|
})
|
||||||
contentName: result.name,
|
dispatch(doResolveUri(uri))
|
||||||
claimId: result.channel_id || result.claim_id,
|
|
||||||
})
|
})
|
||||||
dispatch(doResolveUri(uri))
|
|
||||||
})
|
|
||||||
|
|
||||||
dispatch({
|
dispatch({
|
||||||
type: types.SEARCH_COMPLETED,
|
type: types.SEARCH_COMPLETED,
|
||||||
data: {
|
data: {
|
||||||
query,
|
query,
|
||||||
results,
|
results,
|
||||||
}
|
}
|
||||||
|
})
|
||||||
})
|
})
|
||||||
})
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,9 +7,6 @@ import {
|
||||||
selectWunderBarAddress,
|
selectWunderBarAddress,
|
||||||
selectWunderBarIcon
|
selectWunderBarIcon
|
||||||
} from 'selectors/search'
|
} from 'selectors/search'
|
||||||
import {
|
|
||||||
doSearch,
|
|
||||||
} from 'actions/search'
|
|
||||||
import {
|
import {
|
||||||
doNavigate,
|
doNavigate,
|
||||||
} from 'actions/app'
|
} from 'actions/app'
|
||||||
|
@ -21,7 +18,7 @@ const select = (state) => ({
|
||||||
})
|
})
|
||||||
|
|
||||||
const perform = (dispatch) => ({
|
const perform = (dispatch) => ({
|
||||||
onSearch: (query) => dispatch(doSearch(query)),
|
onSearch: (query) => dispatch(doNavigate('/search', { query, })),
|
||||||
onSubmit: (query) => dispatch(doNavigate('/show', { uri: lbryuri.normalize(query) } ))
|
onSubmit: (query) => dispatch(doNavigate('/show', { uri: lbryuri.normalize(query) } ))
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
|
@ -22,7 +22,9 @@ import {
|
||||||
import {
|
import {
|
||||||
doFileList
|
doFileList
|
||||||
} from 'actions/file_info'
|
} from 'actions/file_info'
|
||||||
import parseQueryParams from 'util/query_params'
|
import {
|
||||||
|
toQueryString,
|
||||||
|
} from 'util/query_params'
|
||||||
|
|
||||||
const {remote, ipcRenderer, shell} = require('electron');
|
const {remote, ipcRenderer, shell} = require('electron');
|
||||||
const contextMenu = remote.require('./menu/context-menu');
|
const contextMenu = remote.require('./menu/context-menu');
|
||||||
|
@ -37,15 +39,16 @@ window.addEventListener('contextmenu', (event) => {
|
||||||
});
|
});
|
||||||
|
|
||||||
window.addEventListener('popstate', (event, param) => {
|
window.addEventListener('popstate', (event, param) => {
|
||||||
const queryString = document.location.search
|
const params = event.state
|
||||||
const pathParts = document.location.pathname.split('/')
|
const pathParts = document.location.pathname.split('/')
|
||||||
const route = '/' + pathParts[pathParts.length - 1]
|
const route = '/' + pathParts[pathParts.length - 1]
|
||||||
|
const queryString = toQueryString(params)
|
||||||
|
|
||||||
let action
|
let action
|
||||||
if (route.match(/html$/)) {
|
if (route.match(/html$/)) {
|
||||||
action = doChangePath('/discover')
|
action = doChangePath('/discover')
|
||||||
} else {
|
} else {
|
||||||
action = doChangePath(`${route}${queryString}`)
|
action = doChangePath(`${route}?${queryString}`)
|
||||||
}
|
}
|
||||||
|
|
||||||
app.store.dispatch(action)
|
app.store.dispatch(action)
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
import {createSelector} from 'reselect'
|
import {createSelector} from 'reselect'
|
||||||
import parseQueryParams from 'util/query_params'
|
import {
|
||||||
|
parseQueryParams,
|
||||||
|
} from 'util/query_params'
|
||||||
import lbryuri from 'lbryuri'
|
import lbryuri from 'lbryuri'
|
||||||
|
|
||||||
export const _selectState = state => state.app || {}
|
export const _selectState = state => state.app || {}
|
||||||
|
@ -37,7 +39,7 @@ export const selectPageTitle = createSelector(
|
||||||
(page, params) => {
|
(page, params) => {
|
||||||
switch (page) {
|
switch (page) {
|
||||||
case 'search':
|
case 'search':
|
||||||
return 'Search'
|
return params.query ? `Search results for ${params.query}` : 'Search'
|
||||||
case 'settings':
|
case 'settings':
|
||||||
return 'Settings'
|
return 'Settings'
|
||||||
case 'help':
|
case 'help':
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
function parseQueryParams(queryString) {
|
export function parseQueryParams(queryString) {
|
||||||
if (queryString === '') return {};
|
if (queryString === '') return {};
|
||||||
const parts = queryString
|
const parts = queryString
|
||||||
.split('?')
|
.split('?')
|
||||||
|
@ -13,4 +13,14 @@ function parseQueryParams(queryString) {
|
||||||
return params;
|
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…
Add table
Reference in a new issue