forge
Explore
Log in

Don't you dare go Hollow

🔔 refine messages and notifications

Browse files at this commit

81b2656ccbfc0fdd87d2313557a6c2660a330f3eBurak BoduroğluParent: e1768cd
  • fix
    • 🔔 refine messages and notifications
Show full message
fix: 🔔 refine messages and notifications

- reorganize the messages page header and notification grouping

- add unread states, notification previews, and localized page navigation

- remove the redundant topbar back action and improve spacing
src/components/layout/app-shell.tsxmodified+1 -14
@@ -21,7 +21,6 @@ import { celebiPanelOpen, openCelebiPanel, setCelebiPanelOpen } from "@/stores/c
2121 import { commandPaletteOpen, openCommandPalette, setCommandPaletteOpen } from "@/stores/command-palette";
2222 import { ShellFeedProvider } from "@/stores/shell-feed-context";
2323 import { usePreferences, useT } from "@/stores/preferences-context";
24-import { useGoBack } from "@/lib/use-go-back";
2524 import { cn } from "@/lib/cn";
2625 import { ModuleGate } from "@/components/layout/module-gate";
2726
@@ -38,7 +37,6 @@ export function AppShell(props: ParentProps) {
3837 const [profileOpen, setProfileOpen] = createSignal(false);
3938 const collapsed = () => prefs.sidebarCollapsed();
4039 const location = useLocation();
41- const goBack = useGoBack();
4240 const fullScreen = () => location().pathname.startsWith("/exam-room/");
4341 const routeLabel = createMemo(() => {
4442 const key = routeLabelKey(location().pathname, auth.user()?.role);
@@ -133,19 +131,8 @@ export function AppShell(props: ParentProps) {
133131
134132 <main id="main-content" tabIndex={-1} class="min-w-0 flex-1 outline-hidden">
135133 <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">
137135 <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>
149136 <span class="hidden truncate text-sm font-semibold sm:block" title={routeLabel()}>{routeLabel()}</span>
150137 </div>
151138
src/components/layout/notification-center.tsxmodified+198 -55
@@ -8,7 +8,9 @@ import { Tabs, TabsContent, TabsList, TabsTrigger } from "@/components/ui/tabs";
88 import {
99 IconBell,
1010 IconCalendar,
11+ IconChevronLeft,
1112 IconExam,
13+ IconExternalLink,
1214 IconHomework,
1315 IconMessage,
1416 IconTrash,
@@ -20,7 +22,10 @@ import {
2022 dismissAllNotificationIds,
2123 dismissNotificationId,
2224 getDismissedNotificationIds,
25+ getReadNotificationIds,
26+ markNotificationRead,
2327 type NotificationItem,
28+ type NotificationType,
2429 } from "@/lib/notifications";
2530 import { usePreferences } from "@/stores/preferences-context";
2631 import { useShellFeed } from "@/stores/shell-feed-context";
@@ -32,6 +37,8 @@ export function NotificationCenter() {
3237 const feed = useShellFeed();
3338 const [open, setOpen] = createSignal(false);
3439 const [dismissedIds, setDismissedIds] = createSignal<Set<string>>(getDismissedNotificationIds());
40+ const [readIds, setReadIds] = createSignal<Set<string>>(getReadNotificationIds());
41+ const [previewNotification, setPreviewNotification] = createSignal<NotificationItem | null>(null);
3542
3643 // Shell feed data comes from the shared poller (ShellFeedProvider): one fetch
3744 // per source for the whole shell instead of a duplicate set here. Every read
@@ -58,11 +65,13 @@ export function NotificationCenter() {
5865 // id DESC, so an older unread message is simply not in it.
5966 const msgs = feed.unreadMessages().items;
6067 for (const m of msgs) {
68+ const body = m.body.replace(/<[^>]*>?/gm, "").trim();
6169 list.push({
6270 id: `msg_${m.id}`,
6371 type: "message",
6472 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,
6675 targetUrl: "/messages",
6776 timestamp: m.sent_at,
6877 });
@@ -147,6 +156,37 @@ export function NotificationCenter() {
147156 return allNotifications().filter((item) => !dismissed.has(item.id));
148157 });
149158
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+
150190 // The list only holds the newest 10 unread messages; `total` is the real
151191 // server-side unread count, so the rest still counts towards the badge.
152192 // Those extra rows have no id here, so they cannot be dismissed one by one:
@@ -166,7 +206,7 @@ export function NotificationCenter() {
166206 const sinceDismissAll = page.total - dismissedUnreadTotal() - activeMessageCount();
167207 return Math.max(0, Math.min(beyondPage, sinceDismissAll));
168208 };
169- const unreadCount = () => activeNotifications().length + unlistedUnread();
209+ const unreadCount = () => unreadNotifications().length + unlistedUnread();
170210
171211 const handleDismissSingle = (evt: MouseEvent, id: string) => {
172212 evt.stopPropagation();
@@ -182,7 +222,11 @@ export function NotificationCenter() {
182222 };
183223
184224 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.
186230 if (item.id.startsWith("msg_")) {
187231 const realId = item.id.replace("msg_", "");
188232 try {
@@ -192,15 +236,27 @@ export function NotificationCenter() {
192236 // ignore
193237 }
194238 }
195- // Dismiss locally
196- const updated = dismissNotificationId(item.id);
197- setDismissedIds(new Set(updated));
239+ setPreviewNotification(item);
240+ };
241+
242+ const handleNavigateToNotification = () => {
243+ const item = previewNotification();
244+ if (!item) return;
245+ setPreviewNotification(null);
198246 setOpen(false);
199247 void navigate({ to: item.targetUrl });
200248 };
201249
202250 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+ >
204260 <PopoverTrigger
205261 class={cn(
206262 "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() {
243299 </Show>
244300 </div>
245301
246- <Tabs defaultValue="all" class="p-2">
247- <TabsList class="mb-1 w-full">
248- <TabsTrigger value="all" class="flex-1">{t("notifications.tabAll")}</TabsTrigger>
249- <TabsTrigger value="system" class="flex-1">{t("notifications.tabSystem")}</TabsTrigger>
302+ <Show
303+ when={previewNotification()}
304+ fallback={
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>
250309 </TabsList>
251310
252311 <TabsContent value="all" class="mt-0 max-h-80 space-y-1 overflow-y-auto">
@@ -258,7 +317,7 @@ export function NotificationCenter() {
258317 }
259318 >
260319 <Show
261- when={activeNotifications().length > 0}
320+ when={notificationGroups().length > 0}
262321 fallback={
263322 <div class="space-y-2 p-8 text-center">
264323 <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() {
270329 </div>
271330 }
272331 >
273- <For each={activeNotifications()}>
274- {(item) => (
275- <div
276- onClick={() => handleSelectNotification(item)}
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"
278- >
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">
280- <Show when={item.type === "message"}>
281- <IconMessage class="h-4 w-4" />
282- </Show>
283- <Show when={item.type === "event"}>
284- <IconCalendar class="h-4 w-4" />
285- </Show>
286- <Show when={item.type === "exam"}>
287- <IconExam class="h-4 w-4" />
288- </Show>
289- <Show when={item.type === "homework"}>
290- <IconHomework class="h-4 w-4" />
291- </Show>
292- </div>
332+ <div class="space-y-2">
333+ <For each={notificationGroups()}>
334+ {(group) => (
335+ <section class={cn("overflow-hidden rounded-xl border", notificationGroupTone(group.type))}>
336+ <div class="flex items-center justify-between gap-2 px-2.5 py-2">
337+ <div class="flex min-w-0 items-center gap-2">
338+ <div class={cn("flex h-6 w-6 shrink-0 items-center justify-center rounded-md", notificationGroupIconTone(group.type))}>
339+ <Show when={group.type === "message"}>
340+ <IconMessage class="h-3.5 w-3.5" />
341+ </Show>
342+ <Show when={group.type === "event"}>
343+ <IconCalendar class="h-3.5 w-3.5" />
344+ </Show>
345+ <Show when={group.type === "exam"}>
346+ <IconExam class="h-3.5 w-3.5" />
347+ </Show>
348+ <Show when={group.type === "homework"}>
349+ <IconHomework class="h-3.5 w-3.5" />
350+ </Show>
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>
293360
294- <div class="min-w-0 flex-1 space-y-0.5 pr-6">
295- <span class="block truncate font-semibold text-text-strong">
296- {item.title}
297- </span>
298- <p class="line-clamp-2 text-[11px] leading-snug text-text-subtle">
299- {item.description}
300- </p>
301- </div>
361+ <div class="space-y-0.5 px-1 pb-1">
362+ <For each={group.items}>
363+ {(item) => (
364+ <div
365+ onClick={() => handleSelectNotification(item)}
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"
367+ >
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>
302382
303- <button
304- type="button"
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"
306- title={t("notifications.dismiss")}
307- onClick={(e) => handleDismissSingle(e, item.id)}
308- >
309- <IconX class="h-3.5 w-3.5" />
310- </button>
311- </div>
312- )}
313- </For>
383+ <div class="min-w-0 flex-1 space-y-0.5 pr-6">
384+ <span class="block truncate font-semibold text-text-strong">
385+ {item.title}
386+ </span>
387+ <p class="line-clamp-2 text-[11px] leading-snug text-text-subtle">
388+ {item.description}
389+ </p>
390+ </div>
391+
392+ <button
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>
314408 </Show>
315409 </Suspense>
316410 </TabsContent>
317411
318- <TabsContent value="system" class="mt-0">
319- <ComingSoonPanel title={t("notifications.tabSystem")} class="border-0 p-3" />
320- </TabsContent>
321- </Tabs>
412+ <TabsContent value="system" class="mt-0">
413+ <ComingSoonPanel title={t("notifications.tabSystem")} class="border-0 p-3" />
414+ </TabsContent>
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>
322465 </PopoverContent>
323466 </Popover>
324467 );
src/i18n/messages.tsmodified+3 -0
@@ -545,6 +545,7 @@ export type MessageKey =
545545 | "notifications.empty"
546546 | "notifications.tabAll"
547547 | "notifications.tabSystem"
548+ | "notifications.goToPage"
548549 | "errors.notFoundDescription"
549550 | "errors.accessDeniedDescription"
550551 | "network.offlineTitle"
@@ -2543,6 +2544,7 @@ const en: Dict = {
25432544 "notifications.empty": "No new notifications yet.",
25442545 "notifications.tabAll": "All",
25452546 "notifications.tabSystem": "System",
2547+ "notifications.goToPage": "Go to page",
25462548 "errors.notFoundDescription": "The page you're looking for may have moved or been deleted.",
25472549 "errors.accessDeniedDescription": "Your role can't view this section. Ask an administrator if you need access.",
25482550 "network.offlineTitle": "You're offline",
@@ -4730,6 +4732,7 @@ const tr: Dict = {
47304732 "notifications.empty": "Henüz yeni bir bildiriminiz yok.",
47314733 "notifications.tabAll": "Tümü",
47324734 "notifications.tabSystem": "Sistem",
4735+ "notifications.goToPage": "Sayfaya git",
47334736 "errors.notFoundDescription": "Aradığın sayfa taşınmış ya da silinmiş olabilir.",
47344737 "errors.accessDeniedDescription": "Rolün bu bölümü görüntülemeye yetkili değil. Gerekliyse kurum yöneticinden yetki iste.",
47354738 "network.offlineTitle": "Bağlantın koptu",
src/lib/notifications.tsmodified+27 -0
@@ -5,11 +5,13 @@ export interface NotificationItem {
55 type: NotificationType;
66 title: string;
77 description: string;
8+ preview?: string;
89 targetUrl: string;
910 timestamp: number;
1011 }
1112
1213 const STORAGE_KEY = "hezarfen.dismissedNotifications";
14+const READ_STORAGE_KEY = "hezarfen.readNotifications";
1315
1416 function canUseStorage(): boolean {
1517 return typeof window !== "undefined" && typeof localStorage !== "undefined";
@@ -52,3 +54,28 @@ export function dismissAllNotificationIds(ids: string[]): Set<string> {
5254 }
5355 return current;
5456 }
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() {
185185 return (
186186 <RouteGuard>
187187 <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-
205188 <div class="min-h-[50vh] sm:min-h-[calc(100vh-11rem)]">
206189 <section class="data-shell overflow-hidden p-0">
207190 <div class="flex min-h-[50vh] flex-col sm:min-h-[calc(100vh-11rem)]">
@@ -215,9 +198,9 @@ export default function MessagesPage() {
215198 </Show>
216199 </div>
217200 {/* 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">
219202 {/* 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">
221204 <button
222205 type="button"
223206 class={cn(
@@ -311,6 +294,17 @@ export default function MessagesPage() {
311294 </div>
312295 </button>
313296 </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>
314308 </aside>
315309
316310 {/* Gmail Main Content Area */}