@@ -2,7 +2,7 @@ import type { NavigationProp, ParamListBase } from '@react-navigation/native';
22import { useNavigation } from '@react-navigation/native' ;
33
44import type { FC } from 'react' ;
5- import { useCallback , useState } from 'react' ;
5+ import { useMemo , useCallback , useState } from 'react' ;
66import { useTranslation } from 'react-i18next' ;
77import { ScrollView } from 'react-native' ;
88import { Box } from 'react-native-flex-layout' ;
@@ -11,6 +11,7 @@ import { Badge, List, useTheme } from 'react-native-paper';
1111import ChangeLanguageModal from '@/components/modals/ChangeLanguageModal' ;
1212import ChangeThemeModal from '@/components/modals/ChangeThemeModal' ;
1313
14+ import useDtuState from '@/hooks/useDtuState' ;
1415import useHasNewAppVersion from '@/hooks/useHasNewAppVersion' ;
1516import useIsConnected from '@/hooks/useIsConnected' ;
1617
@@ -39,6 +40,28 @@ const MainSettingsTab: FC = () => {
3940 usedForIndicatorOnly : true ,
4041 } ) ;
4142
43+ const hasSystemInformation = ! ! useDtuState ( state => ! ! state ?. systemStatus ) ;
44+ const hasNetworkInformation = ! ! useDtuState ( state => ! ! state ?. networkStatus ) ;
45+ const hasNtpInformation = ! ! useDtuState ( state => ! ! state ?. ntpStatus ) ;
46+ const hasMqttInformation = ! ! useDtuState ( state => ! ! state ?. mqttStatus ) ;
47+
48+ const systemInformationDisabled = useMemo (
49+ ( ) => ! hasSystemInformation || ! websocketConnected ,
50+ [ hasSystemInformation , websocketConnected ] ,
51+ ) ;
52+ const networkInformationDisabled = useMemo (
53+ ( ) => ! hasNetworkInformation || ! websocketConnected ,
54+ [ hasNetworkInformation , websocketConnected ] ,
55+ ) ;
56+ const ntpInformationDisabled = useMemo (
57+ ( ) => ! hasNtpInformation || ! websocketConnected ,
58+ [ hasNtpInformation , websocketConnected ] ,
59+ ) ;
60+ const mqttInformationDisabled = useMemo (
61+ ( ) => ! hasMqttInformation || ! websocketConnected ,
62+ [ hasMqttInformation , websocketConnected ] ,
63+ ) ;
64+
4265 const handleAbout = useCallback ( ( ) => {
4366 navigation . navigate ( 'AboutSettingsScreen' ) ;
4467 } , [ navigation ] ) ;
@@ -74,32 +97,32 @@ const MainSettingsTab: FC = () => {
7497 description = { t ( 'opendtu.systemInformationDescription' ) }
7598 left = { props => < List . Icon { ...props } icon = "information" /> }
7699 onPress = { handleAboutOpenDTU }
77- disabled = { ! websocketConnected }
78- style = { { opacity : websocketConnected ? 1 : 0.5 } }
100+ disabled = { systemInformationDisabled }
101+ style = { { opacity : systemInformationDisabled ? 0.5 : 1 } }
79102 />
80103 < List . Item
81104 title = { t ( 'opendtu.networkInformation' ) }
82105 description = { t ( 'opendtu.networkInformationDescription' ) }
83106 left = { props => < List . Icon { ...props } icon = "wifi" /> }
84107 onPress = { handleNetworkInformation }
85- disabled = { ! websocketConnected }
86- style = { { opacity : websocketConnected ? 1 : 0.5 } }
108+ disabled = { networkInformationDisabled }
109+ style = { { opacity : networkInformationDisabled ? 0.5 : 1 } }
87110 />
88111 < List . Item
89112 title = { t ( 'opendtu.ntpInformation' ) }
90113 description = { t ( 'opendtu.ntpInformationDescription' ) }
91114 left = { props => < List . Icon { ...props } icon = "clock" /> }
92115 onPress = { handleNtpInformation }
93- disabled = { ! websocketConnected }
94- style = { { opacity : websocketConnected ? 1 : 0.5 } }
116+ disabled = { ntpInformationDisabled }
117+ style = { { opacity : ntpInformationDisabled ? 0.5 : 1 } }
95118 />
96119 < List . Item
97120 title = { t ( 'opendtu.mqttInformation' ) }
98121 description = { t ( 'opendtu.mqttInformationDescription' ) }
99122 left = { props => < List . Icon { ...props } icon = "broadcast" /> }
100123 onPress = { handleMqttInformation }
101- disabled = { ! websocketConnected }
102- style = { { opacity : websocketConnected ? 1 : 0.5 } }
124+ disabled = { mqttInformationDisabled }
125+ style = { { opacity : mqttInformationDisabled ? 0.5 : 1 } }
103126 />
104127 </ List . Section >
105128 < List . Section >
0 commit comments