fix WSOD on filtering

This commit is contained in:
b1ek 2023-05-11 23:54:50 +10:00
parent 69c66d943a
commit 75ca34ff2a
Signed by: blek
GPG Key ID: 14546221E3595D0C
1 changed files with 8 additions and 8 deletions

View File

@ -343,18 +343,17 @@ export default class IndexPage extends React.Component {
this.state = {
apartments: [],
unfiltered: [],
pageSize: 10,
page: 0,
data_loaded: false,
load_err: false,
loading_filters: true
loading_filters: false
};
ApartamentService.getAll(100).then(data => {
this.setState({apartments: data.data.results, unfiltered: data.data.results, data_loaded: true});
this.setState({apartments: data.data.results, data_loaded: true});
}).catch(err => {
this.setState({data_loaded: true, apartments: [], unfiltered: data.data.results, load_err: err.message});
this.setState({data_loaded: true, apartments: [], load_err: err.message});
});
this.filterData = this.filterData.bind(this);
@ -378,13 +377,12 @@ export default class IndexPage extends React.Component {
const filtered = await filtered_raw.json();
this.setState({apartments: filtered, data_loaded: true, load_err: false});
;
this.setState({apartments: filtered, data_loaded: true, loading: false, load_err: false});
}
render() {
let { page, pageSize } = this.state;
let pages = this.state.apartments.length / pageSize;
let pages = Math.floor(this.state.apartments.length / pageSize);
let current_data = this.state.apartments.slice((page * pageSize), (page * pageSize) + pageSize);
@ -436,6 +434,7 @@ export default class IndexPage extends React.Component {
<PageButtons>
{
pages != 0 ?
[...Array(pages)].map((_, i) => {
if (i > 3 && i != pageSize - 1) {
if (i == 4)
@ -449,7 +448,8 @@ export default class IndexPage extends React.Component {
return (
<PageButton>{i + 1}</PageButton>
);
})
}) :
null
}
</PageButtons>
</IndexPageRoot>