frontend: fix unnecessary requests being sent when switching between channels

This commit is contained in:
hippoz 2022-04-21 02:11:44 +03:00
parent 459b1c6703
commit e19a3aa6cc
No known key found for this signature in database
GPG key ID: 7C52899193467641

View file

@ -1,5 +1,6 @@
<script> <script>
import { afterUpdate, beforeUpdate } from "svelte"; import { afterUpdate, beforeUpdate } from "svelte";
import { element } from "svelte/internal";
import { messagesStoreProvider } from "../../../stores.js"; import { messagesStoreProvider } from "../../../stores.js";
export let channelId; export let channelId;
@ -20,12 +21,12 @@
const onScroll = (e) => { const onScroll = (e) => {
const { scrollTop, offsetHeight, scrollHeight } = e.target; const { scrollTop, offsetHeight, scrollHeight } = e.target;
if (scrollTop === 0) {
messages.loadOlderMessages();
}
if ((scrollTop + offsetHeight) >= scrollHeight) { if ((scrollTop + offsetHeight) >= scrollHeight) {
messages.setIsCollectingOldMessages(true); messages.setIsCollectingOldMessages(true);
} else { } else {
if (scrollTop === 0) {
messages.loadOlderMessages();
}
messages.setIsCollectingOldMessages(false); messages.setIsCollectingOldMessages(false);
} }
}; };