feat: implement infinite scroll by shifting offset to 15th message and removing debug logs
Change the scroll-triggered message loading logic from checking the 4th message to the 15th message as the offset anchor, and remove console.info debug statements for channelUid and loaded messages.
This commit is contained in:
@@ -59,23 +59,21 @@
|
||||
const messagesContainer = document.querySelector(".chat-messages");
|
||||
async function loadExtra() {
|
||||
|
||||
const fourthMessage = messagesContainer.querySelector(".chat-messages :nth-child(4)");
|
||||
if(!fourthMessage){
|
||||
const offsetMessage = messagesContainer.querySelector(".chat-messages :nth-child(15)");
|
||||
if(!offsetMessage){
|
||||
return
|
||||
}
|
||||
const firstMessage = messagesContainer.querySelector(".message:first-child");
|
||||
if(fourthMessage.dataset.seen){
|
||||
if(offsetMessage.dataset.seen){
|
||||
return
|
||||
}
|
||||
|
||||
if(isElementVisible(fourthMessage)){
|
||||
fourthMessage.dataset.seen = true
|
||||
console.info(channelUid, fourthMessage.dataset.created_at)
|
||||
if(isElementVisible(offsetMessage)){
|
||||
offsetMessage.dataset.seen = true
|
||||
const messages = await app.rpc.get_messages(channelUid, 1, fourthMessage.dataset.created_at);
|
||||
messages.forEach((message) => {
|
||||
firstMessage.insertAdjacentHTML("beforebegin", message.html);
|
||||
})
|
||||
console.info(messages)
|
||||
}
|
||||
}
|
||||
messagesContainer.addEventListener("scroll",()=>{
|
||||
|
||||
Reference in New Issue
Block a user