Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ export interface Props {
renderChannel: (props: { item: GroupChannel; index: number }) => React.ReactElement;

renderAddChannel(): React.ReactElement;

// NOTE: scrollRef is used only for external access (export) and not for internal logic.
scrollRef?: React.RefObject<HTMLDivElement>;
}

export const GroupChannelListUIView = ({
Expand All @@ -45,6 +48,8 @@ export const GroupChannelListUIView = ({
renderChannel,

renderAddChannel,

scrollRef,
}: Props) => {
const [showProfileEdit, setShowProfileEdit] = useState(false);
const { stores } = useSendbirdStateContext();
Expand Down Expand Up @@ -102,6 +107,7 @@ export const GroupChannelListUIView = ({
placeholderLoading={renderer.placeholder.loading()}
placeholderEmpty={renderer.placeholder.empty()}
placeholderError={renderer.placeholder.error()}
scrollRef={scrollRef}
/>
</React.Fragment>
);
Expand All @@ -118,19 +124,20 @@ const ChannelListComponent = <T, >(props: {
data: T[];
renderItem: (props: { item: T; index: number }) => React.ReactNode;
onLoadMore?: () => void;
scrollRef: React.RefObject<HTMLDivElement>;

placeholderLoading?: React.ReactNode;
placeholderEmpty?: React.ReactNode;
placeholderError?: React.ReactNode;
}) => {
const { data, renderItem, onLoadMore, placeholderLoading, placeholderError, placeholderEmpty } = props;
const { data, renderItem, onLoadMore, placeholderLoading, placeholderError, placeholderEmpty, scrollRef } = props;

const onScroll = useOnScrollPositionChangeDetector({
onReachedBottom: () => onLoadMore?.(),
});

return (
<div className='sendbird-channel-list__body' onScroll={onScroll}>
<div className='sendbird-channel-list__body' onScroll={onScroll} ref={scrollRef}>
{placeholderError}
<div>{data.map((item, index) => renderItem({ item, index }))}</div>
{placeholderLoading}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ export const GroupChannelListUI = (props: GroupChannelListUIProps) => {
selectedChannelUrl,
loadMore,
onUserProfileUpdated,
scrollRef,
} = useGroupChannelListContext();

const { stores, config } = useSendbirdStateContext();
Expand Down Expand Up @@ -89,6 +90,7 @@ export const GroupChannelListUI = (props: GroupChannelListUIProps) => {
onLoadMore={loadMore}
initialized={initialized}
renderAddChannel={() => <AddGroupChannel />}
scrollRef={scrollRef}
/>
);
};
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useContext, useEffect, useState } from 'react';
import React, { useContext, useEffect, useRef, useState } from 'react';

import type { User } from '@sendbird/chat';
import type { GroupChannel, GroupChannelCreateParams, GroupChannelFilterParams } from '@sendbird/chat/groupChannel';
Expand Down Expand Up @@ -45,6 +45,7 @@ interface ContextBaseType {

export interface GroupChannelListContextType extends ContextBaseType, ChannelListDataSource {
typingChannelUrls: string[];
scrollRef: React.RefObject<HTMLDivElement>;
}
export interface GroupChannelListProviderProps extends
PartialRequired<ContextBaseType, 'onChannelSelect' | 'onChannelCreated'>,
Expand Down Expand Up @@ -80,6 +81,8 @@ export const GroupChannelListProvider = (props: GroupChannelListProviderProps) =
const isConnected = useOnlineStatus(sdk, config.logger);
const scheduler = useMarkAsDeliveredScheduler({ isConnected }, config);

const scrollRef = useRef(null);

const channelListDataSource = useGroupChannelList(sdk, {
collectionCreator: getCollectionCreator(sdk, channelListQueryParams),
markAsDelivered: (channels) => channels.forEach(scheduler.push),
Expand Down Expand Up @@ -141,6 +144,7 @@ export const GroupChannelListProvider = (props: GroupChannelListProviderProps) =
groupChannels,
refresh,
loadMore,
scrollRef,
}}
>
<UserProfileProvider {...props}>
Expand Down