Skip to content

Commit

Permalink
one more regarding #63
Browse files Browse the repository at this point in the history
  • Loading branch information
kurtextrem committed Apr 5, 2020
1 parent 5f158f2 commit 3e0cd45
Showing 1 changed file with 20 additions and 14 deletions.
34 changes: 20 additions & 14 deletions src/components/PostsContainer.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,12 @@ export default class PostsContainer extends Component {
</div>
)

state = {
canLoadMore: true,
items: null,
timeout: 0,
}

constructor(properties) {
super(properties)

Expand All @@ -54,11 +60,6 @@ export default class PostsContainer extends Component {
window.setTimeout(() => this.setTimeout(PostsContainer.TIME_STATE.LOADING), PostsContainer.TIME_STATE.LOADING)
}

state = {
items: null,
timeout: 0,
}

setTimeout(timeout) {
this.setState((previousState, properties) => ({ timeout }))
if (timeout !== PostsContainer.TIME_STATE.ERROR)
Expand All @@ -72,7 +73,6 @@ export default class PostsContainer extends Component {

console.log('preloading', id)
Chrome.send('load', { which: id })
window.setTimeout(this.preload, this.preloadCounter * 1000)
}

@bind
Expand All @@ -94,12 +94,18 @@ export default class PostsContainer extends Component {
@bind
handleData(data) {
++this.initial
if (data !== null)
this.setState((previousState, properties) => ({
items: data.items,
//nextMaxId: data.nextMaxId,
timeout: previousState.timeout,
}))
if (data !== null) {
this.setState(
(previousState, properties) => ({
canLoadMore: data.nextMaxId !== '',
items: data.items,
timeout: previousState.timeout,
}),
() => {
window.setTimeout(this.preload, this.preloadCounter * 1000)
}
)
}

return data
}
Expand Down Expand Up @@ -175,14 +181,14 @@ export default class PostsContainer extends Component {

render() {
const { hasCategories } = this.props
const { items, timeout } = this.state
const { items, timeout, canLoadMore } = this.state

if (items !== null && items.length !== 0)
return (
<div class="position-relative">
<CardDeck class="justify-content-center">{Posts(items, this.renderPost, hasCategories)}</CardDeck>
<div class="text-center">
<Button onClick={this.handleBtnClick} disabled={false}>
<Button onClick={this.handleBtnClick} disabled={!canLoadMore}>
Load more
</Button>
</div>
Expand Down

0 comments on commit 3e0cd45

Please sign in to comment.