1
1
import LockIcon from '@mui/icons-material/Lock' ;
2
2
import LockOpenIcon from '@mui/icons-material/LockOpen' ;
3
3
import WifiIcon from '@mui/icons-material/Wifi' ;
4
- import { Avatar , Badge , List , ListItem , ListItemAvatar , ListItemIcon , ListItemText } from '@mui/material' ;
4
+ import { Avatar , Badge , List , ListItem , ListItemAvatar , ListItemIcon , ListItemText , useTheme } from '@mui/material' ;
5
5
import { useContext } from 'react' ;
6
6
7
7
import { WiFiConnectionContext } from './WiFiConnectionContext' ;
8
+ import type { Theme } from '@mui/material' ;
8
9
import type { FC } from 'react' ;
9
10
import type { WiFiNetwork , WiFiNetworkList } from 'types' ;
10
11
import { MessageBox } from 'components' ;
@@ -42,8 +43,18 @@ export const networkSecurityMode = ({ encryption_type }: WiFiNetwork) => {
42
43
}
43
44
} ;
44
45
46
+ const networkQualityHighlight = ( { rssi } : WiFiNetwork , theme : Theme ) => {
47
+ if ( rssi <= - 85 ) {
48
+ return theme . palette . error . main ;
49
+ } else if ( rssi <= - 75 ) {
50
+ return theme . palette . warning . main ;
51
+ }
52
+ return theme . palette . success . main ;
53
+ } ;
54
+
45
55
const WiFiNetworkSelector : FC < WiFiNetworkSelectorProps > = ( { networkList } ) => {
46
56
const { LL } = useI18nContext ( ) ;
57
+ const theme = useTheme ( ) ;
47
58
48
59
const wifiConnectionContext = useContext ( WiFiConnectionContext ) ;
49
60
@@ -57,8 +68,8 @@ const WiFiNetworkSelector: FC<WiFiNetworkSelectorProps> = ({ networkList }) => {
57
68
secondary = { 'Security: ' + networkSecurityMode ( network ) + ', Ch: ' + network . channel }
58
69
/>
59
70
< ListItemIcon >
60
- < Badge badgeContent = { network . rssi + 'db ' } >
61
- < WifiIcon />
71
+ < Badge badgeContent = { network . rssi + 'dBm ' } >
72
+ < WifiIcon sx = { { color : networkQualityHighlight ( network , theme ) } } />
62
73
</ Badge >
63
74
</ ListItemIcon >
64
75
</ ListItem >
0 commit comments