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

feat: add hasNext to usePaginatedParticipants hook #2025

Merged
merged 1 commit into from
Oct 9, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
2 changes: 2 additions & 0 deletions packages/react-sdk/src/hooks/usePaginatedParticipants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export interface usePaginatedParticipantsResult {
* this function is to be called when loadPeers is called atleast once. This will fetch the next batch of peers
*/
loadMorePeers: Promise<void>;
hasNext: () => boolean;
// list of peers loaded
peers: HMSPeer[];
// total number of peers matching the input options at the time of the request
Expand Down Expand Up @@ -48,6 +49,7 @@ export const usePaginatedParticipants = (options: HMSPeerListIteratorOptions) =>
});
setTotal(iterator.current.getTotal());
}),
hasNext: () => iterator.current.hasNext(),
total,
peers: Object.values(peers),
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,14 +68,13 @@ const VirtualizedParticipantItem = React.memo(
);

export const PaginatedParticipants = ({ roleName, onBack }: { roleName: string; onBack: () => void }) => {
const { peers, total, loadPeers, loadMorePeers } = usePaginatedParticipants({ role: roleName, limit: 20 });
const { peers, total, hasNext, loadPeers, loadMorePeers } = usePaginatedParticipants({ role: roleName, limit: 20 });
const [search, setSearch] = useState<string>('');
const filteredPeers = peers.filter(p => p.name?.toLowerCase().includes(search));
const isConnected = useHMSStore(selectIsConnectedToRoom);
const [ref, { width }] = useMeasure<HTMLDivElement>();
const height = ROW_HEIGHT * (filteredPeers.length + 1);
const resetSidePane = useSidepaneReset();
const hasNext = total > peers.length;

useEffect(() => {
loadPeers();
Expand Down Expand Up @@ -111,7 +110,7 @@ export const PaginatedParticipants = ({ roleName, onBack }: { roleName: string;
<Box css={{ flex: '1 1 0', overflowY: 'auto', overflowX: 'hidden', mr: '-$10' }}>
<VariableSizeList
itemSize={index => (index === filteredPeers.length + 1 ? 16 : ROW_HEIGHT)}
itemData={{ peerList: filteredPeers, hasNext, loadMorePeers, isConnected: isConnected === true }}
itemData={{ peerList: filteredPeers, hasNext: hasNext(), loadMorePeers, isConnected: isConnected === true }}
itemKey={itemKey}
itemCount={filteredPeers.length + 1}
width={width}
Expand Down
Loading