feat(search): new search navigation
This commit is contained in:
parent
06e54fca0f
commit
da6093ad4a
@ -1,10 +1,6 @@
|
|||||||
import React from 'react';
|
import React from 'react';
|
||||||
import Page from './page';
|
import Page from './page';
|
||||||
|
|
||||||
import SearchResults from './search-results'
|
|
||||||
import Search from './search'
|
|
||||||
import SelectField from 'material-ui/SelectField';
|
|
||||||
import MenuItem from 'material-ui/MenuItem';
|
|
||||||
import Feed from './feed';
|
import Feed from './feed';
|
||||||
|
|
||||||
export default class FeedPage extends Page {
|
export default class FeedPage extends Page {
|
||||||
@ -12,81 +8,9 @@ export default class FeedPage extends Page {
|
|||||||
super(props)
|
super(props)
|
||||||
this.setTitle('Rats On The Boat - Content Search Engine');
|
this.setTitle('Rats On The Boat - Content Search Engine');
|
||||||
}
|
}
|
||||||
componentDidMount()
|
|
||||||
{
|
|
||||||
Search.instance().onSearchUpdate = () => this.forceUpdate()
|
|
||||||
}
|
|
||||||
componentWillUnmount()
|
|
||||||
{
|
|
||||||
Search.instance().onSearchUpdate = () => {}
|
|
||||||
}
|
|
||||||
render() {
|
render() {
|
||||||
const orderText = (text, field) => {
|
|
||||||
if(field !== Search.instance().state.orderBy)
|
|
||||||
return text;
|
|
||||||
|
|
||||||
if(Search.instance().state.orderDesc)
|
|
||||||
return text + ' ⇩'
|
|
||||||
else
|
|
||||||
return text + ' ⇧'
|
|
||||||
}
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div id='index-window' className='column center'>
|
<div id='index-window' className='column center'>
|
||||||
<div className='torrents-container'>
|
|
||||||
<SearchResults
|
|
||||||
torrentsSearchResults={Search.instance().searchTorrents}
|
|
||||||
filesSearchResults={Search.instance().searchFiles}
|
|
||||||
currentSearching={Search.instance().state.searchingIndicator}
|
|
||||||
searchText={Search.instance().currentSearch}
|
|
||||||
resultSelector={
|
|
||||||
<SelectField
|
|
||||||
floatingLabelText={__("Sort by")}
|
|
||||||
floatingLabelFixed={true}
|
|
||||||
value={Search.instance().state.orderBy}
|
|
||||||
onChange={(event, index, value) => {
|
|
||||||
event.preventDefault(); // fix overclick on torrent
|
|
||||||
if(value === 'none') {
|
|
||||||
Search.instance().setState({orderBy: null}, () => {
|
|
||||||
Search.instance().search(true)
|
|
||||||
})
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(value === Search.instance().state.orderBy)
|
|
||||||
{
|
|
||||||
Search.instance().setState({orderDesc: !Search.instance().state.orderDesc}, () => {
|
|
||||||
Search.instance().search(true)
|
|
||||||
})
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
Search.instance().setState({
|
|
||||||
orderBy: value,
|
|
||||||
orderDesc: (value === 'seeders' || value === 'completed' || value === 'added') ? true : Search.instance().state.orderDesc
|
|
||||||
}, () => {
|
|
||||||
Search.instance().search(true)
|
|
||||||
})
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<MenuItem value='none' primaryText={__('None')} />
|
|
||||||
<MenuItem value='seeders' primaryText={orderText(__('Seeders'), 'seeders')} />
|
|
||||||
<MenuItem value='name' primaryText={orderText(__('Name'), 'name')} />
|
|
||||||
<MenuItem value='files' primaryText={orderText(__('Files'), 'files')} />
|
|
||||||
<MenuItem value='size' primaryText={orderText(__('Size'), 'size')} />
|
|
||||||
<MenuItem value='added' primaryText={orderText(__('Added date'), 'added')} />
|
|
||||||
<MenuItem value='completed' primaryText={orderText(__('Completed'), 'completed')} />
|
|
||||||
</SelectField>
|
|
||||||
}
|
|
||||||
|
|
||||||
moreTorrentsEnabled={Search.instance().moreSearchTorrents && !Search.instance().state.searchingIndicator}
|
|
||||||
moreFilesEnabled={Search.instance().moreSearchFiles && !Search.instance().state.searchingIndicator}
|
|
||||||
onMoreTorrents={() => Search.instance().moreTorrents()}
|
|
||||||
onMoreFiles={() => Search.instance().moreFiles()}
|
|
||||||
moreTorrentsIndicator={Search.instance().state.moreTorrentsIndicator}
|
|
||||||
moreFilesIndicator={Search.instance().state.moreFilesIndicator}
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
<div className='column center w100p pad0-75'>
|
<div className='column center w100p pad0-75'>
|
||||||
<Feed />
|
<Feed />
|
||||||
</div>
|
</div>
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
import PagesPie from './pages-pie.js';
|
import PagesPie from './pages-pie.js';
|
||||||
|
|
||||||
import FeedPage from './feed-page.js'
|
import FeedPage from './feed-page.js'
|
||||||
|
import SearchPage from './search-page.js'
|
||||||
import ActivityPage from './activity-page'
|
import ActivityPage from './activity-page'
|
||||||
import TorrentPage from './torrent-page.js'
|
import TorrentPage from './torrent-page.js'
|
||||||
import DMCAPage from './dmca-page.js'
|
import DMCAPage from './dmca-page.js'
|
||||||
@ -11,10 +12,18 @@ import DownloadPage from './download-page.js'
|
|||||||
import ChangelogPage from './changelog-page.js'
|
import ChangelogPage from './changelog-page.js'
|
||||||
import FiltersPage from './filters-page.js'
|
import FiltersPage from './filters-page.js'
|
||||||
|
|
||||||
|
const history = []
|
||||||
|
let currentPage
|
||||||
|
|
||||||
let routers = {}
|
let routers = {}
|
||||||
const router = (page, callback) => {
|
const router = (page, callback) => {
|
||||||
if(!callback)
|
if(!callback)
|
||||||
{
|
{
|
||||||
|
currentPage = page ? page : '/'
|
||||||
|
if(history.length >= 10)
|
||||||
|
history.shift()
|
||||||
|
history.push(currentPage)
|
||||||
|
|
||||||
if(!page)
|
if(!page)
|
||||||
routers['/'].callback()
|
routers['/'].callback()
|
||||||
else
|
else
|
||||||
@ -52,12 +61,34 @@ const router = (page, callback) => {
|
|||||||
|
|
||||||
|
|
||||||
window.router = router;
|
window.router = router;
|
||||||
|
window.routerOpenPrev = () => {
|
||||||
|
console.log(history)
|
||||||
|
if(history.length < 2)
|
||||||
|
return
|
||||||
|
history.pop() // last page
|
||||||
|
router(history.pop())
|
||||||
|
}
|
||||||
|
|
||||||
|
window.routerFix = () => {
|
||||||
|
if(history.length >= 10)
|
||||||
|
history.shift()
|
||||||
|
history.push(currentPage)
|
||||||
|
currentPage = ''
|
||||||
|
}
|
||||||
|
|
||||||
|
window.routerCurrent = () => currentPage
|
||||||
|
|
||||||
router('/', () => {
|
router('/', () => {
|
||||||
//singleton
|
//singleton
|
||||||
PagesPie.instance().open(FeedPage, {replace: 'all'});
|
PagesPie.instance().open(FeedPage, {replace: 'all'});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
router('/search', () => {
|
||||||
|
//singleton
|
||||||
|
PagesPie.instance().open(SearchPage, {replace: 'all'});
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
router('/torrent/:hash', (e) => {
|
router('/torrent/:hash', (e) => {
|
||||||
//singleton
|
//singleton
|
||||||
PagesPie.instance().open(TorrentPage, {
|
PagesPie.instance().open(TorrentPage, {
|
||||||
|
92
src/app/search-page.js
Normal file
92
src/app/search-page.js
Normal file
@ -0,0 +1,92 @@
|
|||||||
|
import React from 'react';
|
||||||
|
import Page from './page';
|
||||||
|
|
||||||
|
import SearchResults from './search-results'
|
||||||
|
import Search from './search'
|
||||||
|
import SelectField from 'material-ui/SelectField';
|
||||||
|
import MenuItem from 'material-ui/MenuItem';
|
||||||
|
|
||||||
|
export default class SearchPage extends Page {
|
||||||
|
constructor(props) {
|
||||||
|
super(props)
|
||||||
|
this.setTitle('Rats On The Boat - Content Search Engine');
|
||||||
|
}
|
||||||
|
componentDidMount()
|
||||||
|
{
|
||||||
|
Search.instance().onSearchUpdate = () => this.forceUpdate()
|
||||||
|
}
|
||||||
|
componentWillUnmount()
|
||||||
|
{
|
||||||
|
Search.instance().onSearchUpdate = () => {}
|
||||||
|
}
|
||||||
|
render() {
|
||||||
|
const orderText = (text, field) => {
|
||||||
|
if(field !== Search.instance().state.orderBy)
|
||||||
|
return text;
|
||||||
|
|
||||||
|
if(Search.instance().state.orderDesc)
|
||||||
|
return text + ' ⇩'
|
||||||
|
else
|
||||||
|
return text + ' ⇧'
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className='column center'>
|
||||||
|
<div className='torrents-container'>
|
||||||
|
<SearchResults
|
||||||
|
torrentsSearchResults={Search.instance().searchTorrents}
|
||||||
|
filesSearchResults={Search.instance().searchFiles}
|
||||||
|
currentSearching={Search.instance().state.searchingIndicator}
|
||||||
|
searchText={Search.instance().currentSearch}
|
||||||
|
resultSelector={
|
||||||
|
<SelectField
|
||||||
|
floatingLabelText={__("Sort by")}
|
||||||
|
floatingLabelFixed={true}
|
||||||
|
value={Search.instance().state.orderBy}
|
||||||
|
onChange={(event, index, value) => {
|
||||||
|
event.preventDefault(); // fix overclick on torrent
|
||||||
|
if(value === 'none') {
|
||||||
|
Search.instance().setState({orderBy: null}, () => {
|
||||||
|
Search.instance().search(true)
|
||||||
|
})
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(value === Search.instance().state.orderBy)
|
||||||
|
{
|
||||||
|
Search.instance().setState({orderDesc: !Search.instance().state.orderDesc}, () => {
|
||||||
|
Search.instance().search(true)
|
||||||
|
})
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
Search.instance().setState({
|
||||||
|
orderBy: value,
|
||||||
|
orderDesc: (value === 'seeders' || value === 'completed' || value === 'added') ? true : Search.instance().state.orderDesc
|
||||||
|
}, () => {
|
||||||
|
Search.instance().search(true)
|
||||||
|
})
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<MenuItem value='none' primaryText={__('None')} />
|
||||||
|
<MenuItem value='seeders' primaryText={orderText(__('Seeders'), 'seeders')} />
|
||||||
|
<MenuItem value='name' primaryText={orderText(__('Name'), 'name')} />
|
||||||
|
<MenuItem value='files' primaryText={orderText(__('Files'), 'files')} />
|
||||||
|
<MenuItem value='size' primaryText={orderText(__('Size'), 'size')} />
|
||||||
|
<MenuItem value='added' primaryText={orderText(__('Added date'), 'added')} />
|
||||||
|
<MenuItem value='completed' primaryText={orderText(__('Completed'), 'completed')} />
|
||||||
|
</SelectField>
|
||||||
|
}
|
||||||
|
|
||||||
|
moreTorrentsEnabled={Search.instance().moreSearchTorrents && !Search.instance().state.searchingIndicator}
|
||||||
|
moreFilesEnabled={Search.instance().moreSearchFiles && !Search.instance().state.searchingIndicator}
|
||||||
|
onMoreTorrents={() => Search.instance().moreTorrents()}
|
||||||
|
onMoreFiles={() => Search.instance().moreFiles()}
|
||||||
|
moreTorrentsIndicator={Search.instance().state.moreTorrentsIndicator}
|
||||||
|
moreFilesIndicator={Search.instance().state.moreFilesIndicator}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
@ -38,7 +38,7 @@ class Search extends Component {
|
|||||||
}
|
}
|
||||||
|
|
||||||
search(oldSearch) {
|
search(oldSearch) {
|
||||||
window.router('/')
|
window.router('/search')
|
||||||
this.setState({
|
this.setState({
|
||||||
searchingIndicator: true
|
searchingIndicator: true
|
||||||
});
|
});
|
||||||
@ -257,6 +257,27 @@ class Search extends Component {
|
|||||||
return (
|
return (
|
||||||
<div className="column w100p center">
|
<div className="column w100p center">
|
||||||
<div className='row inline w100p pad0-75 search-row' style={{minWidth: '35em', backgroundColor: 'white', paddingTop: 0, paddingBottom: this.searchError ? 17 : 0, margin: 5, borderRadius: 3}}>
|
<div className='row inline w100p pad0-75 search-row' style={{minWidth: '35em', backgroundColor: 'white', paddingTop: 0, paddingBottom: this.searchError ? 17 : 0, margin: 5, borderRadius: 3}}>
|
||||||
|
{
|
||||||
|
((this.searchTorrents && this.searchTorrents.length > 0) || (this.searchFiles && this.searchFiles.length > 0))
|
||||||
|
&&
|
||||||
|
<div style={{width: 25, height: 25, margin: 2, marginRight: 8}}>
|
||||||
|
<Checkbox
|
||||||
|
checked={false}
|
||||||
|
uncheckedIcon={<svg viewBox="0 0 459 459">
|
||||||
|
<g>
|
||||||
|
<path d="M178.5,382.5h102v-51h-102V382.5z M0,76.5v51h459v-51H0z M76.5,255h306v-51h-306V255z"/>
|
||||||
|
</g>
|
||||||
|
</svg>
|
||||||
|
}
|
||||||
|
iconStyle={{fill: '#27ce74'}}
|
||||||
|
onCheck={() => {
|
||||||
|
if(window.routerCurrent() !== '/search')
|
||||||
|
window.router('/search')
|
||||||
|
}}
|
||||||
|
style={{paddingTop: '0.6em', paddingLeft: '0.2em'}}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
}
|
||||||
<TextField
|
<TextField
|
||||||
style={{marginTop: -12}}
|
style={{marginTop: -12}}
|
||||||
hintText={__('Search torrent or file')}
|
hintText={__('Search torrent or file')}
|
||||||
|
@ -170,7 +170,7 @@ export default class TorrentPage extends Page {
|
|||||||
|
|
||||||
handleChange = (value) => {
|
handleChange = (value) => {
|
||||||
if(value == 'main') {
|
if(value == 'main') {
|
||||||
window.router('/');
|
window.routerOpenPrev();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -338,7 +338,7 @@ export default class TorrentPage extends Page {
|
|||||||
value={this.state.value}
|
value={this.state.value}
|
||||||
onChange={this.handleChange}
|
onChange={this.handleChange}
|
||||||
>
|
>
|
||||||
<Tab label={__('Back to main')} value="main" />
|
<Tab label={__('Back to previus')} value="main" />
|
||||||
<Tab label={__('Information')} value="info" >
|
<Tab label={__('Information')} value="info" >
|
||||||
<div className='column w100p'>
|
<div className='column w100p'>
|
||||||
<div className='row w100p torrent-information-row'>
|
<div className='row w100p torrent-information-row'>
|
||||||
|
@ -238,7 +238,7 @@ export default class Torrent extends Component {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
|
window.routerFix()
|
||||||
PagesPie.instance().open(TorrentPage, {replace: 'all', hash: torrent.hash, peer: torrent.peer})
|
PagesPie.instance().open(TorrentPage, {replace: 'all', hash: torrent.hash, peer: torrent.peer})
|
||||||
}}
|
}}
|
||||||
primaryText={
|
primaryText={
|
||||||
|
Loading…
Reference in New Issue
Block a user