fix fetch on scroll

This commit is contained in:
nflnkr 2023-05-12 22:10:43 +03:00
parent 9b55c9731b
commit e5f679fd96
2 changed files with 2 additions and 3 deletions

@ -44,6 +44,7 @@ export default function Chat({ sx }: Props) {
}).then(result => { }).then(result => {
console.log("GetMessagesResponse", result); console.log("GetMessagesResponse", result);
if (result?.length > 0) { if (result?.length > 0) {
if (chatBoxRef.current && chatBoxRef.current.scrollTop < 1) chatBoxRef.current.scrollTop = 1;
addOrUpdateUnauthMessages(result); addOrUpdateUnauthMessages(result);
setUnauthTicketFetchState("idle"); setUnauthTicketFetchState("idle");
} else setUnauthTicketFetchState("all fetched"); } else setUnauthTicketFetchState("all fetched");
@ -81,7 +82,6 @@ export default function Chat({ sx }: Props) {
return () => { return () => {
unsubscribe(); unsubscribe();
// clearUnauthTicketState();
setUnauthIsPreventAutoscroll(false); setUnauthIsPreventAutoscroll(false);
}; };
}, [sessionData]); }, [sessionData]);
@ -98,7 +98,6 @@ export default function Chat({ sx }: Props) {
if (messagesFetchStateRef.current !== "idle") return; if (messagesFetchStateRef.current !== "idle") return;
if (chatBox.scrollTop < chatBox.clientHeight) { if (chatBox.scrollTop < chatBox.clientHeight) {
if (chatBox.scrollTop < 1) chatBox.scrollTop = 1;
incrementUnauthMessageApiPage(); incrementUnauthMessageApiPage();
} }
}; };

@ -47,6 +47,7 @@ export default function SupportChat() {
}).then(result => { }).then(result => {
console.log("GetMessagesResponse", result); console.log("GetMessagesResponse", result);
if (result?.length > 0) { if (result?.length > 0) {
if (chatBoxRef.current && chatBoxRef.current.scrollTop < 1) chatBoxRef.current.scrollTop = 1;
addOrUpdateMessages(result); addOrUpdateMessages(result);
setMessageFetchState("idle"); setMessageFetchState("idle");
} else setMessageFetchState("all fetched"); } else setMessageFetchState("all fetched");
@ -99,7 +100,6 @@ export default function SupportChat() {
if (messagesFetchStateRef.current !== "idle") return; if (messagesFetchStateRef.current !== "idle") return;
if (chatBox.scrollTop < chatBox.clientHeight) { if (chatBox.scrollTop < chatBox.clientHeight) {
if (chatBox.scrollTop < 1) chatBox.scrollTop = 1;
incrementMessageApiPage(); incrementMessageApiPage();
} }
}; };