Skip to content

Commit 7389c50

Browse files
authored
bug-fix: Fix a bug in ChannelList where activeChannelUrl is set but onChannelSelect fires with null after loading ChannelList (#953)
Fixes: [CLNP-2162](https://sendbird.atlassian.net/browse/CLNP-2162) The bug has been reported by an external user, @aldenquimby original PR: #950 This PR duplicates above. ### Changelogs - Fixed a bug in `ChannelList` where `activeChannelUrl` is set but `onChannelSelect` fires with null after loading `ChannelList` [CLNP-2162]: https://sendbird.atlassian.net/browse/CLNP-2162?atlOrigin=eyJpIjoiNWRkNTljNzYxNjVmNDY3MDlhMDU5Y2ZhYzA5YTRkZjUiLCJwIjoiZ2l0aHViLWNvbS1KU1cifQ
1 parent a6cb95b commit 7389c50

File tree

2 files changed

+17
-4
lines changed

2 files changed

+17
-4
lines changed

src/modules/ChannelList/dux/__tests__/reducers.spec.js

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,24 @@ 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);
19+
// if INIT_CHANNELS_SUCCESS comes back _after_ SET_CURRENT_CHANNEL via activeChannelUrl, don't wipe active channel
20+
it('should not override current channel if disableAutoSelect channels on INIT_CHANNELS_SUCCESS', () => {
21+
const nextState = reducers({
22+
...initialState,
23+
currentChannel: mockData.allChannels[0],
24+
}, {
25+
type: actionTypes.INIT_CHANNELS_SUCCESS,
26+
payload: { channelList: mockData.allChannels, disableAutoSelect: true },
2227
});
2328

29+
expect(nextState.currentChannel.url).toEqual(mockData.allChannels[0].url);
30+
});
31+
32+
// https://sendbird.atlassian.net/browse/UIKIT-2158
33+
it('should check if ITNITAL_LOADING state is true', () => {
34+
expect(initialState.loading).toEqual(true);
35+
});
36+
2437
it('should handle create new channel using CREATE_CHANNEL', () => {
2538
const newChannel = mockData.allChannels[1];
2639
const nextState = reducers(mockData, {

src/modules/ChannelList/dux/reducers.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ export default function channelListReducer(
2929
allChannels: channelList,
3030
disableAutoSelect,
3131
currentChannel:
32-
!disableAutoSelect && channelList && channelList.length && channelList.length > 0 ? channelList[0] : null,
32+
!disableAutoSelect && channelList && channelList.length && channelList.length > 0 ? channelList[0] : state.currentChannel,
3333
};
3434
})
3535
.with({ type: channelListActions.REFRESH_CHANNELS_SUCCESS }, (action) => {

0 commit comments

Comments
 (0)