mirror of
https://github.com/LBRYFoundation/lbry-desktop.git
synced 2025-08-27 07:23:31 +00:00
Back button working properly
This commit is contained in:
parent
fcea4cb305
commit
d2c97d3460
15 changed files with 76 additions and 57 deletions
|
@ -15,27 +15,43 @@ const app = require('electron').remote.app;
|
||||||
const {download} = remote.require('electron-dl');
|
const {download} = remote.require('electron-dl');
|
||||||
const fs = remote.require('fs');
|
const fs = remote.require('fs');
|
||||||
|
|
||||||
export function doNavigate(path) {
|
const queryStringFromParams = (params) => {
|
||||||
|
return Object
|
||||||
|
.keys(params)
|
||||||
|
.map(key => `${key}=${params[key]}`)
|
||||||
|
.join('&')
|
||||||
|
}
|
||||||
|
|
||||||
|
export function doNavigate(path, params) {
|
||||||
return function(dispatch, getState) {
|
return function(dispatch, getState) {
|
||||||
const state = getState()
|
const state = getState()
|
||||||
const previousPath = selectCurrentPath(state)
|
|
||||||
const previousTitle = selectPageTitle(state)
|
|
||||||
history.pushState({}, previousTitle, previousPath);
|
|
||||||
|
|
||||||
dispatch(doChangePath(path))
|
|
||||||
|
|
||||||
const pageTitle = selectPageTitle(state)
|
const pageTitle = selectPageTitle(state)
|
||||||
|
let url = path
|
||||||
|
if (params)
|
||||||
|
url = `${url}?${queryStringFromParams(params)}`
|
||||||
|
|
||||||
|
history.pushState(params, pageTitle, url)
|
||||||
|
|
||||||
window.document.title = pageTitle
|
window.document.title = pageTitle
|
||||||
|
|
||||||
|
dispatch(doChangePath(url))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export function doChangePath(path) {
|
export function doChangePath(path) {
|
||||||
return {
|
return function(dispatch, getState) {
|
||||||
|
dispatch({
|
||||||
type: types.CHANGE_PATH,
|
type: types.CHANGE_PATH,
|
||||||
data: {
|
data: {
|
||||||
path,
|
path,
|
||||||
}
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export function doHistoryBack() {
|
||||||
|
return function(dispatch, getState) {
|
||||||
|
history.back()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -57,16 +73,6 @@ export function doCloseModal() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export function doHistoryBack() {
|
|
||||||
return function(dispatch, getState) {
|
|
||||||
if (window.history.length > 1) {
|
|
||||||
window.history.back();
|
|
||||||
} else {
|
|
||||||
dispatch(doNavigate('discover'))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export function doUpdateDownloadProgress(percent) {
|
export function doUpdateDownloadProgress(percent) {
|
||||||
return {
|
return {
|
||||||
type: types.UPGRADE_DOWNLOAD_PROGRESSED,
|
type: types.UPGRADE_DOWNLOAD_PROGRESSED,
|
||||||
|
|
|
@ -44,7 +44,7 @@ const makeSelect = () => {
|
||||||
}
|
}
|
||||||
|
|
||||||
const perform = (dispatch) => ({
|
const perform = (dispatch) => ({
|
||||||
navigate: (path) => dispatch(doNavigate(path)),
|
navigate: (path, params) => dispatch(doNavigate(path, params)),
|
||||||
})
|
})
|
||||||
|
|
||||||
export default connect(makeSelect, perform)(FileCardStream)
|
export default connect(makeSelect, perform)(FileCardStream)
|
||||||
|
|
|
@ -67,7 +67,7 @@ class FileCardStream extends React.Component {
|
||||||
const isConfirmed = !!metadata;
|
const isConfirmed = !!metadata;
|
||||||
const title = isConfirmed ? metadata.title : uri;
|
const title = isConfirmed ? metadata.title : uri;
|
||||||
const obscureNsfw = this.props.obscureNsfw && isConfirmed && metadata.nsfw;
|
const obscureNsfw = this.props.obscureNsfw && isConfirmed && metadata.nsfw;
|
||||||
const primaryUrl = 'show=' + uri;
|
const primaryUrl = '/show?uri=' + uri;
|
||||||
let description = ""
|
let description = ""
|
||||||
if (isConfirmed) {
|
if (isConfirmed) {
|
||||||
description = metadata.description
|
description = metadata.description
|
||||||
|
@ -80,7 +80,7 @@ class FileCardStream extends React.Component {
|
||||||
return (
|
return (
|
||||||
<section className={ 'card card--small card--link ' + (obscureNsfw ? 'card--obscured ' : '') } onMouseEnter={this.handleMouseOver.bind(this)} onMouseLeave={this.handleMouseOut.bind(this)}>
|
<section className={ 'card card--small card--link ' + (obscureNsfw ? 'card--obscured ' : '') } onMouseEnter={this.handleMouseOver.bind(this)} onMouseLeave={this.handleMouseOut.bind(this)}>
|
||||||
<div className="card__inner">
|
<div className="card__inner">
|
||||||
<a href="#" onClick={() => navigate(primaryUrl)} className="card__link">
|
<Link onClick={() => navigate('/show', { uri })} className="card__link">
|
||||||
<div className="card__title-identity">
|
<div className="card__title-identity">
|
||||||
<h5 title={title}><TruncatedText lines={1}>{title}</TruncatedText></h5>
|
<h5 title={title}><TruncatedText lines={1}>{title}</TruncatedText></h5>
|
||||||
<div className="card__subtitle">
|
<div className="card__subtitle">
|
||||||
|
@ -94,12 +94,12 @@ class FileCardStream extends React.Component {
|
||||||
<div className="card__content card__subtext card__subtext--two-lines">
|
<div className="card__content card__subtext card__subtext--two-lines">
|
||||||
<TruncatedText lines={2}>{description}</TruncatedText>
|
<TruncatedText lines={2}>{description}</TruncatedText>
|
||||||
</div>
|
</div>
|
||||||
</a>
|
</Link>
|
||||||
{this.state.showNsfwHelp && this.state.hovered
|
{this.state.showNsfwHelp && this.state.hovered
|
||||||
? <div className='card-overlay'>
|
? <div className='card-overlay'>
|
||||||
<p>
|
<p>
|
||||||
This content is Not Safe For Work.
|
This content is Not Safe For Work.
|
||||||
To view adult content, please change your <Link className="button-text" href="?settings" label="Settings" />.
|
To view adult content, please change your <Link className="button-text" onClick={() => navigate('settings')} label="Settings" />.
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
: null}
|
: null}
|
||||||
|
|
|
@ -49,7 +49,7 @@ const makeSelect = () => {
|
||||||
}
|
}
|
||||||
|
|
||||||
const perform = (dispatch) => ({
|
const perform = (dispatch) => ({
|
||||||
navigate: (path) => dispatch(doNavigate(path))
|
navigate: (path, params) => dispatch(doNavigate(path, params))
|
||||||
})
|
})
|
||||||
|
|
||||||
export default connect(makeSelect, perform)(FileTileStream)
|
export default connect(makeSelect, perform)(FileTileStream)
|
||||||
|
|
|
@ -86,26 +86,26 @@ class FileTileStream extends React.Component {
|
||||||
<section className={ 'file-tile card ' + (obscureNsfw ? 'card--obscured ' : '') } onMouseEnter={this.handleMouseOver.bind(this)} onMouseLeave={this.handleMouseOut.bind(this)}>
|
<section className={ 'file-tile card ' + (obscureNsfw ? 'card--obscured ' : '') } onMouseEnter={this.handleMouseOver.bind(this)} onMouseLeave={this.handleMouseOut.bind(this)}>
|
||||||
<div className={"row-fluid card__inner file-tile__row"}>
|
<div className={"row-fluid card__inner file-tile__row"}>
|
||||||
<div className="span3 file-tile__thumbnail-container">
|
<div className="span3 file-tile__thumbnail-container">
|
||||||
<a href="#" onClick={() => navigate(`show=${uri}`)}>
|
<Link onClick={() => navigate('/show', { uri })}>
|
||||||
{metadata && metadata.thumbnail ?
|
{metadata && metadata.thumbnail ?
|
||||||
<Thumbnail key={this.props.uri} className="file-tile__thumbnail" src={metadata.thumbnail} alt={'Photo for ' + this.props.uri} />
|
<Thumbnail key={this.props.uri} className="file-tile__thumbnail" src={metadata.thumbnail} alt={'Photo for ' + this.props.uri} />
|
||||||
:
|
:
|
||||||
<Thumbnail className="file-tile__thumbnail" alt={'Photo for ' + this.props.uri} />
|
<Thumbnail className="file-tile__thumbnail" alt={'Photo for ' + this.props.uri} />
|
||||||
}
|
}
|
||||||
</a>
|
</Link>
|
||||||
</div>
|
</div>
|
||||||
<div className="span9">
|
<div className="span9">
|
||||||
<div className="card__title-primary">
|
<div className="card__title-primary">
|
||||||
{ !this.props.hidePrice
|
{ !this.props.hidePrice
|
||||||
? <FilePrice uri={this.props.uri} />
|
? <FilePrice uri={this.props.uri} />
|
||||||
: null}
|
: null}
|
||||||
<div className="meta"><a href="#" onClick={() => navigate(`show=${uri}`)}>{uri}</a></div>
|
<div className="meta"><Link onClick={() => navigate('/show', { uri })}>{uri}</Link></div>
|
||||||
<h3>
|
<h3>
|
||||||
<a href="#" onClick={() => navigate(`show=${uri}`)} title={title}>
|
<Link onClick={() => navigate('/show', { uri })} title={title}>
|
||||||
<TruncatedText lines={1}>
|
<TruncatedText lines={1}>
|
||||||
{title}
|
{title}
|
||||||
</TruncatedText>
|
</TruncatedText>
|
||||||
</a>
|
</Link>
|
||||||
</h3>
|
</h3>
|
||||||
</div>
|
</div>
|
||||||
<div className="card__actions">
|
<div className="card__actions">
|
||||||
|
@ -121,7 +121,7 @@ class FileTileStream extends React.Component {
|
||||||
? <div className='card-overlay'>
|
? <div className='card-overlay'>
|
||||||
<p>
|
<p>
|
||||||
This content is Not Safe For Work.
|
This content is Not Safe For Work.
|
||||||
To view adult content, please change your <Link className="button-text" href="#" onClick={() => navigate('settings')} label="Settings" />.
|
To view adult content, please change your <Link className="button-text" onClick={() => navigate('/settings')} label="Settings" />.
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
: null}
|
: null}
|
||||||
|
|
|
@ -14,22 +14,22 @@ export const Header = (props) => {
|
||||||
<Link onClick={back} button="alt button--flat" icon="icon-arrow-left" />
|
<Link onClick={back} button="alt button--flat" icon="icon-arrow-left" />
|
||||||
</div>
|
</div>
|
||||||
<div className="header__item">
|
<div className="header__item">
|
||||||
<Link onClick={() => navigate('discover')} button="alt button--flat" icon="icon-home" />
|
<Link onClick={() => navigate('/discover')} button="alt button--flat" icon="icon-home" />
|
||||||
</div>
|
</div>
|
||||||
<div className="header__item header__item--wunderbar">
|
<div className="header__item header__item--wunderbar">
|
||||||
<WunderBar/>
|
<WunderBar/>
|
||||||
</div>
|
</div>
|
||||||
<div className="header__item">
|
<div className="header__item">
|
||||||
<Link onClick={() => navigate('wallet')} button="text" icon="icon-bank" label={balance} ></Link>
|
<Link onClick={() => navigate('/wallet')} button="text" icon="icon-bank" label={balance} ></Link>
|
||||||
</div>
|
</div>
|
||||||
<div className="header__item">
|
<div className="header__item">
|
||||||
<Link onClick={() => navigate('publish')} button="primary button--flat" icon="icon-upload" label="Publish" />
|
<Link onClick={() => navigate('/publish')} button="primary button--flat" icon="icon-upload" label="Publish" />
|
||||||
</div>
|
</div>
|
||||||
<div className="header__item">
|
<div className="header__item">
|
||||||
<Link onClick={() => navigate('downloaded')} button="alt button--flat" icon="icon-folder" />
|
<Link onClick={() => navigate('/downloaded')} button="alt button--flat" icon="icon-folder" />
|
||||||
</div>
|
</div>
|
||||||
<div className="header__item">
|
<div className="header__item">
|
||||||
<Link onClick={() => navigate('settings')} button="alt button--flat" icon="icon-gear" />
|
<Link onClick={() => navigate('/settings')} button="alt button--flat" icon="icon-gear" />
|
||||||
</div>
|
</div>
|
||||||
</header>
|
</header>
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
import React from 'react'
|
import React from 'react'
|
||||||
|
import Link from 'component/link'
|
||||||
|
|
||||||
const SubHeader = (props) => {
|
const SubHeader = (props) => {
|
||||||
const {
|
const {
|
||||||
|
@ -12,9 +13,9 @@ const SubHeader = (props) => {
|
||||||
|
|
||||||
for(let link of Object.keys(subLinks)) {
|
for(let link of Object.keys(subLinks)) {
|
||||||
links.push(
|
links.push(
|
||||||
<a href="#" onClick={() => navigate(link)} key={link} className={link == currentPage ? 'sub-header-selected' : 'sub-header-unselected' }>
|
<Link onClick={(event) => navigate(`/${link}`, event)} key={link} className={link == currentPage ? 'sub-header-selected' : 'sub-header-unselected' }>
|
||||||
{subLinks[link]}
|
{subLinks[link]}
|
||||||
</a>
|
</Link>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -27,18 +27,29 @@ window.addEventListener('contextmenu', (event) => {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
});
|
});
|
||||||
|
|
||||||
window.addEventListener('popstate', (event) => {
|
const parseQueryParams = (queryString) => {
|
||||||
let pathname = document.location.pathname
|
if (queryString === '') return {};
|
||||||
if (pathname.match(/dist/))
|
const parts = queryString
|
||||||
pathname = '/discover'
|
.split('?')
|
||||||
|
.pop()
|
||||||
|
.split('&')
|
||||||
|
.map(function(p) { return p.split('=') })
|
||||||
|
|
||||||
app.store.dispatch(doChangePath(pathname))
|
const params = {};
|
||||||
|
parts.forEach(function(arr) {
|
||||||
|
params[arr[0]] = arr[1];
|
||||||
})
|
})
|
||||||
|
return params;
|
||||||
if (window.location.hash != '') {
|
|
||||||
window.history.pushState({}, "Discover", location.hash.substring(2));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
window.addEventListener('popstate', (event) => {
|
||||||
|
const pathname = document.location.pathname
|
||||||
|
const queryString = document.location.search
|
||||||
|
if (pathname.match(/dist/)) return
|
||||||
|
|
||||||
|
app.store.dispatch(doChangePath(`${pathname}${queryString}`))
|
||||||
|
})
|
||||||
|
|
||||||
const initialState = app.store.getState();
|
const initialState = app.store.getState();
|
||||||
app.store.subscribe(runTriggers);
|
app.store.subscribe(runTriggers);
|
||||||
runTriggers();
|
runTriggers();
|
||||||
|
@ -54,6 +65,7 @@ var init = function() {
|
||||||
|
|
||||||
function onDaemonReady() {
|
function onDaemonReady() {
|
||||||
app.store.dispatch(doDaemonReady())
|
app.store.dispatch(doDaemonReady())
|
||||||
|
window.history.pushState({}, "Discover", '/discover');
|
||||||
ReactDOM.render(<Provider store={store}><div>{ lbryio.enabled ? <AuthOverlay/> : '' }<App /><SnackBar /></div></Provider>, canvas)
|
ReactDOM.render(<Provider store={store}><div>{ lbryio.enabled ? <AuthOverlay/> : '' }<App /><SnackBar /></div></Provider>, canvas)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -22,7 +22,7 @@ class FileListDownloaded extends React.Component {
|
||||||
if (fetching) {
|
if (fetching) {
|
||||||
content = <BusyMessage message="Loading" />
|
content = <BusyMessage message="Loading" />
|
||||||
} else if (!downloadedContent.length) {
|
} else if (!downloadedContent.length) {
|
||||||
content = <span>You haven't downloaded anything from LBRY yet. Go <Link href="#" onClick={() => navigate('discover')} label="search for your first download" />!</span>
|
content = <span>You haven't downloaded anything from LBRY yet. Go <Link onClick={() => navigate('/discover')} label="search for your first download" />!</span>
|
||||||
} else {
|
} else {
|
||||||
content = <FileList fileInfos={downloadedContent} hidePrices={true} />
|
content = <FileList fileInfos={downloadedContent} hidePrices={true} />
|
||||||
}
|
}
|
||||||
|
|
|
@ -43,7 +43,7 @@ class FileListPublished extends React.Component {
|
||||||
if (fetching) {
|
if (fetching) {
|
||||||
content = <BusyMessage message="Loading" />
|
content = <BusyMessage message="Loading" />
|
||||||
} else if (!publishedContent.length) {
|
} else if (!publishedContent.length) {
|
||||||
content = <span>You haven't downloaded anything from LBRY yet. Go <Link href="#" onClick={() => navigate('discover')} label="search for your first download" />!</span>
|
content = <span>You haven't downloaded anything from LBRY yet. Go <Link onClick={() => navigate('/discover')} label="search for your first download" />!</span>
|
||||||
} else {
|
} else {
|
||||||
content = <FileList fileInfos={publishedContent} hidePrices={true} />
|
content = <FileList fileInfos={publishedContent} hidePrices={true} />
|
||||||
}
|
}
|
||||||
|
|
|
@ -77,7 +77,7 @@ var HelpPage = React.createClass({
|
||||||
<div className="card__title-primary"><h3>Report a Bug</h3></div>
|
<div className="card__title-primary"><h3>Report a Bug</h3></div>
|
||||||
<div className="card__content">
|
<div className="card__content">
|
||||||
<p>Did you find something wrong?</p>
|
<p>Did you find something wrong?</p>
|
||||||
<p><Link href="?report" label="Submit a Bug Report" icon="icon-bug" button="alt" /></p>
|
<p><Link onClick={() => navigate('report')} label="Submit a Bug Report" icon="icon-bug" button="alt" /></p>
|
||||||
<div className="meta">Thanks! LBRY is made by its users.</div>
|
<div className="meta">Thanks! LBRY is made by its users.</div>
|
||||||
</div>
|
</div>
|
||||||
</section>
|
</section>
|
||||||
|
|
|
@ -147,7 +147,7 @@ var PublishPage = React.createClass({
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
handlePublishStartedConfirmed: function() {
|
handlePublishStartedConfirmed: function() {
|
||||||
this.props.navigate('published')
|
this.props.navigate('/published')
|
||||||
},
|
},
|
||||||
handlePublishError: function(error) {
|
handlePublishError: function(error) {
|
||||||
this.setState({
|
this.setState({
|
||||||
|
|
|
@ -18,7 +18,7 @@ const SearchNoResults = (props) => {
|
||||||
return <section>
|
return <section>
|
||||||
<span className="empty">
|
<span className="empty">
|
||||||
No one has checked anything in for {query} yet.
|
No one has checked anything in for {query} yet.
|
||||||
<Link label="Be the first" href="#" onClick={() => navigate('publish')} />
|
<Link label="Be the first" onClick={() => navigate('/publish')} />
|
||||||
</span>
|
</span>
|
||||||
</section>;
|
</section>;
|
||||||
}
|
}
|
||||||
|
|
|
@ -53,7 +53,7 @@ const ShowPage = (props) => {
|
||||||
</div>
|
</div>
|
||||||
<div className="card__content">
|
<div className="card__content">
|
||||||
{ uriLookupComplete ?
|
{ uriLookupComplete ?
|
||||||
<p>This location is not yet in use. { ' ' }<Link href="#" onClick={() => navigate('publish')} label="Put something here" />.</p> :
|
<p>This location is not yet in use. { ' ' }<Link onClick={() => navigate('/publish')} label="Put something here" />.</p> :
|
||||||
<BusyMessage message="Loading magic decentralized data..." />
|
<BusyMessage message="Loading magic decentralized data..." />
|
||||||
}
|
}
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -22,7 +22,7 @@ export const selectCurrentPage = createSelector(
|
||||||
(path, searchActivated) => {
|
(path, searchActivated) => {
|
||||||
if (searchActivated) return 'search'
|
if (searchActivated) return 'search'
|
||||||
|
|
||||||
return path.replace(/^\//, '').split('=')[0]
|
return path.replace(/^\//, '').split('?')[0]
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue