@@ -5,6 +5,8 @@ import {ClientEvents} from '@/gui/constants';
55import { App } from './App' ;
66import store from '../../modules/store' ;
77import { finGuiReport , thunkInitGuiReport , suiteBegin , testBegin , testResult , testsEnd } from '../../modules/actions' ;
8+ import { setGuiServerConnectionStatus } from '@/static/modules/actions/gui-server-connection' ;
9+ import actionNames from '@/static/modules/action-names' ;
810
911const rootEl = document . getElementById ( 'app' ) as HTMLDivElement ;
1012const root = createRoot ( rootEl ) ;
@@ -13,6 +15,20 @@ function Gui(): ReactNode {
1315 const subscribeToEvents = ( ) : void => {
1416 const eventSource = new EventSource ( '/events' ) ;
1517
18+ eventSource . addEventListener ( ClientEvents . CONNECTED , ( ) : void => {
19+ store . dispatch ( { type : actionNames . UPDATE_LOADING_VISIBILITY , payload : false } ) ;
20+
21+ store . dispatch ( setGuiServerConnectionStatus ( { isConnected : true } ) ) ;
22+ } ) ;
23+
24+ eventSource . onerror = ( ) : void => {
25+ store . dispatch ( { type : actionNames . UPDATE_LOADING_IS_IN_PROGRESS , payload : true } ) ;
26+ store . dispatch ( { type : actionNames . UPDATE_LOADING_TITLE , payload : 'Lost connection to Testplane UI server. Trying to reconnect' } ) ;
27+ store . dispatch ( { type : actionNames . UPDATE_LOADING_VISIBILITY , payload : true } ) ;
28+
29+ store . dispatch ( setGuiServerConnectionStatus ( { isConnected : false } ) ) ;
30+ } ;
31+
1632 eventSource . addEventListener ( ClientEvents . BEGIN_SUITE , ( e ) => {
1733 const data = JSON . parse ( e . data ) ;
1834 store . dispatch ( suiteBegin ( data ) ) ;
0 commit comments