Some checks failed
Security / deep-security-scan (push) Failing after 20m5s
DR Drill / dr-drill (push) Failing after 1m31s
CI / scheduled-backup (push) Failing after 1m31s
CI / backup-verify (push) Has been skipped
CI / weekly-dr-drill (push) Failing after 0s
CI / build-deploy (push) Has been cancelled
CI / security-scan (push) Has been cancelled
主要变更: - 新增 lesson-preparation 模块: 备课编辑器、节点编辑、AI 建议、知识点选择、版本历史、作业发布 - 新增 shared 通用组件: charts/question-bank-filters/schedule-list/ui (chip-nav/filter-bar/page-header/stat-card/stat-item) - 新增 student/admin 端 loading.tsx 与 error.tsx, 优化加载与错误态体验 - 新增 teacher/lesson-plans 页面 (列表/新建/编辑) - 新增 drizzle 迁移 0002_tiny_lionheart 及 snapshot - 新增 textbooks/schema.ts 与 exams/utils/normalize-structure.ts - 修复 Tiptap v3 SSR hydration 崩溃 (rich-text-block immediatelyRender: false) - 重构多模块 data-access/actions/组件, 修复权限校验与类型规范 - 同步架构文档 004/005 反映新增模块、导出、依赖关系 - 归档 bugs/* 测试报告与 e2e 测试脚本 (admin/parent/student/teacher web_test)
118 lines
4.3 KiB
TypeScript
118 lines
4.3 KiB
TypeScript
"use client"
|
|
|
|
import { useMemo, useState } from "react"
|
|
import Link from "next/link"
|
|
import { Mail, MailOpen, Plus, Send, Inbox } from "lucide-react"
|
|
|
|
import { Badge } from "@/shared/components/ui/badge"
|
|
import { Button } from "@/shared/components/ui/button"
|
|
import { Card, CardContent, CardHeader } from "@/shared/components/ui/card"
|
|
import { EmptyState } from "@/shared/components/ui/empty-state"
|
|
import { Tabs, TabsList, TabsTrigger } from "@/shared/components/ui/tabs"
|
|
import { cn, formatDate } from "@/shared/lib/utils"
|
|
import { usePermission } from "@/shared/hooks/use-permission"
|
|
import { Permissions } from "@/shared/types/permissions"
|
|
|
|
import type { Message, MessageType } from "../types"
|
|
|
|
type Tab = "inbox" | "sent"
|
|
|
|
export function MessageList({
|
|
messages,
|
|
currentUserId,
|
|
initialType = "inbox",
|
|
}: {
|
|
messages: Message[]
|
|
currentUserId: string
|
|
initialType?: MessageType
|
|
}) {
|
|
const [tab, setTab] = useState<Tab>(initialType === "sent" ? "sent" : "inbox")
|
|
const { hasPermission } = usePermission()
|
|
const canSend = hasPermission(Permissions.MESSAGE_SEND)
|
|
|
|
const filtered = useMemo(() => {
|
|
if (tab === "inbox") return messages.filter((m) => m.receiverId === currentUserId)
|
|
return messages.filter((m) => m.senderId === currentUserId)
|
|
}, [messages, tab, currentUserId])
|
|
|
|
return (
|
|
<div className="space-y-6">
|
|
<div className="flex flex-wrap items-center justify-between gap-3">
|
|
<Tabs value={tab} onValueChange={(v) => setTab(v as Tab)}>
|
|
<TabsList>
|
|
<TabsTrigger value="inbox" className="gap-2">
|
|
<Inbox className="h-4 w-4" />
|
|
Inbox
|
|
</TabsTrigger>
|
|
<TabsTrigger value="sent" className="gap-2">
|
|
<Send className="h-4 w-4" />
|
|
Sent
|
|
</TabsTrigger>
|
|
</TabsList>
|
|
</Tabs>
|
|
{canSend ? (
|
|
<Button asChild>
|
|
<Link href="/messages/compose">
|
|
<Plus className="mr-2 h-4 w-4" />
|
|
Compose
|
|
</Link>
|
|
</Button>
|
|
) : null}
|
|
</div>
|
|
|
|
{filtered.length === 0 ? (
|
|
<EmptyState
|
|
title={tab === "inbox" ? "Inbox is empty" : "No sent messages"}
|
|
description={
|
|
tab === "inbox"
|
|
? "You have no incoming messages yet."
|
|
: "You have not sent any messages yet."
|
|
}
|
|
icon={Mail}
|
|
className="h-auto border-none shadow-none"
|
|
/>
|
|
) : (
|
|
<div className="space-y-3">
|
|
{filtered.map((m) => {
|
|
const isReceived = m.receiverId === currentUserId
|
|
const counterpart = isReceived ? m.senderName : m.receiverName
|
|
const unread = isReceived && !m.isRead
|
|
return (
|
|
<Link key={m.id} href={`/messages/${m.id}`} className="block">
|
|
<Card className={cn("transition-colors hover:bg-accent/50", unread && "border-primary/40")}>
|
|
<CardHeader className="flex flex-row items-start justify-between gap-2 space-y-0 pb-3">
|
|
<div className="space-y-1">
|
|
<div className="flex items-center gap-2">
|
|
{unread ? (
|
|
<Mail className="h-4 w-4 text-primary" />
|
|
) : (
|
|
<MailOpen className="text-muted-foreground h-4 w-4" />
|
|
)}
|
|
<span className={cn("text-sm font-medium", unread && "text-primary")}>
|
|
{m.subject ?? "(no subject)"}
|
|
</span>
|
|
{unread ? <Badge variant="default" className="text-xs">New</Badge> : null}
|
|
</div>
|
|
<p className="text-muted-foreground text-xs">
|
|
{isReceived ? "From" : "To"}: {counterpart ?? "Unknown"}
|
|
</p>
|
|
</div>
|
|
<span className="text-muted-foreground shrink-0 text-xs">
|
|
{formatDate(m.createdAt)}
|
|
</span>
|
|
</CardHeader>
|
|
<CardContent className="pt-0">
|
|
<p className="text-muted-foreground line-clamp-2 text-sm whitespace-pre-wrap">
|
|
{m.content}
|
|
</p>
|
|
</CardContent>
|
|
</Card>
|
|
</Link>
|
|
)
|
|
})}
|
|
</div>
|
|
)}
|
|
</div>
|
|
)
|
|
}
|