From 6956149a3d8db40260e0d054a6846e540f6f40fd Mon Sep 17 00:00:00 2001 From: Face <69168154+face-hh@users.noreply.github.com> Date: Tue, 15 Jul 2025 19:11:50 +0300 Subject: [PATCH] fix notifications not clearing --- website/src/lib/stores/notifications.ts | 20 ++++++------- .../src/routes/api/notifications/+server.ts | 18 +++++------ .../src/routes/api/rewards/claim/+server.ts | 30 ++++++++++++++++--- website/src/routes/notifications/+page.svelte | 4 +-- 4 files changed, 44 insertions(+), 28 deletions(-) diff --git a/website/src/lib/stores/notifications.ts b/website/src/lib/stores/notifications.ts index ecfbf3c..3618d72 100644 --- a/website/src/lib/stores/notifications.ts +++ b/website/src/lib/stores/notifications.ts @@ -2,7 +2,7 @@ import { writable, derived } from 'svelte/store'; export interface Notification { id: number; - type: string; + type: 'HOPIUM' | 'TRANSFER' | 'RUG_PULL' | 'SYSTEM'; title: string; message: string; link?: string; @@ -24,10 +24,10 @@ export async function fetchNotifications(unreadOnly = false) { if (!response.ok) throw new Error('Failed to fetch notifications'); const data = await response.json(); - + NOTIFICATIONS.set(data.notifications); UNREAD_COUNT.set(data.unreadCount); - + return data; } catch (error) { console.error('Failed to fetch notifications:', error); @@ -35,23 +35,21 @@ export async function fetchNotifications(unreadOnly = false) { } } -export async function markNotificationsAsRead(ids: number[]) { +export async function markNotificationsAsRead() { try { const response = await fetch('/api/notifications', { method: 'PATCH', headers: { 'Content-Type': 'application/json' }, - body: JSON.stringify({ ids, markAsRead: true }) + body: JSON.stringify({ markAsRead: true }) }); if (!response.ok) throw new Error('Failed to mark notifications as read'); - NOTIFICATIONS.update(notifications => - notifications.map(notif => - ids.includes(notif.id) ? { ...notif, isRead: true } : notif - ) + NOTIFICATIONS.update(notifications => + notifications.map(notif => ({ ...notif, isRead: true })) ); - UNREAD_COUNT.update(count => Math.max(0, count - ids.length)); + UNREAD_COUNT.set(0); } catch (error) { console.error('Failed to mark notifications as read:', error); @@ -59,4 +57,4 @@ export async function markNotificationsAsRead(ids: number[]) { } } -export const hasUnreadNotifications = derived(UNREAD_COUNT, count => count > 0); +export const hasUnreadNotifications = derived(UNREAD_COUNT, count => count > 0); \ No newline at end of file diff --git a/website/src/routes/api/notifications/+server.ts b/website/src/routes/api/notifications/+server.ts index 8f9500e..08a6443 100644 --- a/website/src/routes/api/notifications/+server.ts +++ b/website/src/routes/api/notifications/+server.ts @@ -55,24 +55,22 @@ export const PATCH: RequestHandler = async ({ request }) => { if (!session?.user) throw error(401, 'Not authenticated'); const userId = Number(session.user.id); - const { ids, markAsRead } = await request.json(); + const { markAsRead } = await request.json(); - if (!Array.isArray(ids) || typeof markAsRead !== 'boolean') { + if (typeof markAsRead !== 'boolean') { throw error(400, 'Invalid request body'); } try { - await db - .update(notifications) - .set({ isRead: markAsRead }) - .where(and( - eq(notifications.userId, userId), - inArray(notifications.id, ids) - )); + if (markAsRead) { + await db.update(notifications) + .set({ isRead: true }) + .where(eq(notifications.userId, userId)); + } return json({ success: true }); } catch (e) { console.error('Failed to update notifications:', e); throw error(500, 'Failed to update notifications'); } -}; +}; \ No newline at end of file diff --git a/website/src/routes/api/rewards/claim/+server.ts b/website/src/routes/api/rewards/claim/+server.ts index 58994a1..1b34447 100644 --- a/website/src/routes/api/rewards/claim/+server.ts +++ b/website/src/routes/api/rewards/claim/+server.ts @@ -13,10 +13,32 @@ const REWARD_TIERS = [ 1500, // Day 2 1800, // Day 3 2100, // Day 4 - 2500, // Day 5 - 3000, // Day 6 - 3500, // Day 7 - 4000, // Day 8+ + 2500, // Day 5 + 3000, // Day 6 + 3500, // Day 7 + 4000, // Day 8 + 4200, // Day 9 + 4400, // Day 10 + 4600, // Day 11 + 4800, // Day 12 + 5000, // Day 13 + 5200, // Day 14 + 5400, // Day 15 + 5600, // Day 16 + 5800, // Day 17 + 6000, // Day 18 + 6200, // Day 19 + 6400, // Day 20 + 6600, // Day 21 + 6800, // Day 22 + 7000, // Day 23 + 7200, // Day 24 + 7400, // Day 25 + 7600, // Day 26 + 7800, // Day 27 + 8000, // Day 28 + 8200, // Day 29 + 8500 // Day 30+ ]; const PRESTIGE_MULTIPLIERS = { diff --git a/website/src/routes/notifications/+page.svelte b/website/src/routes/notifications/+page.svelte index 8b3c761..3e1eea4 100644 --- a/website/src/routes/notifications/+page.svelte +++ b/website/src/routes/notifications/+page.svelte @@ -33,9 +33,7 @@ const unreadIds = ($NOTIFICATIONS || []).filter((n) => !n.isRead).map((n) => n.id); newNotificationIds = unreadIds; - if (unreadIds.length > 0) { - await markNotificationsAsRead(unreadIds); - } + await markNotificationsAsRead(); } catch (error) { toast.error('Failed to load notifications'); } finally {