сохранение сессии на время посещения других страниц

This commit is contained in:
Alexey Kasyanchuk
2017-02-02 13:19:21 +03:00
parent f816fdd29d
commit fae2eda683

View File

@ -11,6 +11,8 @@ import VisibilityOff from 'material-ui/svg-icons/action/visibility-off';
import formatBytes from './format-bytes' import formatBytes from './format-bytes'
let session;
export default class Search extends Component { export default class Search extends Component {
constructor(props) constructor(props)
{ {
@ -23,6 +25,17 @@ export default class Search extends Component {
moreFilesIndicator: false, moreFilesIndicator: false,
} }
this.searchLimit = 10 this.searchLimit = 10
if(session)
{
this.searchTorrents = session.searchTorrents;
this.searchFiles = session.searchFiles;
this.moreSearchTorrents = session.moreSearchTorrents;
this.moreSearchFiles = session.moreSearchFiles;
this.currentSearch = session.currentSearch;
this.searchValue = session.searchValue;
Object.assign(this.state, this.setSafeSearch(session.notSafeSearch))
}
} }
search() { search() {
@ -134,6 +147,27 @@ export default class Search extends Component {
{ {
if(this.newStatisticFunc) if(this.newStatisticFunc)
window.torrentSocket.off('newStatistic', this.newStatisticFunc); window.torrentSocket.off('newStatistic', this.newStatisticFunc);
session = {
searchTorrents: this.searchTorrents,
searchFiles: this.searchFiles,
moreSearchTorrents: this.moreSearchTorrents,
moreSearchFiles: this.moreSearchFiles,
currentSearch: this.currentSearch,
searchValue: this.searchValue,
notSafeSearch: this.notSafeSearch,
}
}
setSafeSearch(ch) {
this.notSafeSearch = ch;
if(ch)
{
return {safeSearchText: 'safe search disabled', safeSearchColor: '#EC407A'}
}
else
{
return {safeSearchText: 'safe search enabled', safeSearchColor: 'rgb(0, 188, 212)'}
}
} }
render() { render() {
const style = { const style = {
@ -151,6 +185,7 @@ export default class Search extends Component {
floatingLabelText="What to search?" floatingLabelText="What to search?"
fullWidth={true} fullWidth={true}
ref='searchInput' ref='searchInput'
defaultValue={this.searchValue}
onKeyPress={(e) => { onKeyPress={(e) => {
if (e.key === 'Enter') { if (e.key === 'Enter') {
this.search(); this.search();
@ -165,20 +200,13 @@ export default class Search extends Component {
<div className='row'> <div className='row'>
<Checkbox <Checkbox
ref='safeSearch' ref='safeSearch'
checked={this.notSafeSearch ? true : false}
checkedIcon={<Visibility />} checkedIcon={<Visibility />}
uncheckedIcon={<VisibilityOff />} uncheckedIcon={<VisibilityOff />}
label={<span className='text-nowrap' style={{fontSize: '0.87em', transition: '0.1s', color: this.state.safeSearchColor}}>{this.state.safeSearchText}</span>} label={<span className='text-nowrap' style={{fontSize: '0.87em', transition: '0.1s', color: this.state.safeSearchColor}}>{this.state.safeSearchText}</span>}
iconStyle={{fill: this.state.safeSearchColor}} iconStyle={{fill: this.state.safeSearchColor}}
onCheck={(ev, ch) => { onCheck={(ev, ch) => {
this.notSafeSearch = ch; this.setState(this.setSafeSearch(ch));
if(ch)
{
this.setState({safeSearchText: 'safe search disabled', safeSearchColor: '#EC407A'});
}
else
{
this.setState({safeSearchText: 'safe search enabled', safeSearchColor: 'rgb(0, 188, 212)'});
}
}} }}
style={{paddingBottom: '0.8em'}} style={{paddingBottom: '0.8em'}}
/> />