Skip to content

Commit 9200909

Browse files
authored
1 parent 5d2feff commit 9200909

File tree

3 files changed

+16
-3
lines changed

3 files changed

+16
-3
lines changed

src/modules/GroupChannelList/components/GroupChannelListUI/GroupChannelListUIView.tsx

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@ export interface Props {
2727
renderChannel: (props: { item: GroupChannel; index: number }) => React.ReactElement;
2828

2929
renderAddChannel(): React.ReactElement;
30+
31+
// NOTE: scrollRef is used only for external access (export) and not for internal logic.
32+
scrollRef?: React.RefObject<HTMLDivElement>;
3033
}
3134

3235
export const GroupChannelListUIView = ({
@@ -45,6 +48,8 @@ export const GroupChannelListUIView = ({
4548
renderChannel,
4649

4750
renderAddChannel,
51+
52+
scrollRef,
4853
}: Props) => {
4954
const [showProfileEdit, setShowProfileEdit] = useState(false);
5055
const { stores } = useSendbirdStateContext();
@@ -102,6 +107,7 @@ export const GroupChannelListUIView = ({
102107
placeholderLoading={renderer.placeholder.loading()}
103108
placeholderEmpty={renderer.placeholder.empty()}
104109
placeholderError={renderer.placeholder.error()}
110+
scrollRef={scrollRef}
105111
/>
106112
</React.Fragment>
107113
);
@@ -118,19 +124,20 @@ const ChannelListComponent = <T, >(props: {
118124
data: T[];
119125
renderItem: (props: { item: T; index: number }) => React.ReactNode;
120126
onLoadMore?: () => void;
127+
scrollRef: React.RefObject<HTMLDivElement>;
121128

122129
placeholderLoading?: React.ReactNode;
123130
placeholderEmpty?: React.ReactNode;
124131
placeholderError?: React.ReactNode;
125132
}) => {
126-
const { data, renderItem, onLoadMore, placeholderLoading, placeholderError, placeholderEmpty } = props;
133+
const { data, renderItem, onLoadMore, placeholderLoading, placeholderError, placeholderEmpty, scrollRef } = props;
127134

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

132139
return (
133-
<div className='sendbird-channel-list__body' onScroll={onScroll}>
140+
<div className='sendbird-channel-list__body' onScroll={onScroll} ref={scrollRef}>
134141
{placeholderError}
135142
<div>{data.map((item, index) => renderItem({ item, index }))}</div>
136143
{placeholderLoading}

src/modules/GroupChannelList/components/GroupChannelListUI/index.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ export const GroupChannelListUI = (props: GroupChannelListUIProps) => {
3434
selectedChannelUrl,
3535
loadMore,
3636
onUserProfileUpdated,
37+
scrollRef,
3738
} = useGroupChannelListContext();
3839

3940
const { stores, config } = useSendbirdStateContext();
@@ -89,6 +90,7 @@ export const GroupChannelListUI = (props: GroupChannelListUIProps) => {
8990
onLoadMore={loadMore}
9091
initialized={initialized}
9192
renderAddChannel={() => <AddGroupChannel />}
93+
scrollRef={scrollRef}
9294
/>
9395
);
9496
};

src/modules/GroupChannelList/context/GroupChannelListProvider.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React, { useContext, useEffect, useState } from 'react';
1+
import React, { useContext, useEffect, useRef, useState } from 'react';
22

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

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

84+
const scrollRef = useRef(null);
85+
8386
const channelListDataSource = useGroupChannelList(sdk, {
8487
collectionCreator: getCollectionCreator(sdk, channelListQueryParams),
8588
markAsDelivered: (channels) => channels.forEach(scheduler.push),
@@ -141,6 +144,7 @@ export const GroupChannelListProvider = (props: GroupChannelListProviderProps) =
141144
groupChannels,
142145
refresh,
143146
loadMore,
147+
scrollRef,
144148
}}
145149
>
146150
<UserProfileProvider {...props}>

0 commit comments

Comments
 (0)