From 60affa9a77f743ca13575633b164b754fc33ffcb Mon Sep 17 00:00:00 2001 From: Avery Felts Date: Tue, 27 Jan 2026 14:05:40 -0700 Subject: [PATCH] Fix immediate achievement celebration and reliable notification delivery --- src/components/Dashboard.tsx | 3 +++ src/hooks/useNotifications.ts | 9 ++++----- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/src/components/Dashboard.tsx b/src/components/Dashboard.tsx index b150975..58e560b 100644 --- a/src/components/Dashboard.tsx +++ b/src/components/Dashboard.tsx @@ -174,6 +174,9 @@ export function Dashboard({ user }: DashboardProps) { const usage = await fetchUsageData(); setUsageData(usage); setRefreshKey(prev => prev + 1); + + // Check for new achievements immediately + await checkAndUnlockAchievements(usage, updatedPrefs, achievements); }; const handleGeneratePlan = async () => { diff --git a/src/hooks/useNotifications.ts b/src/hooks/useNotifications.ts index dc45a6d..67c3e94 100644 --- a/src/hooks/useNotifications.ts +++ b/src/hooks/useNotifications.ts @@ -72,13 +72,12 @@ export function useNotifications(reminderSettings: ReminderSettings) { const reminderTime = new Date(); reminderTime.setHours(hours, minutes, 0, 0); - // Check if it's time for the reminder (within 1 minute window) - const timeDiff = Math.abs(now.getTime() - reminderTime.getTime()); - if (timeDiff <= 60000) { + // If current time is past the reminder time, send it + if (now >= reminderTime) { sendNotification('QuitTraq Reminder', { body: "Time to log your daily usage! Every day counts on your journey.", - tag: 'daily-reminder', - requireInteraction: false, + tag: 'daily-reminder', // Tag ensures we don't stack multiple notifications + requireInteraction: true, // Keep it visible until user interacts }); localStorage.setItem(LAST_NOTIFICATION_KEY, today); }