🐛 drop deleted items from calendar/message notifiers
Browse files at this commitf0738f4740f4fc3de9dd765d6d58201ab5dea351Parent: 948c509- fix
- 🐛 drop deleted items from calendar/message notifiers
2 changed files +41 -9
src/components/layout/notification-center.tsxmodified+22 -5
| @@ -1,4 +1,4 @@ | |||
| 1 | -import { For, Show, Suspense, createMemo, createResource, createSignal, onCleanup } from "solid-js"; | 1 | +import { For, Show, Suspense, createEffect, createMemo, createResource, createSignal, onCleanup } from "solid-js"; |
| 2 | import { useNavigate } from "@tanstack/solid-router"; | 2 | import { useNavigate } from "@tanstack/solid-router"; |
| 3 | import { getEvents } from "@/api/events"; | 3 | import { getEvents } from "@/api/events"; |
| 4 | import { getExams } from "@/api/exams"; | 4 | import { getExams } from "@/api/exams"; |
| @@ -42,7 +42,7 @@ export function NotificationCenter() { | |||
| 42 | } | 42 | } |
| 43 | ); | 43 | ); |
| 44 | 44 | ||
| 45 | - const [eventsRes] = createResource(async () => { | 45 | + const [eventsRes, { refetch: refetchEvents }] = createResource(async () => { |
| 46 | try { | 46 | try { |
| 47 | return await getEvents(); | 47 | return await getEvents(); |
| 48 | } catch { | 48 | } catch { |
| @@ -50,7 +50,7 @@ export function NotificationCenter() { | |||
| 50 | } | 50 | } |
| 51 | }); | 51 | }); |
| 52 | 52 | ||
| 53 | - const [examsRes] = createResource(async () => { | 53 | + const [examsRes, { refetch: refetchExams }] = createResource(async () => { |
| 54 | try { | 54 | try { |
| 55 | return await getExams(); | 55 | return await getExams(); |
| 56 | } catch { | 56 | } catch { |
| @@ -58,7 +58,7 @@ export function NotificationCenter() { | |||
| 58 | } | 58 | } |
| 59 | }); | 59 | }); |
| 60 | 60 | ||
| 61 | - const [homeworkRes] = createResource(async () => { | 61 | + const [homeworkRes, { refetch: refetchHomework }] = createResource(async () => { |
| 62 | try { | 62 | try { |
| 63 | return await getHomework(); | 63 | return await getHomework(); |
| 64 | } catch { | 64 | } catch { |
| @@ -66,11 +66,28 @@ export function NotificationCenter() { | |||
| 66 | } | 66 | } |
| 67 | }); | 67 | }); |
| 68 | 68 | ||
| 69 | + // Revalidate every source so an item deleted on another page stops | ||
| 70 | + // notifying: on the periodic clock tick (badge self-heals) and whenever | ||
| 71 | + // the panel is opened (list is fresh on interaction). | ||
| 72 | + const refreshAll = () => { | ||
| 73 | + void refetchMessages(); | ||
| 74 | + void refetchEvents(); | ||
| 75 | + void refetchExams(); | ||
| 76 | + void refetchHomework(); | ||
| 77 | + }; | ||
| 78 | + | ||
| 69 | // Reactive clock so passed items drop off without a remount. | 79 | // Reactive clock so passed items drop off without a remount. |
| 70 | const [nowMs, setNowMs] = createSignal(Date.now()); | 80 | const [nowMs, setNowMs] = createSignal(Date.now()); |
| 71 | - const clockTimer = setInterval(() => setNowMs(Date.now()), 60_000); | 81 | + const clockTimer = setInterval(() => { |
| 82 | + setNowMs(Date.now()); | ||
| 83 | + refreshAll(); | ||
| 84 | + }, 60_000); | ||
| 72 | onCleanup(() => clearInterval(clockTimer)); | 85 | onCleanup(() => clearInterval(clockTimer)); |
| 73 | 86 | ||
| 87 | + createEffect(() => { | ||
| 88 | + if (open()) refreshAll(); | ||
| 89 | + }); | ||
| 90 | + | ||
| 74 | // An item is still notifiable until it has ended (ends_at, else starts_at). | 91 | // An item is still notifiable until it has ended (ends_at, else starts_at). |
| 75 | const notEnded = (starts: number, ends?: number | null) => (ends ?? starts) >= nowMs(); | 92 | const notEnded = (starts: number, ends?: number | null) => (ends ?? starts) >= nowMs(); |
| 76 | 93 | ||
src/components/layout/right-nav.tsxmodified+19 -4
| @@ -1,4 +1,4 @@ | |||
| 1 | -import { For, Show, Suspense, createMemo, createResource, createSignal, onCleanup } from "solid-js"; | 1 | +import { For, Show, Suspense, createEffect, createMemo, createResource, createSignal, onCleanup } from "solid-js"; |
| 2 | import { useLocation, useNavigate } from "@tanstack/solid-router"; | 2 | import { useLocation, useNavigate } from "@tanstack/solid-router"; |
| 3 | import { getEvents } from "@/api/events"; | 3 | import { getEvents } from "@/api/events"; |
| 4 | import { getExams } from "@/api/exams"; | 4 | import { getExams } from "@/api/exams"; |
| @@ -60,7 +60,7 @@ export function RightNav() { | |||
| 60 | ); | 60 | ); |
| 61 | 61 | ||
| 62 | // Fetch events & exams | 62 | // Fetch events & exams |
| 63 | - const [eventsRes] = createResource( | 63 | + const [eventsRes, { refetch: refetchEvents }] = createResource( |
| 64 | async () => { | 64 | async () => { |
| 65 | try { | 65 | try { |
| 66 | return (await getEvents({ limit: 100 })).items; | 66 | return (await getEvents({ limit: 100 })).items; |
| @@ -71,7 +71,7 @@ export function RightNav() { | |||
| 71 | { initialValue: [] } | 71 | { initialValue: [] } |
| 72 | ); | 72 | ); |
| 73 | 73 | ||
| 74 | - const [examsRes] = createResource( | 74 | + const [examsRes, { refetch: refetchExams }] = createResource( |
| 75 | async () => { | 75 | async () => { |
| 76 | try { | 76 | try { |
| 77 | return (await getExams({ limit: 100 })).items; | 77 | return (await getExams({ limit: 100 })).items; |
| @@ -82,6 +82,14 @@ export function RightNav() { | |||
| 82 | { initialValue: [] } | 82 | { initialValue: [] } |
| 83 | ); | 83 | ); |
| 84 | 84 | ||
| 85 | + // Revalidate every source so an item deleted on another page stops showing | ||
| 86 | + // in the drawer/badge: on the periodic clock tick and whenever a drawer opens. | ||
| 87 | + const refreshAll = () => { | ||
| 88 | + void refetchMessages(); | ||
| 89 | + void refetchEvents(); | ||
| 90 | + void refetchExams(); | ||
| 91 | + }; | ||
| 92 | + | ||
| 85 | // Computed message data | 93 | // Computed message data |
| 86 | const allMessages = () => messagesRes().items; | 94 | const allMessages = () => messagesRes().items; |
| 87 | const unreadCount = createMemo(() => allMessages().filter((m: Message) => !m.read).length); | 95 | const unreadCount = createMemo(() => allMessages().filter((m: Message) => !m.read).length); |
| @@ -101,9 +109,16 @@ export function RightNav() { | |||
| 101 | 109 | ||
| 102 | // Reactive clock so passed items clear without a remount. | 110 | // Reactive clock so passed items clear without a remount. |
| 103 | const [nowMs, setNowMs] = createSignal(Date.now()); | 111 | const [nowMs, setNowMs] = createSignal(Date.now()); |
| 104 | - const clockTimer = setInterval(() => setNowMs(Date.now()), 60_000); | 112 | + const clockTimer = setInterval(() => { |
| 113 | + setNowMs(Date.now()); | ||
| 114 | + refreshAll(); | ||
| 115 | + }, 60_000); | ||
| 105 | onCleanup(() => clearInterval(clockTimer)); | 116 | onCleanup(() => clearInterval(clockTimer)); |
| 106 | 117 | ||
| 118 | + createEffect(() => { | ||
| 119 | + if (activeTab() !== null) refreshAll(); | ||
| 120 | + }); | ||
| 121 | + | ||
| 107 | // An item is still notifiable until it has ended (ends_at, else starts_at). | 122 | // An item is still notifiable until it has ended (ends_at, else starts_at). |
| 108 | const notEnded = (starts?: number | null, ends?: number | null) => { | 123 | const notEnded = (starts?: number | null, ends?: number | null) => { |
| 109 | if (!starts) return false; | 124 | if (!starts) return false; |