chatscope / chatscope/chat-ui-kit-react

How to close loadingMore status when no more messages?

Open
#77 8 comments 0 reactions 1 assignee Claimed by @supersnager View on GitHub
question
Dominant language
JavaScript
Stars
1.8k
Forks
154
PR merge metrics
No merged PRs in 30d

Description

I have refered to the code in https://chatscope.io/storybook/react/?path=/docs/components-messagelist--loading-more-state and changed the fake fetch part, receiving loaded messages in batches from my own server whenever I scroll the bar to the top. But I have difficulty stopping loading more messages when there are no more messages (aka. `this.state.receivedloadMsgList === []` ), and it failed to work as below.

![image](https://user-images.githubusercontent.com/113967503/201819291-ac39fc59-9e10-4cda-9d7c-0559ce9245ae.png)

The loadingMore circle constantly appears and it is just stuck here. Meanwhile, my last batch of loaded messages doesn't show either ( which is ` [1, 2, 3, 4] ` ).

Does anyone know how to stop executing `onYReachStart` function when there are no more loaded messages? Also, how can I close `loadingMore` status? THANKS!

Here is part of my code:

```
onYReachStart(e) {
if (this.state.loadingMore == true) {
return;
}

if (this.state.receivedloadMsgList != []) {
this.setState({loadingMore: true});
} else {
this.setState({loadingMore: false});return;
}

setTimeout(() => {
let messages = [];

if (this.state.receivedloadMsgList !== []) {

let list = this.state.receivedloadMsgList; // loaded messages from the server

list.reverse().forEach((val, i) => {
let position;

if (val.mode1 == 'sysmessage') {
messages.push()
}else if (val.sender == this.state.ownner.id) { position = 'outgoing' }
else { position = 'incoming' }

if (val.mode1 == 'text') {
messages.push(



)
this.setState({counter: this.state.counter+1});
}
if (val.mode1 == 'photo') {
messages.push(


...


)
this.setState({counter: this.state.counter+1})
}
if (val.mode1 == 'file') {
messages.push(


...


)
}
})
this.setState({loadedMsgList: messages.reverse().concat(this.state.loadedMsgList)});
this.setState({loadingMore: false});
}
}, 1500);
```

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.