@@ -17,11 +17,17 @@ interface IUseNotificationProps {
1717 navigation : any ;
1818}
1919
20+ const getNotificationType = (
21+ notification : Notifications . Notification ,
22+ ) : NotificationNavigateUserDTOTypeEnum | undefined => {
23+ // Differentiate between different notifications
24+ return notification . request . content ?. data ?. type ; // @dev defined through backend side abstract class
25+ } ;
26+
2027export const useNotifications = ( { navigation } : IUseNotificationProps ) => {
2128 const { state } = useUserContext ( ) ;
22- const [ unreadNotifications , setUnreadNotifications ] = useState <
23- Notifications . Notification [ ]
24- > ( [ ] ) ;
29+ const [ unseenEncountersCount , setUnseenEncountersCount ] =
30+ useState < number > ( 0 ) ;
2531 const [ channels , setChannels ] = useState <
2632 Notifications . NotificationChannel [ ]
2733 > ( [ ] ) ;
@@ -85,27 +91,27 @@ export const useNotifications = ({ navigation }: IUseNotificationProps) => {
8591 notificationListener . current =
8692 Notifications . addNotificationReceivedListener (
8793 ( notification ) => {
88- // TODO: we likely will also need to check for notification type here then
89- setUnreadNotifications ( [
90- ...unreadNotifications ,
91- notification ,
92- ] ) ;
93- console . log (
94- "Received new notification: " ,
95- notification ,
96- ) ;
94+ const notificationType =
95+ getNotificationType ( notification ) ;
96+
97+ if (
98+ notificationType ===
99+ NotificationNavigateUserDTOTypeEnum . new_match
100+ ) {
101+ setUnseenEncountersCount (
102+ unseenEncountersCount + 1 ,
103+ ) ;
104+ }
97105 } ,
98106 ) ;
99107
100108 responseListener . current =
101109 Notifications . addNotificationResponseReceivedListener (
102110 ( response ) => {
103- console . log ( "Notification response" , response ) ;
104-
105111 // Differentiate between different notifications
106- const notificationType =
107- response . notification . request . content ?. data
108- ?. type ; // @dev defined through backend side abstract class
112+ const notificationType = getNotificationType (
113+ response . notification ,
114+ ) ;
109115
110116 if ( ! notificationType ) {
111117 navigation . navigate ( ROUTES . MainTabView , {
@@ -116,17 +122,12 @@ export const useNotifications = ({ navigation }: IUseNotificationProps) => {
116122
117123 switch ( notificationType ) {
118124 case NotificationNavigateUserDTOTypeEnum . new_match :
119- // @dev Remove notification from array to update the "unread notification" bubble in the tab
120- const filteredNotifications =
121- unreadNotifications . filter (
122- ( n ) =>
123- n . request . identifier !==
124- response . notification
125- . request . identifier ,
125+ if ( unseenEncountersCount > 0 ) {
126+ // @dev If unseen encounter on click, reduce "unread notification" bubble in the tab
127+ setUnseenEncountersCount (
128+ unseenEncountersCount - 1 ,
126129 ) ;
127- setUnreadNotifications (
128- filteredNotifications ,
129- ) ;
130+ }
130131 reactToNewEncounterNotification (
131132 response ,
132133 navigation ,
@@ -164,4 +165,6 @@ export const useNotifications = ({ navigation }: IUseNotificationProps) => {
164165 } ;
165166 } , [ state . id , state . dateMode ] ) ,
166167 ) ;
168+
169+ return { unseenEncountersCount, setUnseenEncountersCount } ;
167170} ;
0 commit comments