Skip to content

Commit 4108dad

Browse files
Sravan Ssravan-s
authored andcommitted
feat: add new props isLoading to ChannelUI (#350)
It is better to have separate prop to show loader in channel, because, other customers might have used empty/null to show invalid channel and it would be a breaking change for them Usage: ``` <Channel channelUrl={currentChannelUrl} isLoading={!currentChannelUrl} /> ```## External Contributions
1 parent 9bfaca7 commit 4108dad

File tree

8 files changed

+27
-3
lines changed

8 files changed

+27
-3
lines changed

scripts/index_d_ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -469,6 +469,7 @@ declare module "SendbirdUIKitGlobal" {
469469
};
470470

471471
export interface ChannelUIProps {
472+
isLoading?: boolean;
472473
renderPlaceholderLoader?: () => React.ReactNode | React.ReactElement;
473474
renderPlaceholderInvalid?: () => React.ReactNode | React.ReactElement;
474475
renderPlaceholderEmpty?: () => React.ReactNode | React.ReactElement;

src/smart-components/Channel/components/ChannelUI/index.tsx

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import { RenderCustomSeparatorProps, RenderMessageProps } from '../../../../type
1616
import * as messageActionTypes from '../../context/dux/actionTypes';
1717

1818
export interface ChannelUIProps {
19+
isLoading?: boolean;
1920
renderPlaceholderLoader?: () => React.ReactElement;
2021
renderPlaceholderInvalid?: () => React.ReactElement;
2122
renderPlaceholderEmpty?: () => React.ReactElement;
@@ -27,6 +28,7 @@ export interface ChannelUIProps {
2728
}
2829

2930
const ChannelUI: React.FC<ChannelUIProps> = ({
31+
isLoading,
3032
renderPlaceholderLoader,
3133
renderPlaceholderInvalid,
3234
renderPlaceholderEmpty,
@@ -59,6 +61,16 @@ const ChannelUI: React.FC<ChannelUIProps> = ({
5961
const logger = globalStore?.config?.logger;
6062
const isOnline = globalStore?.config?.isOnline;
6163

64+
if (isLoading) {
65+
return (<div className="sendbird-conversation">
66+
{
67+
renderPlaceholderInvalid?.() || (
68+
<PlaceHolder type={PlaceHolderTypes.LOADING} />
69+
)
70+
}
71+
</div>);
72+
}
73+
6274
if (!channelUrl) {
6375
return (<div className="sendbird-conversation">
6476
{

src/smart-components/Channel/context/dux/__tests__/reducers.spec.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,11 @@ describe('Messages-Reducers', () => {
1717
expect(nextState.loading).toEqual(true);
1818
});
1919

20+
// https://sendbird.atlassian.net/browse/UIKIT-2158
21+
it('should check if ITNITAL_LOADING state is true', () => {
22+
expect(initialState.loading).toEqual(true);
23+
});
24+
2025
it('should initialize messages FETCH_INITIAL_MESSAGES_SUCCESS', () => {
2126
const mockData = generateMockChannel();
2227
const nextState = reducers(stateWithCurrentChannel, {

src/smart-components/Channel/context/dux/initialState.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
export default {
22
initialized: false,
3-
loading: false,
3+
loading: true,
44
allMessages: [],
55
currentGroupChannel: { members: [] },
66
// for scrollup

src/smart-components/Channel/index.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ const Channel: React.FC<ChannelProps> = (props: ChannelProps) => {
3030
disableMarkAsRead={props?.disableMarkAsRead}
3131
>
3232
<ChannelUI
33+
isLoading={props?.isLoading}
3334
renderPlaceholderLoader={props?.renderPlaceholderLoader}
3435
renderPlaceholderInvalid={props?.renderPlaceholderInvalid}
3536
renderPlaceholderEmpty={props?.renderPlaceholderEmpty}

src/smart-components/ChannelList/components/ChannelListUI/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ const ChannelListUI: React.FC<ChannelListUIProps> = (props: ChannelListUIProps)
159159
}}
160160
>
161161
{
162-
(sdkError) && (
162+
(sdkError && !loading) && (
163163
(renderPlaceHolderError && typeof renderPlaceHolderError === 'function') ? (
164164
renderPlaceHolderError?.()
165165
) : (

src/smart-components/ChannelList/dux/__tests__/reducers.spec.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,11 @@ describe('Channels-Reducers', () => {
1616
expect(nextState.currentChannel.url).toEqual(mockData.allChannels[0].url);
1717
});
1818

19+
// https://sendbird.atlassian.net/browse/UIKIT-2158
20+
it('should check if ITNITAL_LOADING state is true', () => {
21+
expect(initialState.loading).toEqual(true);
22+
});
23+
1924
it('should handle create new channel using CREATE_CHANNEL', () => {
2025
const nextState = reducers(mockData, {
2126
type: actionTypes.CREATE_CHANNEL,

src/smart-components/ChannelList/dux/initialState.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
export default {
22
// we might not need this initialized state -> should remove
33
initialized: false,
4-
loading: false,
4+
loading: true,
55
allChannels: [],
66
currentChannel: null,
77
showSettings: false,

0 commit comments

Comments
 (0)