Fixed test notification and is now instant

This commit is contained in:
CrissZollo 2025-09-20 08:32:53 +02:00
parent 718868f7b5
commit c6a2c52365

View file

@ -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.');
}