1- import React , { Suspense , useEffect , useState } from 'react' ;
1+ import React , { Suspense } from 'react' ;
22import { ActivityIndicator } from 'react-native' ;
33import { createBottomTabNavigator } from '@react-navigation/bottom-tabs' ;
44import { Ionicons } from '@expo/vector-icons' ;
55import { ThemedText } from '../components/ThemedText' ;
66import { ThemedView } from '../components/ThemedView' ;
77import { colors } from '../theme/colors' ;
8+ import { useMatStore } from '../stores/matStore' ;
89import { MainTabsParamList } from './types' ;
910
1011const createPlaceholder = ( label : string ) => {
@@ -74,29 +75,6 @@ const toIconName = (routeName: keyof MainTabsParamList) => {
7475 }
7576} ;
7677
77- const getMatAlertCount = async ( ) : Promise < number > => {
78- try {
79- const mod = ( await import ( '../stores/matStore' ) ) as Record < string , unknown > ;
80- const candidates = [ mod . useMatStore , mod . useStore ] . filter ( ( candidate ) => {
81- return (
82- ! ! candidate &&
83- typeof candidate === 'function' &&
84- typeof ( candidate as { getState ?: ( ) => unknown } ) . getState === 'function'
85- ) ;
86- } ) as Array < { getState : ( ) => { alerts ?: unknown [ ] } } > ;
87-
88- for ( const store of candidates ) {
89- const alerts = store . getState ( ) . alerts ;
90- if ( Array . isArray ( alerts ) ) {
91- return alerts . length ;
92- }
93- }
94- } catch {
95- return 0 ;
96- }
97- return 0 ;
98- } ;
99-
10078const screens : ReadonlyArray < { name : keyof MainTabsParamList ; component : React . ComponentType } > = [
10179 { name : 'Live' , component : LiveScreen } ,
10280 { name : 'Vitals' , component : VitalsScreen } ,
@@ -114,18 +92,7 @@ const Suspended = ({ component: Component }: { component: React.ComponentType })
11492) ;
11593
11694export const MainTabs = ( ) => {
117- const [ matAlertCount , setMatAlertCount ] = useState ( 0 ) ;
118-
119- useEffect ( ( ) => {
120- const readCount = async ( ) => {
121- const count = await getMatAlertCount ( ) ;
122- setMatAlertCount ( count ) ;
123- } ;
124-
125- void readCount ( ) ;
126- const timer = setInterval ( readCount , 2000 ) ;
127- return ( ) => clearInterval ( timer ) ;
128- } , [ ] ) ;
95+ const matAlertCount = useMatStore ( ( state ) => state . alerts . length ) ;
12996
13097 return (
13198 < Tab . Navigator
0 commit comments