memos/web/src/pages/Inboxes.tsx
johnnyjoygh f5a60263b2 chore(ui): align frontend on shadcn kit
Design system:
- add semantic --success/--warning OKLCH tokens across themes; replace
  hardcoded green/amber feedback colors and their manual dark: overrides
- drop the unused @emotion dependency

Kit usage:
- migrate raw <button>/<input> to ui-kit components (actions) or
  <div>/<span> (non-action surfaces); keep genuinely custom looks as
  raw HTML with their own styles
- make kit usage prop-only (no className overrides): add Button
  size="icon-sm", Badge "warning" variant + "pill" shape
- extract a shared Tabs primitive (segmented/underline) and migrate
  Inboxes + UserProfile onto it
- tokenize z-index tiers as z-overlay/z-dropdown/z-tooltip
- export variant types (ButtonVariant/Size, BadgeVariant/Shape, TabsVariant)
- document the kit and its policy in components/ui/README.md
2026-06-21 09:17:04 +08:00

102 lines
4.6 KiB
TypeScript

import { timestampDate } from "@bufbuild/protobuf/wkt";
import { sortBy } from "lodash-es";
import { ArchiveIcon, BellIcon, InboxIcon } from "lucide-react";
import { useState } from "react";
import MemoCommentMessage from "@/components/Inbox/MemoCommentMessage";
import MemoMentionMessage from "@/components/Inbox/MemoMentionMessage";
import MobileHeader from "@/components/MobileHeader";
import Placeholder from "@/components/Placeholder";
import { Tabs, TabsList, TabsTrigger } from "@/components/ui/tabs";
import useMediaQuery from "@/hooks/useMediaQuery";
import { useNotifications } from "@/hooks/useUserQueries";
import { UserNotification, UserNotification_Status, UserNotification_Type } from "@/types/proto/api/v1/user_service_pb";
import { useTranslate } from "@/utils/i18n";
const Inboxes = () => {
const t = useTranslate();
const md = useMediaQuery("md");
const [filter, setFilter] = useState<"all" | "unread" | "archived">("all");
// Fetch notifications with React Query
const { data: fetchedNotifications = [] } = useNotifications();
const allNotifications = sortBy(fetchedNotifications, (notification: UserNotification) => {
return -((notification.createTime ? timestampDate(notification.createTime) : undefined)?.getTime() || 0);
});
const notifications = allNotifications.filter((notification) => {
if (filter === "unread") return notification.status === UserNotification_Status.UNREAD;
if (filter === "archived") return notification.status === UserNotification_Status.ARCHIVED;
return true;
});
const unreadCount = allNotifications.filter((n) => n.status === UserNotification_Status.UNREAD).length;
const archivedCount = allNotifications.filter((n) => n.status === UserNotification_Status.ARCHIVED).length;
return (
<section className="@container w-full max-w-5xl min-h-full flex flex-col justify-start items-center sm:pt-3 md:pt-6 pb-8">
{!md && <MobileHeader />}
<div className="w-full px-4 sm:px-6">
<div className="w-full border border-border flex flex-col justify-start items-start rounded-xl bg-background text-foreground overflow-hidden">
{/* Header */}
<div className="w-full px-4 py-4 border-b border-border">
<div className="flex flex-row justify-between items-center">
<div className="flex flex-row items-center gap-2">
<BellIcon className="w-5 h-auto text-muted-foreground" />
<h1 className="text-xl font-semibold">{t("common.inbox")}</h1>
{unreadCount > 0 && (
<span className="ml-1 px-2 py-0.5 text-xs font-medium rounded-full bg-primary text-primary-foreground">
{unreadCount}
</span>
)}
</div>
</div>
</div>
{/* Filter Tabs */}
<div className="w-full px-4 py-2 border-b border-border bg-muted/30">
<Tabs value={filter} onValueChange={(value) => setFilter(value as typeof filter)} variant="segmented">
<TabsList>
<TabsTrigger value="all">
{t("common.all")} ({allNotifications.length})
</TabsTrigger>
<TabsTrigger value="unread">
<InboxIcon className="w-3.5 h-auto" />
{t("inbox.unread")} ({unreadCount})
</TabsTrigger>
<TabsTrigger value="archived">
<ArchiveIcon className="w-3.5 h-auto" />
{t("common.archived")} ({archivedCount})
</TabsTrigger>
</TabsList>
</Tabs>
</div>
{/* Notifications List */}
<div className="w-full">
{notifications.length === 0 ? (
<Placeholder
variant="empty"
message={filter === "unread" ? t("inbox.no-unread") : filter === "archived" ? t("inbox.no-archived") : t("message.no-data")}
/>
) : (
<div className="flex flex-col">
{notifications.map((notification: UserNotification) => {
if (notification.type === UserNotification_Type.MEMO_COMMENT) {
return <MemoCommentMessage key={notification.name} notification={notification} />;
}
if (notification.type === UserNotification_Type.MEMO_MENTION) {
return <MemoMentionMessage key={notification.name} notification={notification} />;
}
return null;
})}
</div>
)}
</div>
</div>
</div>
</section>
);
};
export default Inboxes;