-
Notifications
You must be signed in to change notification settings - Fork 11k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Room history scroll position (#29335)
Co-authored-by: gabriellsh <[email protected]>
- Loading branch information
1 parent
059a92e
commit cebe359
Showing
3 changed files
with
33 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'@rocket.chat/meteor': minor | ||
--- | ||
|
||
fix: Room history scrollbar position |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
apps/meteor/client/views/room/components/body/hooks/useRestoreScrollPosition.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import type { IRoom } from '@rocket.chat/core-typings'; | ||
import { useEffect } from 'react'; | ||
|
||
import type { MessageListContextValue } from '../../../../../components/message/list/MessageListContext'; | ||
import { RoomManager } from '../../../../../lib/RoomManager'; | ||
|
||
export function useRestoreScrollPosition( | ||
roomId: IRoom['_id'], | ||
scrollMessageList: Exclude<MessageListContextValue['scrollMessageList'], undefined>, | ||
sendToBottom: () => void, | ||
) { | ||
useEffect(() => { | ||
const store = RoomManager.getStore(roomId); | ||
|
||
if (store?.scroll && !store.atBottom) { | ||
scrollMessageList(() => { | ||
return { left: 30, top: store.scroll }; | ||
}); | ||
} else { | ||
sendToBottom(); | ||
} | ||
}, [roomId, scrollMessageList, sendToBottom]); | ||
} |