fix: autoscroll the user when posting a message even if is not at bottom
This commit is contained in:
parent
10b1e568d2
commit
21ee6f1d66
@ -23,7 +23,7 @@ export const MessagesProvider: React.FC<
|
|||||||
React.PropsWithChildren<MessagesProviderProps>
|
React.PropsWithChildren<MessagesProviderProps>
|
||||||
> = (props) => {
|
> = (props) => {
|
||||||
const { path, children } = props
|
const { path, children } = props
|
||||||
const { authentication } = useAuthentication()
|
const { authentication, user } = useAuthentication()
|
||||||
|
|
||||||
const {
|
const {
|
||||||
items: messages,
|
items: messages,
|
||||||
@ -49,7 +49,10 @@ export const MessagesProvider: React.FC<
|
|||||||
messagesDiv.scrollHeight - messagesDiv.scrollTop <=
|
messagesDiv.scrollHeight - messagesDiv.scrollTop <=
|
||||||
messagesDiv.clientHeight
|
messagesDiv.clientHeight
|
||||||
handleSocketData({ data, setItems })
|
handleSocketData({ data, setItems })
|
||||||
if (data.action === 'create' && isAtBottom) {
|
if (
|
||||||
|
data.action === 'create' &&
|
||||||
|
(isAtBottom || data.item.member.userId === user.id)
|
||||||
|
) {
|
||||||
messagesDiv.scrollTo(0, messagesDiv.scrollHeight)
|
messagesDiv.scrollTo(0, messagesDiv.scrollHeight)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -59,7 +62,7 @@ export const MessagesProvider: React.FC<
|
|||||||
return () => {
|
return () => {
|
||||||
authentication.socket.off('messages')
|
authentication.socket.off('messages')
|
||||||
}
|
}
|
||||||
}, [authentication.socket, setItems, path])
|
}, [authentication.socket, setItems, path, user.id])
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
resetPagination()
|
resetPagination()
|
||||||
|
Reference in New Issue
Block a user