Skip to content

Commit

Permalink
improve message loading process
Browse files Browse the repository at this point in the history
  • Loading branch information
0x46616c6b committed Nov 8, 2018
1 parent 16d1e01 commit 50d0c33
Showing 1 changed file with 16 additions and 17 deletions.
33 changes: 16 additions & 17 deletions src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ class App extends Component {
messages: [],
isLoading: true,
isLoadingOlderMessages: false,
isInitialized: false,
reachedMessagesEnd: false,
showReloadInfo: localStorage.getItem('showReloadInfo') !== '0' || true,
}
Expand Down Expand Up @@ -127,27 +128,25 @@ class App extends Component {
}

fetchMessages () {
let url = `${API_URL}/timeline`

if (this.state.messages[0] !== undefined) {
let after = this.state.messages[0].id

if (after !== undefined) {
fetch(`${API_URL}/timeline?after=${after}`)
.then(response => response.json())
.then(response => {
if (response.data !== undefined && response.data.messages !== null) {
this.setState({messages: response.data.messages.concat(this.state.messages)})
}
})
url = `${API_URL}/timeline?after=${after}`
}
} else {
fetch(`${API_URL}/timeline`)
.then(response => response.json())
.then(response => {
if (response.data !== undefined && response.data.messages !== null) {
this.setState({messages: response.data.messages})
}
})
}

fetch(url)
.then(response => response.json())
.then(response => {
if (response.data !== undefined && response.data.messages !== null) {
this.setState({messages: response.data.messages})
}

this.setState({isInitialized: true})
})

}

handleReloadInfoDismiss () {
Expand Down Expand Up @@ -443,7 +442,7 @@ class App extends Component {
}

render () {
if (this.state.ticker !== null && this.state.ticker.active) {
if (this.state.ticker !== null && this.state.ticker.active && this.state.isInitialized) {
return this.renderActiveMode()
}

Expand Down

0 comments on commit 50d0c33

Please sign in to comment.