Skip to content

Commit 29daf15

Browse files
authored
fix: Active channel url causes flicker of current channel on the channel list (#517)
### Description Of Changes Issue * The activated channel flickers between the previous current channel and a new channel after creating the new group channel * Infinite loop * (1) `Creating a channel` causes the change of the channel list * (2) `useActiveChannelUrl` is triggered by the channel list change * (3) `useActiveChannelUrl` set the current channel to the previous channel Fix * Remove the channel list dependency from the `useEffect` of useActiveChannelUrl to fix the current channel flickers on the channel list
1 parent 245fda2 commit 29daf15

File tree

5 files changed

+14
-15
lines changed

5 files changed

+14
-15
lines changed

src/modules/App/MobileLayout.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ export const MobileLayout: React.FC<MobileLayoutProps> = (
107107
<div className='sb_mobile__panelwrap'>
108108
<Channel
109109
replyType={replyType}
110-
channelUrl={currentChannel?.url}
110+
channelUrl={currentChannel?.url || ''}
111111
onSearchClick={() => {
112112
setPanel(PANELS.MESSAGE_SEARCH);
113113
}}
@@ -130,7 +130,7 @@ export const MobileLayout: React.FC<MobileLayoutProps> = (
130130
panel === PANELS?.CHANNEL_SETTINGS && (
131131
<div className='sb_mobile__panelwrap'>
132132
<ChannelSettings
133-
channelUrl={currentChannel?.url}
133+
channelUrl={currentChannel?.url || ''}
134134
onCloseClick={() => {
135135
setPanel(PANELS.CHANNEL);
136136
}}
@@ -145,7 +145,7 @@ export const MobileLayout: React.FC<MobileLayoutProps> = (
145145
panel === PANELS?.MESSAGE_SEARCH && (
146146
<div className='sb_mobile__panelwrap'>
147147
<MessageSearch
148-
channelUrl={currentChannel?.url}
148+
channelUrl={currentChannel?.url || ''}
149149
onCloseClick={() => {
150150
setPanel(PANELS.CHANNEL);
151151
}}

src/modules/App/index.jsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,15 +79,15 @@ export default function App(props) {
7979
replyType={replyType}
8080
>
8181
<AppLayout
82-
currentChannel={currentChannel}
83-
setCurrentChannel={setCurrentChannel}
8482
isReactionEnabled={isReactionEnabled}
8583
replyType={replyType}
8684
isMessageGroupingEnabled={isMessageGroupingEnabled}
8785
allowProfileEdit={allowProfileEdit}
8886
showSearchIcon={showSearchIcon}
8987
onProfileEditSuccess={onProfileEditSuccess}
9088
disableAutoSelect={disableAutoSelect}
89+
currentChannel={currentChannel}
90+
setCurrentChannel={setCurrentChannel}
9191
/>
9292
</Sendbird>
9393
);

src/modules/App/types.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import type { User } from '@sendbird/chat';
2-
import type { GroupChannel } from '@sendbird/chat/groupChannel';
2+
import { GroupChannel } from '@sendbird/chat/groupChannel';
33
import type { FileMessage, UserMessage } from '@sendbird/chat/message';
44

55
import type { Locale } from 'date-fns';
@@ -20,7 +20,7 @@ export interface AppLayoutProps {
2020
onProfileEditSuccess?(user: User): void;
2121
disableAutoSelect?: boolean;
2222
currentChannel?: GroupChannel;
23-
setCurrentChannel?: React.Dispatch<GroupChannel>;
23+
setCurrentChannel: React.Dispatch<GroupChannel>;
2424
}
2525

2626
export interface MobileLayoutProps extends AppLayoutProps {

src/modules/ChannelList/context/ChannelListProvider.tsx

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ export interface ChannelListProviderProps {
8181
overrideInviteUser?(params: OverrideInviteUserType): void;
8282
onThemeChange?(theme: string): void;
8383
onProfileEditSuccess?(user: User): void;
84-
onChannelSelect?(channel: GroupChannel): void;
84+
onChannelSelect?(channel: GroupChannel | null): void;
8585
sortChannelList?: (channels: GroupChannel[]) => GroupChannel[];
8686
queries?: ChannelListQueries;
8787
children?: React.ReactElement;
@@ -104,7 +104,7 @@ export interface ChannelListProviderInterface extends ChannelListProviderProps {
104104
channelListQuery: GroupChannelListQuery;
105105
currentUserId: string;
106106
channelListDispatcher: CustomUseReducerDispatcher;
107-
channelSource: GroupChannelListQuerySb;
107+
channelSource: GroupChannelListQuerySb | null;
108108
}
109109

110110
interface ChannelListStoreInterface {
@@ -188,12 +188,12 @@ const ChannelListProvider: React.FC<ChannelListProviderProps> = (props: ChannelL
188188
channelListReducers,
189189
channelListInitialState,
190190
) as [ChannelListStoreInterface, CustomUseReducerDispatcher];
191-
const { loading, currentChannel } = channelListStore;
191+
const { currentChannel } = channelListStore;
192192

193-
const [channelSource, setChannelSource] = useState<GroupChannelListQuerySb>();
193+
const [channelSource, setChannelSource] = useState<GroupChannelListQuerySb | null>(null);
194194
const [typingChannels, setTypingChannels] = useState<Array<GroupChannel>>([]);
195195

196-
const [channelsTomarkAsRead, setChannelsToMarkAsRead] = useState([]);
196+
const [channelsTomarkAsRead, setChannelsToMarkAsRead] = useState<Array<GroupChannel>>([]);
197197
useEffect(() => {
198198
// https://stackoverflow.com/a/60907638
199199
let isMounted = true;
@@ -378,7 +378,6 @@ const ChannelListProvider: React.FC<ChannelListProviderProps> = (props: ChannelL
378378
overrideInviteUser,
379379
onChannelSelect,
380380
sortChannelList,
381-
loading,
382381
allowProfileEdit: enableEditProfile,
383382
channelListDispatcher,
384383
channelSource,

src/modules/ChannelList/context/hooks/useActiveChannelUrl.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ function useActiveChannelUrl({
2525
return useEffect(() => {
2626
if (activeChannelUrl) {
2727
logger.info('ChannelListProvider: looking for active channel', { activeChannelUrl });
28-
const activeChannel = channels.find(channel => channel.url === activeChannelUrl);
28+
const activeChannel = channels?.find(channel => channel.url === activeChannelUrl);
2929
if (activeChannel) {
3030
channelListDispatcher({
3131
type: messageActionTypes.SET_CURRENT_CHANNEL,
@@ -49,7 +49,7 @@ function useActiveChannelUrl({
4949
});
5050
}
5151
}
52-
}, [activeChannelUrl, channels, sdk]);
52+
}, [activeChannelUrl]);
5353
}
5454

5555
export default useActiveChannelUrl;

0 commit comments

Comments
 (0)