Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: socket issue & Chat keeps on going to top #832

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export const ChatSupportTest = () => {
<SupportChat

signer={librarySigner}
supportAddress="0x6F7919412318E65109c5698bd0E640fc33DE2337"
supportAddress="0x99A08ac6254dcf7ccc37CeC662aeba8eFA666666"
apiKey="tAWEnggQ9Z.UaDBNjrvlJZx3giBTIQDcT8bKQo1O1518uF1Tea7rPwfzXv2ouV5rX9ViwgJUrXm"
env={env}
greetingMsg="How can i help you?"
Expand Down
2 changes: 1 addition & 1 deletion packages/uiweb/src/lib/components/supportChat/Chat.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ export type ButtonStyleProps = {
setChats(uniqueChats);
};
const socketData = useSDKSocket({
account: account,
account: accountadd,
env,
apiKey,
});
Expand Down
31 changes: 26 additions & 5 deletions packages/uiweb/src/lib/components/supportChat/Modal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,17 +59,32 @@ export const Modal: React.FC = () => {
timestamp: undefined,
icon: <HandWaveSvg fill={theme.btnColorPrimary}/>,
};
const onScroll = () => {
const onScroll = async () => {
if (listInnerRef.current) {
const { scrollTop } = listInnerRef.current;
if (scrollTop === 0) {
// This will be triggered after hitting the first element.
// pagination
getChatCall();
const content = listInnerRef.current;
const curScrollPos = content.scrollTop;
const oldScroll = content.scrollHeight - content.clientHeight;

await getChatCall();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think there is no need to await this function here

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@KlausMikhaelson it is fetching all the history chats from PushAPI and hence it's nice to make it an async call


const newScroll = content.scrollHeight - content.clientHeight;
content.scrollTop = curScrollPos + (newScroll - oldScroll);
}
}
};

const scrollToBottom = () => {
setTimeout(()=>{
if (listInnerRef.current) {
listInnerRef.current.scrollTop = listInnerRef.current.scrollHeight +100;

}
},0)

};

const getChatCall = async () => {
if (!connectedUser) return;
if (wasLastListPresent && !lastThreadHashFetched) return;
Expand All @@ -86,6 +101,7 @@ export const Modal: React.FC = () => {
setLastThreadHashFetched(lastThreadHash);
setWasLastListPresent(lastListPresent);
setLoading(false);
scrollToBottom();
};

const connectUser = async () => {
Expand All @@ -109,6 +125,7 @@ export const Modal: React.FC = () => {
const chat = await decryptChat({ message, connectedUser, env });
socketData.messagesSinceLastConnection.decrypted = true;
setChatsSorted([...chats, chat]);
scrollToBottom();
}
}

Expand All @@ -120,7 +137,11 @@ export const Modal: React.FC = () => {

useEffect(() => {
getChatCall();
}, [connectedUser]);
}, [connectedUser, env, account]);

useEffect(() => {
scrollToBottom();
}, [connectedUser, env, account, lastThreadHashFetched]);

return (
<Container theme={theme}>
Expand Down