🔔 refine messages and notifications
Browse files at this commit81b2656ccbfc0fdd87d2313557a6c2660a330f3eParent: e1768cd- fix
- 🔔 refine messages and notifications
5 changed files +242 -88
- src/components/layout/app-shell.tsx +1 -14
- src/components/layout/notification-center.tsx +198 -55
- src/i18n/messages.ts +3 -0
- src/lib/notifications.ts +27 -0
- src/pages/messages-page.tsx +13 -19
src/components/layout/app-shell.tsxmodified+1 -14
| @@ -21,7 +21,6 @@ import { celebiPanelOpen, openCelebiPanel, setCelebiPanelOpen } from "@/stores/c | |||
| 21 | import { commandPaletteOpen, openCommandPalette, setCommandPaletteOpen } from "@/stores/command-palette"; | 21 | import { commandPaletteOpen, openCommandPalette, setCommandPaletteOpen } from "@/stores/command-palette"; |
| 22 | import { ShellFeedProvider } from "@/stores/shell-feed-context"; | 22 | import { ShellFeedProvider } from "@/stores/shell-feed-context"; |
| 23 | import { usePreferences, useT } from "@/stores/preferences-context"; | 23 | import { usePreferences, useT } from "@/stores/preferences-context"; |
| 24 | -import { useGoBack } from "@/lib/use-go-back"; | ||
| 25 | import { cn } from "@/lib/cn"; | 24 | import { cn } from "@/lib/cn"; |
| 26 | import { ModuleGate } from "@/components/layout/module-gate"; | 25 | import { ModuleGate } from "@/components/layout/module-gate"; |
| 27 | 26 | ||
| @@ -38,7 +37,6 @@ export function AppShell(props: ParentProps) { | |||
| 38 | const [profileOpen, setProfileOpen] = createSignal(false); | 37 | const [profileOpen, setProfileOpen] = createSignal(false); |
| 39 | const collapsed = () => prefs.sidebarCollapsed(); | 38 | const collapsed = () => prefs.sidebarCollapsed(); |
| 40 | const location = useLocation(); | 39 | const location = useLocation(); |
| 41 | - const goBack = useGoBack(); | ||
| 42 | const fullScreen = () => location().pathname.startsWith("/exam-room/"); | 40 | const fullScreen = () => location().pathname.startsWith("/exam-room/"); |
| 43 | const routeLabel = createMemo(() => { | 41 | const routeLabel = createMemo(() => { |
| 44 | const key = routeLabelKey(location().pathname, auth.user()?.role); | 42 | const key = routeLabelKey(location().pathname, auth.user()?.role); |
| @@ -133,19 +131,8 @@ export function AppShell(props: ParentProps) { | |||
| 133 | 131 | ||
| 134 | <main id="main-content" tabIndex={-1} class="min-w-0 flex-1 outline-hidden"> | 132 | <main id="main-content" tabIndex={-1} class="min-w-0 flex-1 outline-hidden"> |
| 135 | <Show when={auth.user() && !fullScreen()}> | 133 | <Show when={auth.user() && !fullScreen()}> |
| 136 | - <header class="sticky top-[env(safe-area-inset-top)] z-30 flex h-[45px] items-center gap-3 border-b border-border/70 bg-background px-4 sm:px-6 lg:px-4"> | 134 | + <header class="sticky top-[env(safe-area-inset-top)] z-30 flex h-[49px] items-center gap-3 border-b border-border/70 bg-background px-4 pt-1.5 sm:px-6 lg:px-4"> |
| 137 | <div class="flex min-w-0 shrink-0 items-center gap-2 sm:w-52 lg:w-[260px]"> | 135 | <div class="flex min-w-0 shrink-0 items-center gap-2 sm:w-52 lg:w-[260px]"> |
| 138 | - <Show when={location().pathname !== "/"}> | ||
| 139 | - <button | ||
| 140 | - type="button" | ||
| 141 | - onClick={goBack} | ||
| 142 | - class="topbar-control flex h-9 w-9 shrink-0 items-center justify-center rounded-md outline-hidden focus-visible:ring-2 focus-visible:ring-ring" | ||
| 143 | - aria-label={t("common.back")} | ||
| 144 | - title={t("common.back")} | ||
| 145 | - > | ||
| 146 | - <IconChevronLeft class="h-4 w-4" /> | ||
| 147 | - </button> | ||
| 148 | - </Show> | ||
| 149 | <span class="hidden truncate text-sm font-semibold sm:block" title={routeLabel()}>{routeLabel()}</span> | 136 | <span class="hidden truncate text-sm font-semibold sm:block" title={routeLabel()}>{routeLabel()}</span> |
| 150 | </div> | 137 | </div> |
| 151 | 138 | ||
src/components/layout/notification-center.tsxmodified+198 -55
| @@ -8,7 +8,9 @@ import { Tabs, TabsContent, TabsList, TabsTrigger } from "@/components/ui/tabs"; | |||
| 8 | import { | 8 | import { |
| 9 | IconBell, | 9 | IconBell, |
| 10 | IconCalendar, | 10 | IconCalendar, |
| 11 | + IconChevronLeft, | ||
| 11 | IconExam, | 12 | IconExam, |
| 13 | + IconExternalLink, | ||
| 12 | IconHomework, | 14 | IconHomework, |
| 13 | IconMessage, | 15 | IconMessage, |
| 14 | IconTrash, | 16 | IconTrash, |
| @@ -20,7 +22,10 @@ import { | |||
| 20 | dismissAllNotificationIds, | 22 | dismissAllNotificationIds, |
| 21 | dismissNotificationId, | 23 | dismissNotificationId, |
| 22 | getDismissedNotificationIds, | 24 | getDismissedNotificationIds, |
| 25 | + getReadNotificationIds, | ||
| 26 | + markNotificationRead, | ||
| 23 | type NotificationItem, | 27 | type NotificationItem, |
| 28 | + type NotificationType, | ||
| 24 | } from "@/lib/notifications"; | 29 | } from "@/lib/notifications"; |
| 25 | import { usePreferences } from "@/stores/preferences-context"; | 30 | import { usePreferences } from "@/stores/preferences-context"; |
| 26 | import { useShellFeed } from "@/stores/shell-feed-context"; | 31 | import { useShellFeed } from "@/stores/shell-feed-context"; |
| @@ -32,6 +37,8 @@ export function NotificationCenter() { | |||
| 32 | const feed = useShellFeed(); | 37 | const feed = useShellFeed(); |
| 33 | const [open, setOpen] = createSignal(false); | 38 | const [open, setOpen] = createSignal(false); |
| 34 | const [dismissedIds, setDismissedIds] = createSignal<Set<string>>(getDismissedNotificationIds()); | 39 | const [dismissedIds, setDismissedIds] = createSignal<Set<string>>(getDismissedNotificationIds()); |
| 40 | + const [readIds, setReadIds] = createSignal<Set<string>>(getReadNotificationIds()); | ||
| 41 | + const [previewNotification, setPreviewNotification] = createSignal<NotificationItem | null>(null); | ||
| 35 | 42 | ||
| 36 | // Shell feed data comes from the shared poller (ShellFeedProvider): one fetch | 43 | // Shell feed data comes from the shared poller (ShellFeedProvider): one fetch |
| 37 | // per source for the whole shell instead of a duplicate set here. Every read | 44 | // per source for the whole shell instead of a duplicate set here. Every read |
| @@ -58,11 +65,13 @@ export function NotificationCenter() { | |||
| 58 | // id DESC, so an older unread message is simply not in it. | 65 | // id DESC, so an older unread message is simply not in it. |
| 59 | const msgs = feed.unreadMessages().items; | 66 | const msgs = feed.unreadMessages().items; |
| 60 | for (const m of msgs) { | 67 | for (const m of msgs) { |
| 68 | + const body = m.body.replace(/<[^>]*>?/gm, "").trim(); | ||
| 61 | list.push({ | 69 | list.push({ |
| 62 | id: `msg_${m.id}`, | 70 | id: `msg_${m.id}`, |
| 63 | type: "message", | 71 | type: "message", |
| 64 | title: personLabel(m.sender), | 72 | title: personLabel(m.sender), |
| 65 | - description: m.subject || m.body.replace(/<[^>]*>?/gm, "").trim(), | 73 | + description: m.subject || body, |
| 74 | + preview: m.subject ? `${m.subject}\n${body}` : body, | ||
| 66 | targetUrl: "/messages", | 75 | targetUrl: "/messages", |
| 67 | timestamp: m.sent_at, | 76 | timestamp: m.sent_at, |
| 68 | }); | 77 | }); |
| @@ -147,6 +156,37 @@ export function NotificationCenter() { | |||
| 147 | return allNotifications().filter((item) => !dismissed.has(item.id)); | 156 | return allNotifications().filter((item) => !dismissed.has(item.id)); |
| 148 | }); | 157 | }); |
| 149 | 158 | ||
| 159 | + const isUnread = (item: NotificationItem) => !readIds().has(item.id); | ||
| 160 | + const unreadNotifications = createMemo(() => activeNotifications().filter(isUnread)); | ||
| 161 | + | ||
| 162 | + const notificationGroupOrder: NotificationType[] = ["message", "event", "exam", "homework"]; | ||
| 163 | + const notificationGroupLabel = (type: NotificationType) => { | ||
| 164 | + if (type === "message") return t("nav.messages"); | ||
| 165 | + if (type === "event") return t("events.title"); | ||
| 166 | + if (type === "exam") return t("exams.title"); | ||
| 167 | + return t("homework.title"); | ||
| 168 | + }; | ||
| 169 | + const notificationGroupTone = (type: NotificationType) => { | ||
| 170 | + if (type === "message") return "border-primary/20 bg-primary/[0.035]"; | ||
| 171 | + if (type === "event") return "border-violet-500/20 bg-violet-500/[0.035]"; | ||
| 172 | + if (type === "exam") return "border-amber-500/25 bg-amber-500/[0.045]"; | ||
| 173 | + return "border-emerald-500/20 bg-emerald-500/[0.035]"; | ||
| 174 | + }; | ||
| 175 | + const notificationGroupIconTone = (type: NotificationType) => { | ||
| 176 | + if (type === "message") return "bg-primary/10 text-primary-text"; | ||
| 177 | + if (type === "event") return "bg-violet-500/10 text-violet-700 dark:text-violet-300"; | ||
| 178 | + if (type === "exam") return "bg-amber-500/10 text-amber-700 dark:text-amber-300"; | ||
| 179 | + return "bg-emerald-500/10 text-emerald-700 dark:text-emerald-300"; | ||
| 180 | + }; | ||
| 181 | + const notificationGroups = createMemo(() => | ||
| 182 | + notificationGroupOrder | ||
| 183 | + .map((type) => ({ | ||
| 184 | + type, | ||
| 185 | + items: activeNotifications().filter((item) => item.type === type), | ||
| 186 | + })) | ||
| 187 | + .filter((group) => group.items.length > 0) | ||
| 188 | + ); | ||
| 189 | + | ||
| 150 | // The list only holds the newest 10 unread messages; `total` is the real | 190 | // The list only holds the newest 10 unread messages; `total` is the real |
| 151 | // server-side unread count, so the rest still counts towards the badge. | 191 | // server-side unread count, so the rest still counts towards the badge. |
| 152 | // Those extra rows have no id here, so they cannot be dismissed one by one: | 192 | // Those extra rows have no id here, so they cannot be dismissed one by one: |
| @@ -166,7 +206,7 @@ export function NotificationCenter() { | |||
| 166 | const sinceDismissAll = page.total - dismissedUnreadTotal() - activeMessageCount(); | 206 | const sinceDismissAll = page.total - dismissedUnreadTotal() - activeMessageCount(); |
| 167 | return Math.max(0, Math.min(beyondPage, sinceDismissAll)); | 207 | return Math.max(0, Math.min(beyondPage, sinceDismissAll)); |
| 168 | }; | 208 | }; |
| 169 | - const unreadCount = () => activeNotifications().length + unlistedUnread(); | 209 | + const unreadCount = () => unreadNotifications().length + unlistedUnread(); |
| 170 | 210 | ||
| 171 | const handleDismissSingle = (evt: MouseEvent, id: string) => { | 211 | const handleDismissSingle = (evt: MouseEvent, id: string) => { |
| 172 | evt.stopPropagation(); | 212 | evt.stopPropagation(); |
| @@ -182,7 +222,11 @@ export function NotificationCenter() { | |||
| 182 | }; | 222 | }; |
| 183 | 223 | ||
| 184 | const handleSelectNotification = async (item: NotificationItem) => { | 224 | const handleSelectNotification = async (item: NotificationItem) => { |
| 185 | - // If message notification, mark read in backend | 225 | + if (isUnread(item)) { |
| 226 | + setReadIds(new Set(markNotificationRead(item.id))); | ||
| 227 | + } | ||
| 228 | + | ||
| 229 | + // Message notifications also need to be marked read in the backend. | ||
| 186 | if (item.id.startsWith("msg_")) { | 230 | if (item.id.startsWith("msg_")) { |
| 187 | const realId = item.id.replace("msg_", ""); | 231 | const realId = item.id.replace("msg_", ""); |
| 188 | try { | 232 | try { |
| @@ -192,15 +236,27 @@ export function NotificationCenter() { | |||
| 192 | // ignore | 236 | // ignore |
| 193 | } | 237 | } |
| 194 | } | 238 | } |
| 195 | - // Dismiss locally | 239 | + setPreviewNotification(item); |
| 196 | - const updated = dismissNotificationId(item.id); | 240 | + }; |
| 197 | - setDismissedIds(new Set(updated)); | 241 | + |
| 242 | + const handleNavigateToNotification = () => { | ||
| 243 | + const item = previewNotification(); | ||
| 244 | + if (!item) return; | ||
| 245 | + setPreviewNotification(null); | ||
| 198 | setOpen(false); | 246 | setOpen(false); |
| 199 | void navigate({ to: item.targetUrl }); | 247 | void navigate({ to: item.targetUrl }); |
| 200 | }; | 248 | }; |
| 201 | 249 | ||
| 202 | return ( | 250 | return ( |
| 203 | - <Popover open={open()} onOpenChange={setOpen} placement="bottom-end" gutter={8}> | 251 | + <Popover |
| 252 | + open={open()} | ||
| 253 | + onOpenChange={(nextOpen) => { | ||
| 254 | + setOpen(nextOpen); | ||
| 255 | + if (!nextOpen) setPreviewNotification(null); | ||
| 256 | + }} | ||
| 257 | + placement="bottom-end" | ||
| 258 | + gutter={8} | ||
| 259 | + > | ||
| 204 | <PopoverTrigger | 260 | <PopoverTrigger |
| 205 | class={cn( | 261 | class={cn( |
| 206 | "topbar-control relative flex h-9 w-9 shrink-0 cursor-pointer items-center justify-center rounded-xl outline-hidden focus-visible:ring-2 focus-visible:ring-ring", | 262 | "topbar-control relative flex h-9 w-9 shrink-0 cursor-pointer items-center justify-center rounded-xl outline-hidden focus-visible:ring-2 focus-visible:ring-ring", |
| @@ -243,10 +299,13 @@ export function NotificationCenter() { | |||
| 243 | </Show> | 299 | </Show> |
| 244 | </div> | 300 | </div> |
| 245 | 301 | ||
| 246 | - <Tabs defaultValue="all" class="p-2"> | 302 | + <Show |
| 247 | - <TabsList class="mb-1 w-full"> | 303 | + when={previewNotification()} |
| 248 | - <TabsTrigger value="all" class="flex-1">{t("notifications.tabAll")}</TabsTrigger> | 304 | + fallback={ |
| 249 | - <TabsTrigger value="system" class="flex-1">{t("notifications.tabSystem")}</TabsTrigger> | 305 | + <Tabs defaultValue="all" class="p-2"> |
| 306 | + <TabsList class="mx-auto mb-2 h-8 w-fit min-w-[180px] p-0.5"> | ||
| 307 | + <TabsTrigger value="all" class="h-7 flex-1 px-3 text-[11px]">{t("notifications.tabAll")}</TabsTrigger> | ||
| 308 | + <TabsTrigger value="system" class="h-7 flex-1 px-3 text-[11px]">{t("notifications.tabSystem")}</TabsTrigger> | ||
| 250 | </TabsList> | 309 | </TabsList> |
| 251 | 310 | ||
| 252 | <TabsContent value="all" class="mt-0 max-h-80 space-y-1 overflow-y-auto"> | 311 | <TabsContent value="all" class="mt-0 max-h-80 space-y-1 overflow-y-auto"> |
| @@ -258,7 +317,7 @@ export function NotificationCenter() { | |||
| 258 | } | 317 | } |
| 259 | > | 318 | > |
| 260 | <Show | 319 | <Show |
| 261 | - when={activeNotifications().length > 0} | 320 | + when={notificationGroups().length > 0} |
| 262 | fallback={ | 321 | fallback={ |
| 263 | <div class="space-y-2 p-8 text-center"> | 322 | <div class="space-y-2 p-8 text-center"> |
| 264 | <div class="mx-auto flex h-10 w-10 items-center justify-center rounded-full bg-surface-tint text-text-subtle"> | 323 | <div class="mx-auto flex h-10 w-10 items-center justify-center rounded-full bg-surface-tint text-text-subtle"> |
| @@ -270,55 +329,139 @@ export function NotificationCenter() { | |||
| 270 | </div> | 329 | </div> |
| 271 | } | 330 | } |
| 272 | > | 331 | > |
| 273 | - <For each={activeNotifications()}> | 332 | + <div class="space-y-2"> |
| 274 | - {(item) => ( | 333 | + <For each={notificationGroups()}> |
| 275 | - <div | 334 | + {(group) => ( |
| 276 | - onClick={() => handleSelectNotification(item)} | 335 | + <section class={cn("overflow-hidden rounded-xl border", notificationGroupTone(group.type))}> |
| 277 | - class="group relative flex cursor-pointer select-none items-start gap-3 rounded-xl p-2.5 text-xs transition-colors hover:bg-surface-tint" | 336 | + <div class="flex items-center justify-between gap-2 px-2.5 py-2"> |
| 278 | - > | 337 | + <div class="flex min-w-0 items-center gap-2"> |
| 279 | - <div class="mt-0.5 flex h-8 w-8 shrink-0 items-center justify-center rounded-lg bg-surface-tint text-text-subtle transition-colors group-hover:bg-primary group-hover:text-primary-foreground"> | 338 | + <div class={cn("flex h-6 w-6 shrink-0 items-center justify-center rounded-md", notificationGroupIconTone(group.type))}> |
| 280 | - <Show when={item.type === "message"}> | 339 | + <Show when={group.type === "message"}> |
| 281 | - <IconMessage class="h-4 w-4" /> | 340 | + <IconMessage class="h-3.5 w-3.5" /> |
| 282 | - </Show> | 341 | + </Show> |
| 283 | - <Show when={item.type === "event"}> | 342 | + <Show when={group.type === "event"}> |
| 284 | - <IconCalendar class="h-4 w-4" /> | 343 | + <IconCalendar class="h-3.5 w-3.5" /> |
| 285 | - </Show> | 344 | + </Show> |
| 286 | - <Show when={item.type === "exam"}> | 345 | + <Show when={group.type === "exam"}> |
| 287 | - <IconExam class="h-4 w-4" /> | 346 | + <IconExam class="h-3.5 w-3.5" /> |
| 288 | - </Show> | 347 | + </Show> |
| 289 | - <Show when={item.type === "homework"}> | 348 | + <Show when={group.type === "homework"}> |
| 290 | - <IconHomework class="h-4 w-4" /> | 349 | + <IconHomework class="h-3.5 w-3.5" /> |
| 291 | - </Show> | 350 | + </Show> |
| 292 | - </div> | 351 | + </div> |
| 352 | + <span class="truncate text-[11px] font-bold uppercase tracking-[0.08em] text-text-subtle"> | ||
| 353 | + {notificationGroupLabel(group.type)} | ||
| 354 | + </span> | ||
| 355 | + </div> | ||
| 356 | + <span class="shrink-0 rounded-full bg-background/70 px-1.5 py-0.5 font-mono text-[10px] font-bold text-text-subtle"> | ||
| 357 | + {group.items.length} | ||
| 358 | + </span> | ||
| 359 | + </div> | ||
| 293 | 360 | ||
| 294 | - <div class="min-w-0 flex-1 space-y-0.5 pr-6"> | 361 | + <div class="space-y-0.5 px-1 pb-1"> |
| 295 | - <span class="block truncate font-semibold text-text-strong"> | 362 | + <For each={group.items}> |
| 296 | - {item.title} | 363 | + {(item) => ( |
| 297 | - </span> | 364 | + <div |
| 298 | - <p class="line-clamp-2 text-[11px] leading-snug text-text-subtle"> | 365 | + onClick={() => handleSelectNotification(item)} |
| 299 | - {item.description} | 366 | + class="group relative flex cursor-pointer select-none items-start gap-3 rounded-lg p-2 text-xs transition-colors hover:bg-background/70" |
| 300 | - </p> | 367 | + > |
| 301 | - </div> | 368 | + <div class="mt-0.5 flex h-8 w-8 shrink-0 items-center justify-center rounded-lg bg-background/75 text-text-subtle transition-colors group-hover:bg-primary group-hover:text-primary-foreground"> |
| 369 | + <Show when={item.type === "message"}> | ||
| 370 | + <IconMessage class="h-4 w-4" /> | ||
| 371 | + </Show> | ||
| 372 | + <Show when={item.type === "event"}> | ||
| 373 | + <IconCalendar class="h-4 w-4" /> | ||
| 374 | + </Show> | ||
| 375 | + <Show when={item.type === "exam"}> | ||
| 376 | + <IconExam class="h-4 w-4" /> | ||
| 377 | + </Show> | ||
| 378 | + <Show when={item.type === "homework"}> | ||
| 379 | + <IconHomework class="h-4 w-4" /> | ||
| 380 | + </Show> | ||
| 381 | + </div> | ||
| 302 | 382 | ||
| 303 | - <button | 383 | + <div class="min-w-0 flex-1 space-y-0.5 pr-6"> |
| 304 | - type="button" | 384 | + <span class="block truncate font-semibold text-text-strong"> |
| 305 | - class="absolute right-2 top-2.5 flex h-6 w-6 items-center justify-center rounded-md text-text-subtle/70 opacity-80 transition-all hover:bg-destructive/10 hover:text-destructive-text sm:opacity-0 sm:group-hover:opacity-100" | 385 | + {item.title} |
| 306 | - title={t("notifications.dismiss")} | 386 | + </span> |
| 307 | - onClick={(e) => handleDismissSingle(e, item.id)} | 387 | + <p class="line-clamp-2 text-[11px] leading-snug text-text-subtle"> |
| 308 | - > | 388 | + {item.description} |
| 309 | - <IconX class="h-3.5 w-3.5" /> | 389 | + </p> |
| 310 | - </button> | 390 | + </div> |
| 311 | - </div> | 391 | + |
| 312 | - )} | 392 | + <button |
| 313 | - </For> | 393 | + type="button" |
| 394 | + class="absolute right-2 top-2 flex h-6 w-6 items-center justify-center rounded-md text-text-subtle/70 opacity-80 transition-all hover:bg-destructive/10 hover:text-destructive-text sm:opacity-0 sm:group-hover:opacity-100" | ||
| 395 | + title={t("notifications.dismiss")} | ||
| 396 | + onClick={(e) => handleDismissSingle(e, item.id)} | ||
| 397 | + > | ||
| 398 | + <IconX class="h-3.5 w-3.5" /> | ||
| 399 | + </button> | ||
| 400 | + </div> | ||
| 401 | + )} | ||
| 402 | + </For> | ||
| 403 | + </div> | ||
| 404 | + </section> | ||
| 405 | + )} | ||
| 406 | + </For> | ||
| 407 | + </div> | ||
| 314 | </Show> | 408 | </Show> |
| 315 | </Suspense> | 409 | </Suspense> |
| 316 | </TabsContent> | 410 | </TabsContent> |
| 317 | 411 | ||
| 318 | - <TabsContent value="system" class="mt-0"> | 412 | + <TabsContent value="system" class="mt-0"> |
| 319 | - <ComingSoonPanel title={t("notifications.tabSystem")} class="border-0 p-3" /> | 413 | + <ComingSoonPanel title={t("notifications.tabSystem")} class="border-0 p-3" /> |
| 320 | - </TabsContent> | 414 | + </TabsContent> |
| 321 | - </Tabs> | 415 | + </Tabs> |
| 416 | + } | ||
| 417 | + > | ||
| 418 | + {(item) => ( | ||
| 419 | + <div class="space-y-4 p-4"> | ||
| 420 | + <div class="flex items-center gap-2"> | ||
| 421 | + <Button | ||
| 422 | + type="button" | ||
| 423 | + variant="ghost" | ||
| 424 | + size="sm" | ||
| 425 | + class="h-7 rounded-lg px-2 text-[11px] text-text-subtle" | ||
| 426 | + onClick={() => setPreviewNotification(null)} | ||
| 427 | + > | ||
| 428 | + <IconChevronLeft class="mr-1 h-3.5 w-3.5" /> | ||
| 429 | + {t("common.back")} | ||
| 430 | + </Button> | ||
| 431 | + </div> | ||
| 432 | + | ||
| 433 | + <div class="space-y-2"> | ||
| 434 | + <div class="flex items-start gap-3"> | ||
| 435 | + <div class={cn("flex h-10 w-10 shrink-0 items-center justify-center rounded-xl", notificationGroupIconTone(item().type))}> | ||
| 436 | + <Show when={item().type === "message"}> | ||
| 437 | + <IconMessage class="h-5 w-5" /> | ||
| 438 | + </Show> | ||
| 439 | + <Show when={item().type === "event"}> | ||
| 440 | + <IconCalendar class="h-5 w-5" /> | ||
| 441 | + </Show> | ||
| 442 | + <Show when={item().type === "exam"}> | ||
| 443 | + <IconExam class="h-5 w-5" /> | ||
| 444 | + </Show> | ||
| 445 | + <Show when={item().type === "homework"}> | ||
| 446 | + <IconHomework class="h-5 w-5" /> | ||
| 447 | + </Show> | ||
| 448 | + </div> | ||
| 449 | + <div class="min-w-0 space-y-1"> | ||
| 450 | + <h4 class="text-sm font-semibold leading-snug text-text-strong">{item().title}</h4> | ||
| 451 | + <p class="whitespace-pre-line text-xs leading-relaxed text-text-subtle"> | ||
| 452 | + {item().preview ?? item().description} | ||
| 453 | + </p> | ||
| 454 | + </div> | ||
| 455 | + </div> | ||
| 456 | + </div> | ||
| 457 | + | ||
| 458 | + <Button type="button" size="sm" class="w-full rounded-lg" onClick={handleNavigateToNotification}> | ||
| 459 | + <IconExternalLink class="mr-1.5 h-3.5 w-3.5" /> | ||
| 460 | + {t("notifications.goToPage")} | ||
| 461 | + </Button> | ||
| 462 | + </div> | ||
| 463 | + )} | ||
| 464 | + </Show> | ||
| 322 | </PopoverContent> | 465 | </PopoverContent> |
| 323 | </Popover> | 466 | </Popover> |
| 324 | ); | 467 | ); |
src/i18n/messages.tsmodified+3 -0
| @@ -545,6 +545,7 @@ export type MessageKey = | |||
| 545 | | "notifications.empty" | 545 | | "notifications.empty" |
| 546 | | "notifications.tabAll" | 546 | | "notifications.tabAll" |
| 547 | | "notifications.tabSystem" | 547 | | "notifications.tabSystem" |
| 548 | + | "notifications.goToPage" | ||
| 548 | | "errors.notFoundDescription" | 549 | | "errors.notFoundDescription" |
| 549 | | "errors.accessDeniedDescription" | 550 | | "errors.accessDeniedDescription" |
| 550 | | "network.offlineTitle" | 551 | | "network.offlineTitle" |
| @@ -2543,6 +2544,7 @@ const en: Dict = { | |||
| 2543 | "notifications.empty": "No new notifications yet.", | 2544 | "notifications.empty": "No new notifications yet.", |
| 2544 | "notifications.tabAll": "All", | 2545 | "notifications.tabAll": "All", |
| 2545 | "notifications.tabSystem": "System", | 2546 | "notifications.tabSystem": "System", |
| 2547 | + "notifications.goToPage": "Go to page", | ||
| 2546 | "errors.notFoundDescription": "The page you're looking for may have moved or been deleted.", | 2548 | "errors.notFoundDescription": "The page you're looking for may have moved or been deleted.", |
| 2547 | "errors.accessDeniedDescription": "Your role can't view this section. Ask an administrator if you need access.", | 2549 | "errors.accessDeniedDescription": "Your role can't view this section. Ask an administrator if you need access.", |
| 2548 | "network.offlineTitle": "You're offline", | 2550 | "network.offlineTitle": "You're offline", |
| @@ -4730,6 +4732,7 @@ const tr: Dict = { | |||
| 4730 | "notifications.empty": "Henüz yeni bir bildiriminiz yok.", | 4732 | "notifications.empty": "Henüz yeni bir bildiriminiz yok.", |
| 4731 | "notifications.tabAll": "Tümü", | 4733 | "notifications.tabAll": "Tümü", |
| 4732 | "notifications.tabSystem": "Sistem", | 4734 | "notifications.tabSystem": "Sistem", |
| 4735 | + "notifications.goToPage": "Sayfaya git", | ||
| 4733 | "errors.notFoundDescription": "Aradığın sayfa taşınmış ya da silinmiş olabilir.", | 4736 | "errors.notFoundDescription": "Aradığın sayfa taşınmış ya da silinmiş olabilir.", |
| 4734 | "errors.accessDeniedDescription": "Rolün bu bölümü görüntülemeye yetkili değil. Gerekliyse kurum yöneticinden yetki iste.", | 4737 | "errors.accessDeniedDescription": "Rolün bu bölümü görüntülemeye yetkili değil. Gerekliyse kurum yöneticinden yetki iste.", |
| 4735 | "network.offlineTitle": "Bağlantın koptu", | 4738 | "network.offlineTitle": "Bağlantın koptu", |
src/lib/notifications.tsmodified+27 -0
| @@ -5,11 +5,13 @@ export interface NotificationItem { | |||
| 5 | type: NotificationType; | 5 | type: NotificationType; |
| 6 | title: string; | 6 | title: string; |
| 7 | description: string; | 7 | description: string; |
| 8 | + preview?: string; | ||
| 8 | targetUrl: string; | 9 | targetUrl: string; |
| 9 | timestamp: number; | 10 | timestamp: number; |
| 10 | } | 11 | } |
| 11 | 12 | ||
| 12 | const STORAGE_KEY = "hezarfen.dismissedNotifications"; | 13 | const STORAGE_KEY = "hezarfen.dismissedNotifications"; |
| 14 | +const READ_STORAGE_KEY = "hezarfen.readNotifications"; | ||
| 13 | 15 | ||
| 14 | function canUseStorage(): boolean { | 16 | function canUseStorage(): boolean { |
| 15 | return typeof window !== "undefined" && typeof localStorage !== "undefined"; | 17 | return typeof window !== "undefined" && typeof localStorage !== "undefined"; |
| @@ -52,3 +54,28 @@ export function dismissAllNotificationIds(ids: string[]): Set<string> { | |||
| 52 | } | 54 | } |
| 53 | return current; | 55 | return current; |
| 54 | } | 56 | } |
| 57 | + | ||
| 58 | +export function getReadNotificationIds(): Set<string> { | ||
| 59 | + if (!canUseStorage()) return new Set(); | ||
| 60 | + try { | ||
| 61 | + const raw = localStorage.getItem(READ_STORAGE_KEY); | ||
| 62 | + if (!raw) return new Set(); | ||
| 63 | + const arr = JSON.parse(raw); | ||
| 64 | + return Array.isArray(arr) ? new Set(arr) : new Set(); | ||
| 65 | + } catch { | ||
| 66 | + return new Set(); | ||
| 67 | + } | ||
| 68 | +} | ||
| 69 | + | ||
| 70 | +export function markNotificationRead(id: string): Set<string> { | ||
| 71 | + const current = getReadNotificationIds(); | ||
| 72 | + current.add(id); | ||
| 73 | + if (canUseStorage()) { | ||
| 74 | + try { | ||
| 75 | + localStorage.setItem(READ_STORAGE_KEY, JSON.stringify(Array.from(current))); | ||
| 76 | + } catch { | ||
| 77 | + // ignore | ||
| 78 | + } | ||
| 79 | + } | ||
| 80 | + return current; | ||
| 81 | +} | ||
src/pages/messages-page.tsxmodified+13 -19
| @@ -185,23 +185,6 @@ export default function MessagesPage() { | |||
| 185 | return ( | 185 | return ( |
| 186 | <RouteGuard> | 186 | <RouteGuard> |
| 187 | <div class="space-y-4"> | 187 | <div class="space-y-4"> |
| 188 | - <div class="flex flex-wrap items-start justify-between gap-3"> | ||
| 189 | - <div class="min-w-0"> | ||
| 190 | - <h1 class="text-2xl font-semibold tracking-tight text-text-strong">{t("nav.messages")}</h1> | ||
| 191 | - </div> | ||
| 192 | - <Button | ||
| 193 | - size="sm" | ||
| 194 | - class="shrink-0 rounded-lg" | ||
| 195 | - onClick={() => { | ||
| 196 | - setReplyData(null); | ||
| 197 | - setComposeOpen(true); | ||
| 198 | - }} | ||
| 199 | - > | ||
| 200 | - <IconPlus class="h-4 w-4" /> | ||
| 201 | - <span>{t("messages.newMessage")}</span> | ||
| 202 | - </Button> | ||
| 203 | - </div> | ||
| 204 | - | ||
| 205 | <div class="min-h-[50vh] sm:min-h-[calc(100vh-11rem)]"> | 188 | <div class="min-h-[50vh] sm:min-h-[calc(100vh-11rem)]"> |
| 206 | <section class="data-shell overflow-hidden p-0"> | 189 | <section class="data-shell overflow-hidden p-0"> |
| 207 | <div class="flex min-h-[50vh] flex-col sm:min-h-[calc(100vh-11rem)]"> | 190 | <div class="flex min-h-[50vh] flex-col sm:min-h-[calc(100vh-11rem)]"> |
| @@ -215,9 +198,9 @@ export default function MessagesPage() { | |||
| 215 | </Show> | 198 | </Show> |
| 216 | </div> | 199 | </div> |
| 217 | {/* Folder toolbar — the app shell already owns the global sidebar. */} | 200 | {/* Folder toolbar — the app shell already owns the global sidebar. */} |
| 218 | - <aside class="flex flex-wrap items-center gap-2 border-b border-border-hairline bg-surface-overlay px-3 py-2.5"> | 201 | + <aside class="flex flex-wrap items-center justify-between gap-2 border-b border-border-hairline bg-surface-overlay px-3 py-2.5"> |
| 219 | {/* Folder navigation stays compact, leaving the only sidebar to the app shell. */} | 202 | {/* Folder navigation stays compact, leaving the only sidebar to the app shell. */} |
| 220 | - <nav class="flex min-w-0 max-w-full flex-1 items-center gap-1 overflow-x-auto"> | 203 | + <nav class="flex min-w-0 flex-1 items-center gap-1 overflow-x-auto"> |
| 221 | <button | 204 | <button |
| 222 | type="button" | 205 | type="button" |
| 223 | class={cn( | 206 | class={cn( |
| @@ -311,6 +294,17 @@ export default function MessagesPage() { | |||
| 311 | </div> | 294 | </div> |
| 312 | </button> | 295 | </button> |
| 313 | </nav> | 296 | </nav> |
| 297 | + <Button | ||
| 298 | + size="sm" | ||
| 299 | + class="shrink-0 rounded-lg" | ||
| 300 | + onClick={() => { | ||
| 301 | + setReplyData(null); | ||
| 302 | + setComposeOpen(true); | ||
| 303 | + }} | ||
| 304 | + > | ||
| 305 | + <IconPlus class="h-4 w-4" /> | ||
| 306 | + <span>{t("messages.newMessage")}</span> | ||
| 307 | + </Button> | ||
| 314 | </aside> | 308 | </aside> |
| 315 | 309 | ||
| 316 | {/* Gmail Main Content Area */} | 310 | {/* Gmail Main Content Area */} |