File size: 4,458 Bytes
9d4a3b0
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
"use client";

import Link from "next/link";
import { useMemo, useState } from "react";
import { Bell, BriefcaseBusiness, MessageCircle, MoreHorizontal, ThumbsUp, UserPlus, type LucideIcon } from "lucide-react";
import { Avatar } from "@/components/Avatar";
import { people } from "@/lib/demo-data";

type NotificationCategory = "all" | "posts" | "mentions";
type NotificationItem = {
  id: string;
  category: NotificationCategory;
  icon: LucideIcon;
  person?: typeof people[number];
  text: string;
  age: string;
  href: string;
  unread?: boolean;
};

const filters: Array<{ label: string; value: NotificationCategory }> = [
  { label: "All", value: "all" },
  { label: "My posts", value: "posts" },
  { label: "Mentions", value: "mentions" },
];

const notifications: NotificationItem[] = [
  { id: "network-accepted", category: "all", icon: UserPlus, person: people[0], text: "Jordan Lee accepted your invitation. You can now see each other’s updates.", age: "1h", href: "/my-network", unread: true },
  { id: "post-reactions", category: "posts", icon: ThumbsUp, person: people[1], text: "Priya Raman and 18 others reacted to your post about design review rituals.", age: "3h", href: "/feed", unread: true },
  { id: "post-comment", category: "posts", icon: MessageCircle, person: people[2], text: "Noah Williams commented: “This is exactly the tradeoff our team is discussing.”", age: "5h", href: "/feed", unread: true },
  { id: "mention-thread", category: "mentions", icon: MessageCircle, person: people[1], text: "Priya Raman mentioned you in a thread about responsible AI review rituals.", age: "7h", href: "/notifications" },
  { id: "job-alert", category: "all", icon: BriefcaseBusiness, text: "New roles match your job alert: Senior Product Designer in San Francisco Bay Area.", age: "1d", href: "/jobs" },
];

export function NotificationsView() {
  const [activeFilter, setActiveFilter] = useState<NotificationCategory>("all");
  const [openMenuId, setOpenMenuId] = useState<string | null>(null);
  const filteredNotifications = useMemo(() => (
    activeFilter === "all"
      ? notifications
      : notifications.filter((item) => item.category === activeFilter)
  ), [activeFilter]);

  return (
    <div className="notifications-layout">
      <aside className="surface notification-settings">
        <Bell size={28} />
        <h2>Manage your notifications</h2>
        <p>Choose what you hear about and how often.</p>
        <button>View settings</button>
      </aside>
      <section className="surface notifications-feed">
        <div className="notification-tabs" role="tablist" aria-label="Notification filters">
          {filters.map((filter) => (
            <button
              aria-selected={activeFilter === filter.value}
              className={activeFilter === filter.value ? "active" : ""}
              key={filter.value}
              onClick={() => {
                setActiveFilter(filter.value);
                setOpenMenuId(null);
              }}
              role="tab"
              type="button"
            >
              {filter.label}
            </button>
          ))}
        </div>
        {filteredNotifications.length ? filteredNotifications.map((item) => {
          const Icon = item.icon;
          const open = openMenuId === item.id;
          return (
            <article className={`notification-row ${item.unread ? "unread" : ""}`} key={item.id}>
              {item.person ? <Avatar name={item.person.name} src={item.person.avatar} size="lg" /> : <span className="notification-icon"><Icon size={23} /></span>}
              <Link prefetch={false} className="notification-copy" href={item.href}><p>{item.text}</p></Link>
              <time>{item.age}</time>
              <span className="notification-menu">
                <button className="icon-button" aria-expanded={open} aria-label="Notification menu" onClick={() => setOpenMenuId(open ? null : item.id)} type="button">
                  <MoreHorizontal size={20} />
                </button>
                {open && <span className="notification-menu-popover" role="menu"><button type="button">Mark as read</button><button type="button">Mute updates</button></span>}
              </span>
            </article>
          );
        }) : <div className="empty-state"><Bell size={34} /><h3>No notifications here</h3><p>New updates will appear when they match this filter.</p></div>}
      </section>
    </div>
  );
}