@@ -10,7 +10,7 @@ import { UserData, Match, SnapshotOrNullType } from '../Types';
1010import Avatar from '../Avatar' ;
1111import './Friends.css'
1212import ToggleFullscreen from './ToggleFullscreen' ;
13- import { saveMessagingDeviceToken } from '../firebase-messaging-setup ' ;
13+ import { saveFcmToken } from '../firebase.config ' ;
1414
1515type Users = { [ key : string ] : UserData }
1616
@@ -28,24 +28,26 @@ export default function Friends({ user, load, reset }: FriendsProps) {
2828 const [ isExpanded , setIsExpanded ] = useState ( false ) ;
2929 const [ matches , setMatches ] = useState < firebase . database . DataSnapshot > ( [ ] ) ;
3030 const [ searchResults , setSearchResults ] = useState < firebase . database . DataSnapshot > ( [ ] ) ;
31- const [ hasAttemptedNotificationPermission , setHasAttemptedNotificationPermission ] = useState ( false ) ;
31+ const [ requestedNotifications , setRequestedNotifications ] = useState ( false ) ;
3232
3333 // Request notification permission when Friends component mounts
3434 useEffect ( ( ) => {
3535 const requestPermission = async ( ) => {
36- if ( user && Notification . permission === 'default' && ! hasAttemptedNotificationPermission ) {
36+ if ( user && Notification . permission === 'default' && ! requestedNotifications ) {
3737 console . log ( "Friends modal opened, attempting notification permission request..." ) ;
3838 try {
39- await saveMessagingDeviceToken ( ) ;
39+ const permission = await Notification . requestPermission ( ) ;
40+ if ( permission === 'granted' )
41+ saveFcmToken ( ) ;
4042 } catch ( error ) {
4143 console . error ( "Error requesting notification permission:" , error ) ;
4244 } finally {
43- setHasAttemptedNotificationPermission ( true ) ;
45+ setRequestedNotifications ( true ) ;
4446 }
4547 }
4648 } ;
4749 requestPermission ( ) ;
48- } , [ user , hasAttemptedNotificationPermission ] ) ;
50+ } , [ user , requestedNotifications ] ) ;
4951
5052 // Synchronize Matches
5153 useEffect ( ( ) => {
0 commit comments