55 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
66 */
77
8- import {
9- FunctionComponent ,
10- PropsWithChildren ,
11- useCallback ,
12- useEffect ,
13- } from 'react' ;
8+ import { FunctionComponent , PropsWithChildren , useCallback , useEffect } from 'react' ;
149import { useDispatch , useSelector } from 'react-redux' ;
1510import { Grid } from '@mui/material' ;
1611import { CardErrorBoundary , useSnackMessage } from '@gridsuite/commons-ui' ;
17- import {
18- selectComputedLanguage ,
19- selectLanguage ,
20- selectTheme ,
21- } from '../../redux/actions' ;
12+ import { selectComputedLanguage , selectLanguage , selectTheme } from '../../redux/actions' ;
2213import { AppState } from '../../redux/reducer' ;
2314import { ConfigNotif , ConfigParameters , ConfigSrv } from '../../services' ;
24- import {
25- APP_NAME ,
26- COMMON_APP_NAME ,
27- PARAM_LANGUAGE ,
28- PARAM_THEME ,
29- } from '../../utils/config-params' ;
15+ import { APP_NAME , COMMON_APP_NAME , PARAM_LANGUAGE , PARAM_THEME } from '../../utils/config-params' ;
3016import { getComputedLanguage } from '../../utils/language' ;
3117import AppTopBar from './app-top-bar' ;
3218import ReconnectingWebSocket from 'reconnecting-websocket' ;
@@ -51,11 +37,7 @@ const App: FunctionComponent<PropsWithChildren<{}>> = (props, context) => {
5137 break ;
5238 case PARAM_LANGUAGE :
5339 dispatch ( selectLanguage ( param . value ) ) ;
54- dispatch (
55- selectComputedLanguage (
56- getComputedLanguage ( param . value )
57- )
58- ) ;
40+ dispatch ( selectComputedLanguage ( getComputedLanguage ( param . value ) ) ) ;
5941 break ;
6042 default :
6143 break ;
@@ -65,29 +47,26 @@ const App: FunctionComponent<PropsWithChildren<{}>> = (props, context) => {
6547 [ dispatch ]
6648 ) ;
6749
68- const connectNotificationsUpdateConfig =
69- useCallback ( ( ) : ReconnectingWebSocket => {
70- const ws = ConfigNotif . connectNotificationsWsUpdateConfig ( ) ;
71- ws . onmessage = function ( event ) {
72- let eventData = JSON . parse ( event . data ) ;
73- if ( eventData ?. headers ?. parameterName ) {
74- ConfigSrv . fetchConfigParameter (
75- eventData . headers . parameterName
76- )
77- . then ( ( param ) => updateParams ( [ param ] ) )
78- . catch ( ( error ) =>
79- snackError ( {
80- messageTxt : error . message ,
81- headerId : 'paramsRetrievingError' ,
82- } )
83- ) ;
84- }
85- } ;
86- ws . onerror = function ( event ) {
87- console . error ( 'Unexpected Notification WebSocket error' , event ) ;
88- } ;
89- return ws ;
90- } , [ updateParams , snackError ] ) ;
50+ const connectNotificationsUpdateConfig = useCallback ( ( ) : ReconnectingWebSocket => {
51+ const ws = ConfigNotif . connectNotificationsWsUpdateConfig ( ) ;
52+ ws . onmessage = function ( event ) {
53+ let eventData = JSON . parse ( event . data ) ;
54+ if ( eventData ?. headers ?. parameterName ) {
55+ ConfigSrv . fetchConfigParameter ( eventData . headers . parameterName )
56+ . then ( ( param ) => updateParams ( [ param ] ) )
57+ . catch ( ( error ) =>
58+ snackError ( {
59+ messageTxt : error . message ,
60+ headerId : 'paramsRetrievingError' ,
61+ } )
62+ ) ;
63+ }
64+ } ;
65+ ws . onerror = function ( event ) {
66+ console . error ( 'Unexpected Notification WebSocket error' , event ) ;
67+ } ;
68+ return ws ;
69+ } , [ updateParams , snackError ] ) ;
9170
9271 useEffect ( ( ) => {
9372 if ( user !== null ) {
@@ -112,13 +91,7 @@ const App: FunctionComponent<PropsWithChildren<{}>> = (props, context) => {
11291 const ws = connectNotificationsUpdateConfig ( ) ;
11392 return ( ) => ws . close ( ) ;
11493 }
115- } , [
116- user ,
117- dispatch ,
118- updateParams ,
119- snackError ,
120- connectNotificationsUpdateConfig ,
121- ] ) ;
94+ } , [ user , dispatch , updateParams , snackError , connectNotificationsUpdateConfig ] ) ;
12295
12396 return (
12497 < Grid
@@ -131,9 +104,7 @@ const App: FunctionComponent<PropsWithChildren<{}>> = (props, context) => {
131104 >
132105 < Grid item xs = "auto" component = { AppTopBar } />
133106 < Grid item container xs component = "main" >
134- < CardErrorBoundary >
135- { /*Router outlet ->*/ props . children }
136- </ CardErrorBoundary >
107+ < CardErrorBoundary > { /*Router outlet ->*/ props . children } </ CardErrorBoundary >
137108 </ Grid >
138109 </ Grid >
139110 ) ;
0 commit comments