diff --git a/src/components/layout/app-shell.tsx b/src/components/layout/app-shell.tsx index d7c5f11..de978b2 100644 --- a/src/components/layout/app-shell.tsx +++ b/src/components/layout/app-shell.tsx @@ -21,7 +21,6 @@ import { celebiPanelOpen, openCelebiPanel, setCelebiPanelOpen } from "@/stores/c import { commandPaletteOpen, openCommandPalette, setCommandPaletteOpen } from "@/stores/command-palette"; import { ShellFeedProvider } from "@/stores/shell-feed-context"; import { usePreferences, useT } from "@/stores/preferences-context"; -import { useGoBack } from "@/lib/use-go-back"; import { cn } from "@/lib/cn"; import { ModuleGate } from "@/components/layout/module-gate"; @@ -38,7 +37,6 @@ export function AppShell(props: ParentProps) { const [profileOpen, setProfileOpen] = createSignal(false); const collapsed = () => prefs.sidebarCollapsed(); const location = useLocation(); - const goBack = useGoBack(); const fullScreen = () => location().pathname.startsWith("/exam-room/"); const routeLabel = createMemo(() => { const key = routeLabelKey(location().pathname, auth.user()?.role); @@ -133,19 +131,8 @@ export function AppShell(props: ParentProps) {
-
+
- - -
diff --git a/src/components/layout/notification-center.tsx b/src/components/layout/notification-center.tsx index f4fcc4f..0a9f145 100644 --- a/src/components/layout/notification-center.tsx +++ b/src/components/layout/notification-center.tsx @@ -8,7 +8,9 @@ import { Tabs, TabsContent, TabsList, TabsTrigger } from "@/components/ui/tabs"; import { IconBell, IconCalendar, + IconChevronLeft, IconExam, + IconExternalLink, IconHomework, IconMessage, IconTrash, @@ -20,7 +22,10 @@ import { dismissAllNotificationIds, dismissNotificationId, getDismissedNotificationIds, + getReadNotificationIds, + markNotificationRead, type NotificationItem, + type NotificationType, } from "@/lib/notifications"; import { usePreferences } from "@/stores/preferences-context"; import { useShellFeed } from "@/stores/shell-feed-context"; @@ -32,6 +37,8 @@ export function NotificationCenter() { const feed = useShellFeed(); const [open, setOpen] = createSignal(false); const [dismissedIds, setDismissedIds] = createSignal>(getDismissedNotificationIds()); + const [readIds, setReadIds] = createSignal>(getReadNotificationIds()); + const [previewNotification, setPreviewNotification] = createSignal(null); // Shell feed data comes from the shared poller (ShellFeedProvider): one fetch // per source for the whole shell instead of a duplicate set here. Every read @@ -58,11 +65,13 @@ export function NotificationCenter() { // id DESC, so an older unread message is simply not in it. const msgs = feed.unreadMessages().items; for (const m of msgs) { + const body = m.body.replace(/<[^>]*>?/gm, "").trim(); list.push({ id: `msg_${m.id}`, type: "message", title: personLabel(m.sender), - description: m.subject || m.body.replace(/<[^>]*>?/gm, "").trim(), + description: m.subject || body, + preview: m.subject ? `${m.subject}\n${body}` : body, targetUrl: "/messages", timestamp: m.sent_at, }); @@ -147,6 +156,37 @@ export function NotificationCenter() { return allNotifications().filter((item) => !dismissed.has(item.id)); }); + const isUnread = (item: NotificationItem) => !readIds().has(item.id); + const unreadNotifications = createMemo(() => activeNotifications().filter(isUnread)); + + const notificationGroupOrder: NotificationType[] = ["message", "event", "exam", "homework"]; + const notificationGroupLabel = (type: NotificationType) => { + if (type === "message") return t("nav.messages"); + if (type === "event") return t("events.title"); + if (type === "exam") return t("exams.title"); + return t("homework.title"); + }; + const notificationGroupTone = (type: NotificationType) => { + if (type === "message") return "border-primary/20 bg-primary/[0.035]"; + if (type === "event") return "border-violet-500/20 bg-violet-500/[0.035]"; + if (type === "exam") return "border-amber-500/25 bg-amber-500/[0.045]"; + return "border-emerald-500/20 bg-emerald-500/[0.035]"; + }; + const notificationGroupIconTone = (type: NotificationType) => { + if (type === "message") return "bg-primary/10 text-primary-text"; + if (type === "event") return "bg-violet-500/10 text-violet-700 dark:text-violet-300"; + if (type === "exam") return "bg-amber-500/10 text-amber-700 dark:text-amber-300"; + return "bg-emerald-500/10 text-emerald-700 dark:text-emerald-300"; + }; + const notificationGroups = createMemo(() => + notificationGroupOrder + .map((type) => ({ + type, + items: activeNotifications().filter((item) => item.type === type), + })) + .filter((group) => group.items.length > 0) + ); + // The list only holds the newest 10 unread messages; `total` is the real // server-side unread count, so the rest still counts towards the badge. // Those extra rows have no id here, so they cannot be dismissed one by one: @@ -166,7 +206,7 @@ export function NotificationCenter() { const sinceDismissAll = page.total - dismissedUnreadTotal() - activeMessageCount(); return Math.max(0, Math.min(beyondPage, sinceDismissAll)); }; - const unreadCount = () => activeNotifications().length + unlistedUnread(); + const unreadCount = () => unreadNotifications().length + unlistedUnread(); const handleDismissSingle = (evt: MouseEvent, id: string) => { evt.stopPropagation(); @@ -182,7 +222,11 @@ export function NotificationCenter() { }; const handleSelectNotification = async (item: NotificationItem) => { - // If message notification, mark read in backend + if (isUnread(item)) { + setReadIds(new Set(markNotificationRead(item.id))); + } + + // Message notifications also need to be marked read in the backend. if (item.id.startsWith("msg_")) { const realId = item.id.replace("msg_", ""); try { @@ -192,15 +236,27 @@ export function NotificationCenter() { // ignore } } - // Dismiss locally - const updated = dismissNotificationId(item.id); - setDismissedIds(new Set(updated)); + setPreviewNotification(item); + }; + + const handleNavigateToNotification = () => { + const item = previewNotification(); + if (!item) return; + setPreviewNotification(null); setOpen(false); void navigate({ to: item.targetUrl }); }; return ( - + { + setOpen(nextOpen); + if (!nextOpen) setPreviewNotification(null); + }} + placement="bottom-end" + gutter={8} + > - - - {t("notifications.tabAll")} - {t("notifications.tabSystem")} + + + {t("notifications.tabAll")} + {t("notifications.tabSystem")} @@ -258,7 +317,7 @@ export function NotificationCenter() { } > 0} + when={notificationGroups().length > 0} fallback={
@@ -270,55 +329,139 @@ export function NotificationCenter() {
} > - - {(item) => ( -
handleSelectNotification(item)} - 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" - > -
- - - - - - - - - - - - -
+
+ + {(group) => ( +
+
+
+
+ + + + + + + + + + + + +
+ + {notificationGroupLabel(group.type)} + +
+ + {group.items.length} + +
-
- - {item.title} - -

- {item.description} -

-
+
+ + {(item) => ( +
handleSelectNotification(item)} + class="group relative flex cursor-pointer select-none items-start gap-3 rounded-lg p-2 text-xs transition-colors hover:bg-background/70" + > +
+ + + + + + + + + + + + +
- -
- )} -
+
+ + {item.title} + +

+ {item.description} +

+
+ + +
+ )} + +
+ + )} + +
- - - - + + + + + } + > + {(item) => ( +
+
+ +
+ +
+
+
+ + + + + + + + + + + + +
+
+

{item().title}

+

+ {item().preview ?? item().description} +

+
+
+
+ + +
+ )} + ); diff --git a/src/i18n/messages.ts b/src/i18n/messages.ts index 5bc7bf8..c56e710 100644 --- a/src/i18n/messages.ts +++ b/src/i18n/messages.ts @@ -545,6 +545,7 @@ export type MessageKey = | "notifications.empty" | "notifications.tabAll" | "notifications.tabSystem" + | "notifications.goToPage" | "errors.notFoundDescription" | "errors.accessDeniedDescription" | "network.offlineTitle" @@ -2543,6 +2544,7 @@ const en: Dict = { "notifications.empty": "No new notifications yet.", "notifications.tabAll": "All", "notifications.tabSystem": "System", + "notifications.goToPage": "Go to page", "errors.notFoundDescription": "The page you're looking for may have moved or been deleted.", "errors.accessDeniedDescription": "Your role can't view this section. Ask an administrator if you need access.", "network.offlineTitle": "You're offline", @@ -4730,6 +4732,7 @@ const tr: Dict = { "notifications.empty": "Henüz yeni bir bildiriminiz yok.", "notifications.tabAll": "Tümü", "notifications.tabSystem": "Sistem", + "notifications.goToPage": "Sayfaya git", "errors.notFoundDescription": "Aradığın sayfa taşınmış ya da silinmiş olabilir.", "errors.accessDeniedDescription": "Rolün bu bölümü görüntülemeye yetkili değil. Gerekliyse kurum yöneticinden yetki iste.", "network.offlineTitle": "Bağlantın koptu", diff --git a/src/lib/notifications.ts b/src/lib/notifications.ts index 42c9e9b..4ab1ad2 100644 --- a/src/lib/notifications.ts +++ b/src/lib/notifications.ts @@ -5,11 +5,13 @@ export interface NotificationItem { type: NotificationType; title: string; description: string; + preview?: string; targetUrl: string; timestamp: number; } const STORAGE_KEY = "hezarfen.dismissedNotifications"; +const READ_STORAGE_KEY = "hezarfen.readNotifications"; function canUseStorage(): boolean { return typeof window !== "undefined" && typeof localStorage !== "undefined"; @@ -52,3 +54,28 @@ export function dismissAllNotificationIds(ids: string[]): Set { } return current; } + +export function getReadNotificationIds(): Set { + if (!canUseStorage()) return new Set(); + try { + const raw = localStorage.getItem(READ_STORAGE_KEY); + if (!raw) return new Set(); + const arr = JSON.parse(raw); + return Array.isArray(arr) ? new Set(arr) : new Set(); + } catch { + return new Set(); + } +} + +export function markNotificationRead(id: string): Set { + const current = getReadNotificationIds(); + current.add(id); + if (canUseStorage()) { + try { + localStorage.setItem(READ_STORAGE_KEY, JSON.stringify(Array.from(current))); + } catch { + // ignore + } + } + return current; +} diff --git a/src/pages/messages-page.tsx b/src/pages/messages-page.tsx index 5fdaea1..295dca7 100644 --- a/src/pages/messages-page.tsx +++ b/src/pages/messages-page.tsx @@ -185,23 +185,6 @@ export default function MessagesPage() { return (
-
-
-

{t("nav.messages")}

-
- -
-
@@ -215,9 +198,9 @@ export default function MessagesPage() {
{/* Folder toolbar — the app shell already owns the global sidebar. */} -