99} from 'react-admin' ;
1010import { onlineManager , useQueryClient } from '@tanstack/react-query' ;
1111import { Stack , Tooltip } from '@mui/material' ;
12- import CircleIcon from '@mui/icons-material/Circle ' ;
12+ import OfflineIcon from '@mui/icons-material/SignalWifiConnectedNoInternet4 ' ;
1313import '../assets/app.css' ;
1414
1515const MyAppBar = ( ) => {
@@ -18,44 +18,45 @@ const MyAppBar = () => {
1818 < AppBar >
1919 < TitlePortal />
2020 < Stack direction = "row" spacing = { 1 } >
21- < Tooltip title = { isOnline ? 'Online' : 'Offline' } >
22- < CircleIcon
23- sx = { {
24- color : isOnline ? 'success.main' : 'warning.main' ,
25- width : 24 ,
26- height : 24 ,
27- } }
28- />
29- </ Tooltip >
21+ { ! isOnline ? (
22+ < Tooltip title = "Offline" >
23+ < OfflineIcon
24+ sx = { {
25+ color : 'warning.main' ,
26+ width : 24 ,
27+ height : 24 ,
28+ } }
29+ />
30+ </ Tooltip >
31+ ) : null }
3032 </ Stack >
3133 < InspectorButton />
3234 </ AppBar >
3335 ) ;
3436} ;
3537
36- export default ( { children } ) => {
37- return (
38- < >
39- < Layout appBar = { MyAppBar } >
40- { children }
41- < NotificationsFromQueryClient />
42- </ Layout >
43- < ReactQueryDevtools
44- initialIsOpen = { false }
45- buttonPosition = "bottom-left"
46- />
47- </ >
48- ) ;
49- } ;
38+ export const MyLayout = ( { children } ) => (
39+ < >
40+ < Layout appBar = { MyAppBar } >
41+ { children }
42+ < NotificationsFromQueryClient />
43+ </ Layout >
44+ < ReactQueryDevtools
45+ initialIsOpen = { false }
46+ buttonPosition = "bottom-left"
47+ />
48+ </ >
49+ ) ;
5050
5151const useIsOnline = ( ) => {
5252 const [ isOnline , setIsOnline ] = React . useState ( onlineManager . isOnline ( ) ) ;
53+
5354 React . useEffect ( ( ) => {
54- const handleChange = isOnline => {
55- setIsOnline ( isOnline ) ;
55+ const handleChange = ( ) => {
56+ setIsOnline ( onlineManager . isOnline ( ) ) ;
5657 } ;
5758 return onlineManager . subscribe ( handleChange ) ;
58- } ) ;
59+ } , [ ] ) ;
5960
6061 return isOnline ;
6162} ;
@@ -69,12 +70,15 @@ const NotificationsFromQueryClient = () => {
6970 const queryClient = useQueryClient ( ) ;
7071 const notify = useNotify ( ) ;
7172
72- queryClient . setMutationDefaults ( [ ] , {
73- onSettled ( data , error ) {
74- if ( error ) {
75- notify ( error . message , { type : 'error' } ) ;
76- }
77- } ,
78- } ) ;
73+ React . useEffect ( ( ) => {
74+ queryClient . setMutationDefaults ( [ ] , {
75+ onSettled ( data , error ) {
76+ if ( error ) {
77+ notify ( error . message , { type : 'error' } ) ;
78+ }
79+ } ,
80+ } ) ;
81+ } , [ queryClient , notify ] ) ;
82+
7983 return null ;
8084} ;
0 commit comments