@@ -11,16 +11,18 @@ export default function reducer(state, action) {
1111 } ;
1212 case actions . RESET_CHANNEL_LIST :
1313 return initialState ;
14- case actions . INIT_CHANNELS_SUCCESS :
14+ case actions . INIT_CHANNELS_SUCCESS : {
15+ const nextChannel = ( action . payload && action . payload . length && action . payload . length > 0 )
16+ ? action . payload [ 0 ] . url
17+ : null ;
1518 return {
1619 ...state ,
1720 initialized : true ,
1821 loading : false ,
1922 allChannels : action . payload ,
20- currentChannel : ( action . payload && action . payload . length && action . payload . length > 0 )
21- ? action . payload [ 0 ] . url
22- : null ,
23+ currentChannel : state . disableAutoSelect ? null : nextChannel ,
2324 } ;
25+ }
2426 case actions . FETCH_CHANNELS_SUCCESS : {
2527 const currentChannels = state . allChannels . map ( ( c ) => c . url ) ;
2628 const filteredChannels = action . payload . filter (
@@ -64,22 +66,24 @@ export default function reducer(state, action) {
6466 } ;
6567 }
6668 }
69+ const nextChannel = ( channel . url === state . currentChannel )
70+ ? state . allChannels [ state . allChannels [ 0 ] . url === channel . url ? 1 : 0 ] . url
71+ : state . currentChannel ;
6772 return {
6873 ...state ,
69- currentChannel : ( channel . url === state . currentChannel )
70- ? state . allChannels [ state . allChannels [ 0 ] . url === channel . url ? 1 : 0 ] . url
71- : state . currentChannel ,
74+ currentChannel : state . disableAutoSelect ? null : nextChannel ,
7275 allChannels : state . allChannels . filter ( ( { url } ) => url !== channel . url ) ,
7376 } ;
7477 }
7578 case actions . LEAVE_CHANNEL_SUCCESS :
7679 case actions . ON_CHANNEL_DELETED : {
7780 const channelUrl = action . payload ;
81+ const nextChannel = ( channelUrl === state . currentChannel )
82+ ? state . allChannels [ 0 ] . url
83+ : state . currentChannel ;
7884 return {
7985 ...state ,
80- currentChannel : ( channelUrl === state . currentChannel )
81- ? state . allChannels [ 0 ] . url
82- : state . currentChannel ,
86+ currentChannel : state . disableAutoSelect ? null : nextChannel ,
8387 allChannels : state . allChannels . filter ( ( { url } ) => url !== channelUrl ) ,
8488 } ;
8589 }
@@ -88,28 +92,31 @@ export default function reducer(state, action) {
8892 if ( state . channelListQuery ) {
8993 if ( filterChannelListParams ( state . channelListQuery , channel , state . currentUserId ) ) {
9094 const filteredChannels = getChannelsWithUpsertedChannel ( state . allChannels , channel ) ;
95+ const nextChannel = ( isMe && ( channel . url === state . currentChannel ) )
96+ ? filteredChannels [ 0 ] . url
97+ : state . currentChannel ;
9198 return {
9299 ...state ,
93- currentChannel : ( isMe && ( channel . url === state . currentChannel ) )
94- ? filteredChannels [ 0 ] . url
95- : state . currentChannel ,
100+ currentChannel : state . disableAutoSelect ? null : nextChannel ,
96101 allChannels : filteredChannels ,
97102 } ;
98103 }
104+ const nextChannel = ( channel . url === state . currentChannel )
105+ ? state . allChannels [ 0 ] . url
106+ : state . currentChannel ;
99107 return {
100108 ...state ,
101- currentChannel : ( channel . url === state . currentChannel )
102- ? state . allChannels [ 0 ] . url
103- : state . currentChannel ,
109+ currentChannel : state . disableAutoSelect ? null : nextChannel ,
104110 allChannels : state . allChannels . filter ( ( { url } ) => url !== channel . url ) ,
105111 } ;
106112 }
107113 const filteredChannels = state . allChannels . filter ( ( c ) => ! ( c . url === channel . url && isMe ) ) ;
114+ const nextChannel = ( isMe && ( channel . url === state . currentChannel ) )
115+ ? filteredChannels [ 0 ] . url
116+ : state . currentChannel ;
108117 return {
109118 ...state ,
110- currentChannel : ( isMe && ( channel . url === state . currentChannel ) )
111- ? filteredChannels [ 0 ] . url
112- : state . currentChannel ,
119+ currentChannel : state . disableAutoSelect ? null : nextChannel ,
113120 allChannels : filteredChannels ,
114121 } ;
115122 }
@@ -128,12 +135,13 @@ export default function reducer(state, action) {
128135 allChannels : getChannelsWithUpsertedChannel ( allChannels , channel ) ,
129136 } ;
130137 }
138+ const nextChannel = ( channel . url === state . currentChannel )
139+ ? state . allChannels [ state . allChannels [ 0 ] . url === channel . url ? 1 : 0 ] . url
140+ // if coming channel is first of channel list, current channel will be the next one
141+ : state . currentChannel ;
131142 return {
132143 ...state ,
133- currentChannel : ( channel . url === state . currentChannel )
134- ? state . allChannels [ state . allChannels [ 0 ] . url === channel . url ? 1 : 0 ] . url
135- // if coming channel is first of channel list, current channel will be the next one
136- : state . currentChannel ,
144+ currentChannel : state . disableAutoSelect ? null : nextChannel ,
137145 allChannels : state . allChannels . filter ( ( { url } ) => url !== channel . url ) ,
138146 } ;
139147 }
@@ -186,12 +194,13 @@ export default function reducer(state, action) {
186194 allChannels : getChannelsWithUpsertedChannel ( state . allChannels , channel ) ,
187195 } ;
188196 }
197+ const nextChannel = ( channel . url === state . currentChannel )
198+ ? state . allChannels [ state . allChannels [ 0 ] . url === channel . url ? 1 : 0 ] . url
199+ // if coming channel is first of channel list, current channel will be the next one
200+ : state . currentChannel ;
189201 return {
190202 ...state ,
191- currentChannel : ( channel . url === state . currentChannel )
192- ? state . allChannels [ state . allChannels [ 0 ] . url === channel . url ? 1 : 0 ] . url
193- // if coming channel is first of channel list, current channel will be the next one
194- : state . currentChannel ,
203+ currentChannel : state . disableAutoSelect ? null : nextChannel ,
195204 allChannels : state . allChannels . filter ( ( { url } ) => url !== channel . url ) ,
196205 } ;
197206 }
@@ -216,12 +225,13 @@ export default function reducer(state, action) {
216225 allChannels : getChannelsWithUpsertedChannel ( state . allChannels , channel ) ,
217226 } ;
218227 }
228+ const nextChannel = ( channel . url === state . currentChannel )
229+ ? state . allChannels [ state . allChannels [ 0 ] . url === channel . url ? 1 : 0 ] . url
230+ // if coming channel is first of channel list, current channel will be the next one
231+ : state . currentChannel ;
219232 return {
220233 ...state ,
221- currentChannel : ( channel . url === state . currentChannel )
222- ? state . allChannels [ state . allChannels [ 0 ] . url === channel . url ? 1 : 0 ] . url
223- // if coming channel is first of channel list, current channel will be the next one
224- : state . currentChannel ,
234+ currentChannel : state . disableAutoSelect ? null : nextChannel ,
225235 allChannels : state . allChannels . filter ( ( { url } ) => url !== channel . url ) ,
226236 } ;
227237 }
@@ -252,6 +262,11 @@ export default function reducer(state, action) {
252262 currentUserId : action . payload . currentUserId ,
253263 channelListQuery : action . payload . channelListQuery ,
254264 } ;
265+ case actions . SET_AUTO_SELECT_CHANNEL_ITEM :
266+ return {
267+ ...state ,
268+ disableAutoSelect : action . payload ,
269+ } ;
255270 default :
256271 return state ;
257272 }
0 commit comments