import React, { FunctionComponent, useEffect, useState } from 'react'; import { eventEmitter, EventType } from '../../services/EventEmitter'; import { getVoiceMailCounter, updateMissedCounter, updateVoiceMailsCounter, } from '../../store/callLogs/callLogSlice'; import { Logger } from '../../utils/Log'; import { useAppDispatch, useAppSelector } from '../../store/hooks'; import { Text, View } from 'react-native'; export const EventsTabIcon: FunctionComponent = () => { const logger = new Logger('EventsTabIcon'); const [missedCallsCounter, setMissedCallsCounter] = useState(0); const dispatch = useAppDispatch(); const missedCounter = useAppSelector((state) => state.callLogs.missedCounter); useEffect(() => { getVoiceMailCounter(); eventEmitter.addListener( EventType.MissedCallUnreadCounterUpdated, (counter: number) => { logger.info(`MissedCallsCounterUpdated: ${counter}`); setMissedCallsCounter(counter); dispatch(updateMissedCounter(counter)) } ); eventEmitter.addListener( EventType.VoiceMailUnreadCounterUpdated, (counter: number) => { logger.info(`VoiceMailsCounterUpdated: ${counter}`); dispatch(updateVoiceMailsCounter(counter)); } ); }, []); if (missedCounter > 0) { return ( {missedCounter} ); } else return null; };