File tree Expand file tree Collapse file tree 2 files changed +42
-0
lines changed Expand file tree Collapse file tree 2 files changed +42
-0
lines changed Original file line number Diff line number Diff line change @@ -87,12 +87,40 @@ const ResizableArea: React.FC = () => {
8787 ) ;
8888} ;
8989
90+
91+ const WebSocketStatus : React . FC = ( ) => {
92+ const enabled = useSelector ( selectors . websocketFeatureFlagEnabled ) ;
93+ const status = useSelector ( selectors . websocketStatusSelector ) ;
94+
95+ if ( ! enabled ) { return null ; }
96+
97+ const style : React . CSSProperties = {
98+ position : 'absolute' ,
99+ left : '1em' ,
100+ bottom : '1em' ,
101+ zIndex : '1' ,
102+ } ;
103+
104+ switch ( status . state ) {
105+ case 'connected' :
106+ style . color = 'green' ;
107+ return < div style = { style } > ⬤</ div > ;
108+ case 'disconnected' :
109+ style . color = 'grey' ;
110+ return < div style = { style } > ⬤</ div > ;
111+ case 'error' :
112+ style . color = 'red' ;
113+ return < div style = { style } title = { status . error } > ⬤</ div > ;
114+ }
115+ }
116+
90117const Playground : React . FC = ( ) => {
91118 const showNotifications = useSelector ( selectors . anyNotificationsToShowSelector ) ;
92119
93120 return (
94121 < >
95122 < div className = { styles . container } >
123+ < WebSocketStatus />
96124 < Header />
97125 < ResizableArea />
98126 </ div >
Original file line number Diff line number Diff line change @@ -343,3 +343,17 @@ export const useWebsocketSelector = createSelector(
343343 websocket ,
344344 ( ws ) => ws . connected && ws . featureFlagEnabled ,
345345) ;
346+
347+ export type WebSocketStatus =
348+ { state : 'disconnected' } |
349+ { state : 'connected' } |
350+ { state : 'error' , error : string } ;
351+
352+ export const websocketStatusSelector = createSelector (
353+ websocket ,
354+ ( ws ) : WebSocketStatus => {
355+ if ( ws . error ) { return { state : 'error' , error : ws . error } ; }
356+ if ( ws . connected ) { return { state : 'connected' } ; }
357+ return { state : 'disconnected' } ;
358+ }
359+ ) ;
You can’t perform that action at this time.
0 commit comments