hezarfen_frontend
Clone
https://git.tahinli.com/archive/hezarfen_frontend.git
0 watching0 forksTypeScript5.5 MiB5fcd955Burak Boduroğlu2 months ago730 commits
| 1 | import { Show, createEffect, createSignal } from "solid-js"; |
| 2 | import { useNavigate } from "@tanstack/solid-router"; |
| 3 | import { Popover, PopoverContent, PopoverTrigger } from "@/components/ui/popover"; |
| 4 | import { IconBell } from "@/components/ui/icons"; |
| 5 | import { cn } from "@/lib/cn"; |
| 6 | import { formatUnreadCount } from "@/lib/notifications"; |
| 7 | import { createNotificationFeed } from "@/components/layout/notification-feed"; |
| 8 | import { NotificationList } from "@/components/layout/notification-list"; |
| 9 | import { useT } from "@/stores/preferences-context"; |
| 10 | |
| 11 | /** The header bell: the notification list in a popover. */ |
| 12 | export function NotificationCenter() { |
| 13 | const t = useT(); |
| 14 | const navigate = useNavigate(); |
| 15 | const feed = createNotificationFeed(); |
| 16 | const [open, setOpen] = createSignal(false); |
| 17 | |
| 18 | createEffect(() => { |
| 19 | if (open()) { |
| 20 | feed.opened(); |
| 21 | feed.refreshAll(); |
| 22 | } |
| 23 | }); |
| 24 | |
| 25 | const unreadCount = feed.unreadCount; |
| 26 | let panel: HTMLDivElement | undefined; |
| 27 | |
| 28 | return ( |
| 29 | <Popover |
| 30 | open={open()} |
| 31 | onOpenChange={setOpen} |
| 32 | placement="bottom-end" |
| 33 | gutter={8} |
| 34 | > |
| 35 | <PopoverTrigger |
| 36 | class={cn( |
| 37 | "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", |
| 38 | open() && "bg-muted text-foreground" |
| 39 | )} |
| 40 | title={t("notifications.title")} |
| 41 | aria-label={ |
| 42 | unreadCount() > 0 |
| 43 | ? `${t("notifications.title")} — ${t("notifications.unreadCount", { count: unreadCount() })}` |
| 44 | : t("notifications.title") |
| 45 | } |
| 46 | > |
| 47 | <IconBell class="h-4 w-4" /> |
| 48 | <Show when={unreadCount() > 0}> |
| 49 | <span class="absolute -top-1 -right-1 flex h-5 min-w-5 items-center justify-center rounded-full bg-destructive px-1 text-[11px] font-bold text-destructive-foreground ring-2 ring-background" aria-hidden="true"> |
| 50 | {formatUnreadCount(unreadCount())} |
| 51 | </span> |
| 52 | </Show> |
| 53 | </PopoverTrigger> |
| 54 | |
| 55 | {/* Focus lands on the popover itself, not its first control: that is |
| 56 | "Tümünü sil", and one Enter would clear the whole list. */} |
| 57 | <PopoverContent |
| 58 | class="w-80 sm:w-96 rounded-xl border border-border-line bg-surface-base p-0 shadow-2xl overflow-hidden" |
| 59 | ref={(el: HTMLDivElement) => { |
| 60 | panel = el; |
| 61 | }} |
| 62 | tabIndex={-1} |
| 63 | aria-label={t("notifications.title")} |
| 64 | onOpenAutoFocus={(event: Event) => { |
| 65 | event.preventDefault(); |
| 66 | panel?.focus(); |
| 67 | }} |
| 68 | > |
| 69 | <NotificationList |
| 70 | feed={feed} |
| 71 | onNavigate={(url) => { |
| 72 | setOpen(false); |
| 73 | void navigate({ to: url }); |
| 74 | }} |
| 75 | /> |
| 76 | </PopoverContent> |
| 77 | </Popover> |
| 78 | ); |
| 79 | } |