2
2
mirror of https://github.com/Thream/website.git synced 2024-07-21 09:28:32 +02:00

fix: autoscroll the user when posting a message even if is not at bottom

This commit is contained in:
Divlo 2022-06-29 06:23:23 +02:00
parent 10b1e568d2
commit 21ee6f1d66
No known key found for this signature in database
GPG Key ID: 8F9478F220CE65E9

View File

@ -23,7 +23,7 @@ export const MessagesProvider: React.FC<
React.PropsWithChildren<MessagesProviderProps>
> = (props) => {
const { path, children } = props
const { authentication } = useAuthentication()
const { authentication, user } = useAuthentication()
const {
items: messages,
@ -49,7 +49,10 @@ export const MessagesProvider: React.FC<
messagesDiv.scrollHeight - messagesDiv.scrollTop <=
messagesDiv.clientHeight
handleSocketData({ data, setItems })
if (data.action === 'create' && isAtBottom) {
if (
data.action === 'create' &&
(isAtBottom || data.item.member.userId === user.id)
) {
messagesDiv.scrollTo(0, messagesDiv.scrollHeight)
}
}
@ -59,7 +62,7 @@ export const MessagesProvider: React.FC<
return () => {
authentication.socket.off('messages')
}
}, [authentication.socket, setItems, path])
}, [authentication.socket, setItems, path, user.id])
useEffect(() => {
resetPagination()