Skip to content

Instantly share code, notes, and snippets.

@jmichaliga
Created September 5, 2018 00:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jmichaliga/00e2002cbb3acd1c86140d7ed0594d87 to your computer and use it in GitHub Desktop.
Save jmichaliga/00e2002cbb3acd1c86140d7ed0594d87 to your computer and use it in GitHub Desktop.
Message List Sample Code
_handleScroll = event => {
const thresholdValue = event.target.offsetHeight
const curScroll = event.target.scrollTop
const reloadValue = event.target.scrollHeight
const offset = styles.gridItem.height
if(reloadValue - offset <= thresholdValue + curScroll){
this._fetchMessages(this.state.pageToken);
}
}
_fetchMessages = pT => {
let pageToken = '';
if(pT){pageToken = "?pageToken="+pT}
this.setState({isLoading: true})
if(!this.state.isLoading){
axios.get(API_URL+'messages'+pageToken)
.then( resp => resp.data )
.then( data => {
let newMessages = [];
for(let msg of data.messages){
newMessages.push({
uuid: uuidv4(),
id: msg.id,
content: msg.content,
updated: msg.updated,
author: {
name: msg.author.name,
photoUrl: msg.author.photoUrl
}
})
}
this.setState({
count: data.count,
messages: [
...this.state.messages,
...newMessages
],
pageToken: data.pageToken,
isLoading: false
})
})
.catch( err => console.warn(err))
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment