-
Notifications
You must be signed in to change notification settings - Fork 10.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Members/Channels list infinite scroll (#28636)
Co-authored-by: Guilherme Jun Grillo <48109548+guijun13@users.noreply.github.com>
- Loading branch information
1 parent
ec4394e
commit abe5fb5
Showing
4 changed files
with
125 additions
and
21 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,39 @@ | ||
import { Box } from '@rocket.chat/fuselage'; | ||
import type { ComponentProps } from 'react'; | ||
import React, { useEffect, useRef } from 'react'; | ||
|
||
type InfiniteListAnchorProps = { | ||
loadMore: () => void; | ||
} & ComponentProps<typeof Box>; | ||
|
||
const InfiniteListAnchor = ({ loadMore, ...props }: InfiniteListAnchorProps) => { | ||
const ref = useRef<HTMLDivElement | null>(null); | ||
|
||
useEffect(() => { | ||
const target = ref.current; | ||
|
||
if (!target) { | ||
return; | ||
} | ||
|
||
const observer = new IntersectionObserver( | ||
(e) => { | ||
if (e[0].isIntersecting) { | ||
loadMore(); | ||
} | ||
}, | ||
{ | ||
root: null, | ||
threshold: 0.1, | ||
}, | ||
); | ||
|
||
observer.observe(target); | ||
|
||
return () => observer.disconnect(); | ||
}, [loadMore]); | ||
|
||
return <Box width={5} height={5} ref={ref} {...props} />; | ||
}; | ||
|
||
export default InfiniteListAnchor; |
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
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
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