5
5
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
6
6
*/
7
7
8
- import {
9
- FunctionComponent ,
10
- PropsWithChildren ,
11
- useCallback ,
12
- useEffect ,
13
- } from 'react' ;
8
+ import { FunctionComponent , PropsWithChildren , useCallback , useEffect } from 'react' ;
14
9
import { useDispatch , useSelector } from 'react-redux' ;
15
10
import { Grid } from '@mui/material' ;
16
11
import { 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' ;
22
13
import { AppState } from '../../redux/reducer' ;
23
14
import { 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' ;
30
16
import { getComputedLanguage } from '../../utils/language' ;
31
17
import AppTopBar from './app-top-bar' ;
32
18
import ReconnectingWebSocket from 'reconnecting-websocket' ;
@@ -51,11 +37,7 @@ const App: FunctionComponent<PropsWithChildren<{}>> = (props, context) => {
51
37
break ;
52
38
case PARAM_LANGUAGE :
53
39
dispatch ( selectLanguage ( param . value ) ) ;
54
- dispatch (
55
- selectComputedLanguage (
56
- getComputedLanguage ( param . value )
57
- )
58
- ) ;
40
+ dispatch ( selectComputedLanguage ( getComputedLanguage ( param . value ) ) ) ;
59
41
break ;
60
42
default :
61
43
break ;
@@ -65,29 +47,26 @@ const App: FunctionComponent<PropsWithChildren<{}>> = (props, context) => {
65
47
[ dispatch ]
66
48
) ;
67
49
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 ] ) ;
91
70
92
71
useEffect ( ( ) => {
93
72
if ( user !== null ) {
@@ -112,13 +91,7 @@ const App: FunctionComponent<PropsWithChildren<{}>> = (props, context) => {
112
91
const ws = connectNotificationsUpdateConfig ( ) ;
113
92
return ( ) => ws . close ( ) ;
114
93
}
115
- } , [
116
- user ,
117
- dispatch ,
118
- updateParams ,
119
- snackError ,
120
- connectNotificationsUpdateConfig ,
121
- ] ) ;
94
+ } , [ user , dispatch , updateParams , snackError , connectNotificationsUpdateConfig ] ) ;
122
95
123
96
return (
124
97
< Grid
@@ -131,9 +104,7 @@ const App: FunctionComponent<PropsWithChildren<{}>> = (props, context) => {
131
104
>
132
105
< Grid item xs = "auto" component = { AppTopBar } />
133
106
< Grid item container xs component = "main" >
134
- < CardErrorBoundary >
135
- { /*Router outlet ->*/ props . children }
136
- </ CardErrorBoundary >
107
+ < CardErrorBoundary > { /*Router outlet ->*/ props . children } </ CardErrorBoundary >
137
108
</ Grid >
138
109
</ Grid >
139
110
) ;
0 commit comments