@@ -22,9 +22,10 @@ import { HighlightedText } from "./HighlightedText";
2222import { TocItem } from "../../structure/TocItem" ;
2323
2424import { ResolveQuestionButton } from "./ResolveQuestionButton" ;
25- import "./SlackActiveQuestions.css" ;
2625import { removeTrailingSlashFromQueryParam } from "./queryParamUtils" ;
2726
27+ import "./SlackActiveQuestions.css" ;
28+
2829interface Question {
2930 id : string ;
3031 selectedText : string ;
@@ -37,9 +38,34 @@ interface Question {
3738 resolved : boolean ;
3839}
3940
41+ let slackConnectionDismissed = false ;
42+
43+ function SlackConnectionIndicator ( { onDismiss } : { onDismiss : ( ) => void } ) {
44+ const handleDismiss = ( ) => {
45+ slackConnectionDismissed = true ;
46+ onDismiss ( ) ;
47+ } ;
48+
49+ return (
50+ < div className = "znai-slack-connection-indicator" >
51+ < div className = "znai-slack-connection-content" >
52+ < span className = "znai-slack-connection-message" > Slack conversations are offline</ span >
53+ < button
54+ className = "znai-slack-connection-close"
55+ onClick = { handleDismiss }
56+ aria-label = "Dismiss Slack connection indicator"
57+ >
58+ ✕
59+ </ button >
60+ </ div >
61+ </ div >
62+ ) ;
63+ }
64+
4065export function SlackActiveQuestions ( { containerNode, tocItem } : { containerNode : HTMLElement ; tocItem : TocItem } ) {
4166 const [ questions , setQuestions ] = useState < Question [ ] > ( [ ] ) ;
4267 const [ notification , setNotification ] = useState < { type : "success" | "error" ; message : string } | null > ( null ) ;
68+ const [ showConnectionIndicator , setShowConnectionIndicator ] = useState ( false ) ;
4369
4470 const params = new URLSearchParams ( window . location . search ) ;
4571 const questionId = params . get ( "questionId" ) || "" ;
@@ -80,11 +106,18 @@ export function SlackActiveQuestions({ containerNode, tocItem }: { containerNode
80106 } ) ) ;
81107 setQuestions ( questions ) ;
82108 } else {
83- setNotification ( { type : "error" , message : `Failed to fetch slack questions: ${ response . statusText } ` } ) ;
109+ handleFetchError ( `Failed to fetch slack questions: ${ response . status } ${ response . statusText } ` ) ;
84110 setQuestions ( [ ] ) ;
85111 }
86112 } catch ( err ) {
87- setNotification ( { type : "error" , message : `Failed to fetch slack questions: ${ err } ` } ) ;
113+ handleFetchError ( `Failed to fetch slack questions: ${ err } ` ) ;
114+ }
115+ }
116+
117+ function handleFetchError ( errorMessage : string ) {
118+ console . error ( errorMessage ) ;
119+ if ( ! slackConnectionDismissed ) {
120+ setShowConnectionIndicator ( true ) ;
88121 }
89122 }
90123
@@ -150,6 +183,7 @@ export function SlackActiveQuestions({ containerNode, tocItem }: { containerNode
150183 return (
151184 < >
152185 { renderedQuestions }
186+ { showConnectionIndicator && < SlackConnectionIndicator onDismiss = { ( ) => setShowConnectionIndicator ( false ) } /> }
153187 { notification && (
154188 < Notification type = { notification . type } message = { notification . message } onClose = { ( ) => setNotification ( null ) } />
155189 ) }
0 commit comments