Skip to content

Commit 61b7534

Browse files
authored
fix: loading status should be handled in message list (#970)
## Description https://github.com/sendbird/sendbird-uikit-react/blob/v3.10.0/src/modules/Channel/components/ChannelUI/index.tsx#L59-L67 Upon reviewing the `v3.10.0` code, I noticed that the actual loading of the message list is handled in the **MessageList** component, while the loading state displayed in the `ChannelUI` relies solely on a prop called `isLoading`. During the migration process in this area, a mistake was made. I left a note indicating the purpose of this, as I'm unsure of its intended use. Additionally, due to the change in `isLoading` being optional, the condition for `isInvalid` became invalid in the GroupChannel module. Therefore, I added a separate fetch error to the context. ticket: [CLNP-2259] [CLNP-2259]: https://sendbird.atlassian.net/browse/CLNP-2259?atlOrigin=eyJpIjoiNWRkNTljNzYxNjVmNDY3MDlhMDU5Y2ZhYzA5YTRkZjUiLCJwIjoiZ2l0aHViLWNvbS1KU1cifQ
1 parent 3c270dd commit 61b7534

File tree

4 files changed

+24
-12
lines changed

4 files changed

+24
-12
lines changed

src/modules/Channel/components/ChannelUI/index.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ export interface ChannelUIProps extends GroupChannelUIBasicProps {
1313

1414
const ChannelUI = (props: ChannelUIProps) => {
1515
const context = useChannelContext();
16-
const { channelUrl, isInvalid, loading } = context;
16+
const { channelUrl, isInvalid } = context;
1717

1818
// Inject components to presentation layer
1919
const {
@@ -26,7 +26,7 @@ const ChannelUI = (props: ChannelUIProps) => {
2626
<GroupChannelUIView
2727
{...props}
2828
{...context}
29-
loading={props?.isLoading ?? loading}
29+
isLoading={props?.isLoading}
3030
isInvalid={isInvalid}
3131
channelUrl={channelUrl}
3232
renderChannelHeader={renderChannelHeader}

src/modules/GroupChannel/components/GroupChannelUI/GroupChannelUIView.tsx

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ export interface GroupChannelUIBasicProps {
3737
}
3838

3939
export interface GroupChannelUIViewProps extends GroupChannelUIBasicProps {
40-
loading: boolean;
40+
isLoading?: boolean;
4141
isInvalid: boolean;
4242
channelUrl: string;
4343
renderChannelHeader: GroupChannelUIBasicProps['renderChannelHeader'];
@@ -47,7 +47,7 @@ export interface GroupChannelUIViewProps extends GroupChannelUIBasicProps {
4747

4848
export const GroupChannelUIView = (props: GroupChannelUIViewProps) => {
4949
const {
50-
loading,
50+
isLoading,
5151
isInvalid,
5252
channelUrl,
5353
renderChannelHeader,
@@ -62,7 +62,9 @@ export const GroupChannelUIView = (props: GroupChannelUIViewProps) => {
6262
const sdkError = stores?.sdkStore?.error;
6363
const { logger, isOnline } = config;
6464

65-
if (loading) {
65+
// Note: This is not a loading status of the message list.
66+
// It is just for custom props from the Channel module and is not used in the GroupChannel module. (We should remove this in v4)
67+
if (isLoading) {
6668
return <div className="sendbird-conversation">{renderPlaceholderLoader?.() || <PlaceHolder type={PlaceHolderTypes.LOADING} />}</div>;
6769
}
6870

src/modules/GroupChannel/components/GroupChannelUI/index.tsx

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ export interface GroupChannelUIProps extends GroupChannelUIBasicProps {}
1111

1212
export const GroupChannelUI = (props: GroupChannelUIProps) => {
1313
const context = useGroupChannelContext();
14-
const { currentChannel, channelUrl, loading } = context;
14+
const { channelUrl, fetchChannelError } = context;
1515

1616
// Inject components to presentation layer
1717
const {
@@ -24,8 +24,7 @@ export const GroupChannelUI = (props: GroupChannelUIProps) => {
2424
<GroupChannelUIView
2525
{...props}
2626
{...context}
27-
loading={loading}
28-
isInvalid={channelUrl && !currentChannel}
27+
isInvalid={fetchChannelError !== null}
2928
channelUrl={channelUrl}
3029
renderChannelHeader={renderChannelHeader}
3130
renderMessageList={renderMessageList}

src/modules/GroupChannel/context/GroupChannelProvider.tsx

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import React, { useContext, useEffect, useMemo, useRef, useState } from 'react';
2-
import type { User } from '@sendbird/chat';
2+
import type { SendbirdError, User } from '@sendbird/chat';
33
import {
44
FileMessageCreateParams,
55
MultipleFilesMessageCreateParams,
@@ -76,6 +76,7 @@ interface ContextBaseType {
7676

7777
export interface GroupChannelContextType extends ContextBaseType, MessageListDataSourceWithoutActions, MessageActions {
7878
currentChannel: GroupChannel | null;
79+
fetchChannelError: SendbirdError | null;
7980
nicknamesMap: Map<string, string>;
8081

8182
scrollRef: React.MutableRefObject<HTMLDivElement>;
@@ -141,6 +142,7 @@ export const GroupChannelProvider = (props: GroupChannelProviderProps) => {
141142
const [quoteMessage, setQuoteMessage] = useState<SendableMessageType>(null);
142143
const [animatedMessageId, setAnimatedMessageId] = useState(0);
143144
const [currentChannel, setCurrentChannel] = useState<GroupChannel | null>(null);
145+
const [fetchChannelError, setFetchChannelError] = useState<SendbirdError>(null);
144146

145147
// Ref
146148
const { scrollRef, scrollPubSub, scrollDistanceFromBottomRef, isScrollBottomReached, setIsScrollBottomReached } = useMessageListScroll();
@@ -180,8 +182,14 @@ export const GroupChannelProvider = (props: GroupChannelProviderProps) => {
180182
scrollPubSub.publish('scrollToBottom', null);
181183
}
182184
},
183-
onChannelDeleted: () => setCurrentChannel(null),
184-
onCurrentUserBanned: () => setCurrentChannel(null),
185+
onChannelDeleted: () => {
186+
setCurrentChannel(null);
187+
setFetchChannelError(null);
188+
},
189+
onCurrentUserBanned: () => {
190+
setCurrentChannel(null);
191+
setFetchChannelError(null);
192+
},
185193
onChannelUpdated: (channel) => setCurrentChannel(channel),
186194
logger: config.logger,
187195
});
@@ -244,8 +252,10 @@ export const GroupChannelProvider = (props: GroupChannelProviderProps) => {
244252
try {
245253
const channel = await sdkStore.sdk.groupChannel.getChannel(channelUrl);
246254
setCurrentChannel(channel);
247-
} catch {
255+
setFetchChannelError(null);
256+
} catch (error) {
248257
setCurrentChannel(null);
258+
setFetchChannelError(error);
249259
} finally {
250260
// Reset states when channel changes
251261
setQuoteMessage(null);
@@ -390,6 +400,7 @@ export const GroupChannelProvider = (props: GroupChannelProviderProps) => {
390400

391401
// Internal Interface
392402
currentChannel,
403+
fetchChannelError,
393404
nicknamesMap,
394405

395406
scrollRef,

0 commit comments

Comments
 (0)