diff --git a/src/screens/NotificationSettingsScreen.tsx b/src/screens/NotificationSettingsScreen.tsx index 4b45e80..28d18a6 100644 --- a/src/screens/NotificationSettingsScreen.tsx +++ b/src/screens/NotificationSettingsScreen.tsx @@ -164,9 +164,24 @@ const NotificationSettingsScreen = () => { const handleTestNotification = async () => { try { - // Cancel previous test notification if exists - if (testNotificationId) { - await notificationService.cancelNotification(testNotificationId); + // Remove all previous test notifications before scheduling a new one + const scheduled = notificationService.getScheduledNotifications?.() || []; + const testNotifications = scheduled.filter(n => n.id.startsWith('test-notification-')); + if (testNotifications.length > 0 && typeof notificationService.cancelNotification === 'function') { + for (const n of testNotifications) { + await notificationService.cancelNotification(n.id); + } + } + + + // Temporarily override timeBeforeAiring to 0 for the test notification + let originalTimeBeforeAiring: number | undefined = undefined; + if (typeof notificationService.getSettings === 'function') { + const currentSettings = await notificationService.getSettings(); + originalTimeBeforeAiring = currentSettings.timeBeforeAiring; + if (typeof notificationService.updateSettings === 'function') { + await notificationService.updateSettings({ timeBeforeAiring: 0 }); + } } const testNotification = { @@ -176,15 +191,24 @@ const NotificationSettingsScreen = () => { episodeTitle: 'Test Episode', season: 1, episode: 1, - releaseDate: new Date(Date.now() + 60000).toISOString(), // 1 minute from now + releaseDate: new Date(Date.now() + 5000).toISOString(), // 5 seconds from now notified: false }; - + const notificationId = await notificationService.scheduleEpisodeNotification(testNotification); + + // Restore original timeBeforeAiring + if ( + typeof notificationService.updateSettings === 'function' && + originalTimeBeforeAiring !== undefined + ) { + await notificationService.updateSettings({ timeBeforeAiring: originalTimeBeforeAiring }); + } + if (notificationId) { setTestNotificationId(notificationId); - setCountdown(60); // Start 60 second countdown - Alert.alert('Success', 'Test notification scheduled for 1 minute from now'); + setCountdown(0); // No countdown for instant notification + Alert.alert('Success', 'Test notification scheduled to fire instantly'); } else { Alert.alert('Error', 'Failed to schedule test notification. Make sure notifications are enabled.'); }