I would add another target, that is the messages container. Then, proceed to modify the scroll method to look like this
scroll
async scroll() { if (this.chatTarget.scrollTop < 100 && !this.fetching && !this.hasLastPageTarget) { this.fetching = true await get(this.urlValue, { responseKind: "turbo-stream", query: { page: this.pageValue } }); this.pageValue += 1; this.fetching = false } }
PS. you might want to scroll the container when it loads. You can do so in the initialize method
initialize
initialize() { this.scrollToBottom(); super.initialize(); } scrollToBottom() { this.inboxTarget.scroll({ top: this.inboxTarget.scrollHeight, behavior: this.messageSent ? "smooth" : "instant", }); }
Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink.
Hide child comments as well
Confirm
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
I would add another target, that is the messages container. Then, proceed to modify the
scroll
method to look like thisPS. you might want to scroll the container when it loads. You can do so in the
initialize
method