@@ -15,6 +15,7 @@ let disableAvatars = false;
1515let rateLimitedMode = false ;
1616let workspaceName = "Slack" ;
1717let addChannelChoices = [ ] ;
18+ let addChannelLoadId = 0 ;
1819
1920// ---------------------------------------------------------------------------
2021// Startup
@@ -377,18 +378,22 @@ function showAddChannelDialog() {
377378 const select = document . getElementById ( "add-channel-select" ) ;
378379 const errorEl = document . getElementById ( "add-channel-error" ) ;
379380 const confirmBtn = document . getElementById ( "btn-add-channel-confirm" ) ;
381+ const cancelBtn = document . getElementById ( "btn-add-channel-cancel" ) ;
382+ const loadId = ++ addChannelLoadId ;
380383 select . innerHTML = '<option value="">Loading channels...</option>' ;
381384 select . disabled = true ;
382385 confirmBtn . disabled = true ;
386+ confirmBtn . textContent = "Add Channel" ;
383387 errorEl . classList . add ( "hidden" ) ;
384388 dialog . classList . remove ( "hidden" ) ;
385- select . focus ( ) ;
389+ cancelBtn . focus ( ) ;
386390 document . addEventListener ( "keydown" , _onDialogKeydown ) ;
387391
388392 Promise . all ( [
389393 bg ( { type : "get_channels" } ) ,
390394 bg ( { type : "get_watched_channels" } ) ,
391395 ] ) . then ( ( [ chanRes , watchedRes ] ) => {
396+ if ( loadId !== addChannelLoadId || dialog . classList . contains ( "hidden" ) ) { return ; }
392397 if ( chanRes . error ) {
393398 errorEl . textContent = `Could not load channels: ${ chanRes . error } ` ;
394399 errorEl . classList . remove ( "hidden" ) ;
@@ -414,11 +419,13 @@ function showAddChannelDialog() {
414419 }
415420
416421 select . innerHTML = addChannelChoices
417- . map ( ( c ) => `<option value="${ escHtml ( c . id ) } "># ${ escHtml ( c . name ) } </option>` )
422+ . map ( ( c ) => `<option value="${ escHtml ( c . id ) } ">${ c . is_private ? "🔒 " : "#" } ${ escHtml ( c . name ) } </option>` )
418423 . join ( "" ) ;
419424 select . disabled = false ;
420425 confirmBtn . disabled = false ;
426+ select . focus ( ) ;
421427 } ) . catch ( ( e ) => {
428+ if ( loadId !== addChannelLoadId || dialog . classList . contains ( "hidden" ) ) { return ; }
422429 errorEl . textContent = `Could not load channels: ${ e . message } ` ;
423430 errorEl . classList . remove ( "hidden" ) ;
424431 select . innerHTML = '<option value="">No channels available</option>' ;
@@ -427,6 +434,8 @@ function showAddChannelDialog() {
427434
428435function hideAddChannelDialog ( ) {
429436 document . getElementById ( "add-channel-dialog" ) . classList . add ( "hidden" ) ;
437+ document . getElementById ( "btn-add-channel-confirm" ) . textContent = "Add Channel" ;
438+ addChannelLoadId ++ ;
430439 addChannelChoices = [ ] ;
431440 document . removeEventListener ( "keydown" , _onDialogKeydown ) ;
432441}
0 commit comments