cache filters in session storage
This commit is contained in:
parent
c91eba0a62
commit
eb89bb3526
|
@ -174,7 +174,8 @@ const FiltersForm = (props) => {
|
|||
{ value: 1, label: '1 комната' },
|
||||
{ value: 2, label: '2 комнаты' },
|
||||
{ value: 3, label: '3 комнаты' },
|
||||
{ value: 4, label: '4 комнаты' }
|
||||
{ value: 4, label: '4 комнаты' },
|
||||
{ value: -1, label: 'Выберите' }
|
||||
];
|
||||
|
||||
const def_form = {
|
||||
|
@ -194,10 +195,15 @@ const FiltersForm = (props) => {
|
|||
form_err: false
|
||||
};
|
||||
|
||||
let cached_filters = window.sessionStorage.getItem('pairent_filters');
|
||||
if (cached_filters) cached_filters = JSON.parse(cached_filters);
|
||||
|
||||
const [ state, setState_ ] = useState(def_form);
|
||||
const [ state, setState_ ] = useState(cached_filters || def_form);
|
||||
|
||||
const setState = (new_state) => {
|
||||
|
||||
window.sessionStorage.setItem('pairent_filters', JSON.stringify({ ...state, ...new_state }));
|
||||
|
||||
return setState_({...state, ...new_state});
|
||||
}
|
||||
|
||||
|
@ -358,10 +364,10 @@ export default class IndexPage extends React.Component {
|
|||
}
|
||||
|
||||
render() {
|
||||
const { page, pageSize } = this.state;
|
||||
const pages = this.state.apartments.length / pageSize;
|
||||
let { page, pageSize } = this.state;
|
||||
let pages = this.state.apartments.length / pageSize;
|
||||
|
||||
const current_data = this.state.apartments.slice((page * pageSize), (page * pageSize) + pageSize);
|
||||
let current_data = this.state.apartments.slice((page * pageSize), (page * pageSize) + pageSize);
|
||||
|
||||
|
||||
return (
|
||||
|
|
Loading…
Reference in New Issue