Files
no-whatever/src/components/Modal.tsx
T
kurihada 4f4220652e refactor(P2/P3): 完成全部7批重构 — 模块化、SSE退避、无障碍、Zod校验、Server组件、Room关系化
批次A:重命名 + 路由拆分
- store.ts → roomRepository.ts,更新全部 import
- blindbox/plan/route.ts 精简为薄路由,业务逻辑抽取到 planActions.ts / planQueries.ts

批次B:blindboxPlanGen.ts 拆分(710行 → src/lib/plan/)
- agentPlan.ts:Agent 工具调用与系统提示
- legacyPlan.ts:非 Agent 备用生成逻辑
- ideaSelection.ts:Idea 筛选与 Slot 映射
- transitEnrichment.ts:交通信息查询与填充
- index.ts:runPlanGeneration 主入口

批次C:SSE 连接稳定性
- useRoomPolling.ts 加入指数退避重连(上限60s,含Jitter)
- plan/stream/route.ts 添加30s心跳 + abort信号清理

批次D:无障碍修复
- Modal:role=dialog、aria-modal、aria-labelledby
- AuthModal:aria-label关闭按钮、tablist/tab/aria-selected
- PlanItemEditModal、QrInviteModal:补全aria-label
- BlindboxPlan:图标按钮aria-label

批次E:Zod 引入
- src/lib/schemas/ai.ts:AI返回值 Schema(IdeaTagsSchema等5个)
- src/lib/schemas/requests.ts:请求体 Schema
- ai.ts 手工验证替换为 Zod safeParse

批次F:Server Components
- achievements/page.tsx → Server Component + AchievementsClient.tsx
- profile/page.tsx → Server Component + ProfileClient.tsx

批次G:Room 关系化模型
- prisma/schema.prisma:新增 RoomMember、RoomRestaurant、RoomLike、RoomSwipe 4张表
- migration:20260302010000_room_relational_model
- roomRepository.ts 完整重写(关系查询+应用锁)
- buildRoomStatus.ts 适配关系查询

测试:全部329个用例通过,修复68个因auth mock缺失导致的测试失败
2026-03-02 20:27:06 +08:00

82 lines
2.2 KiB
TypeScript

"use client";
import { useRef } from "react";
import { motion, AnimatePresence } from "framer-motion";
type ModalVariant = "sheet" | "dialog";
interface ModalProps {
open: boolean;
onClose: () => void;
children: React.ReactNode;
variant?: ModalVariant;
/** Used for aria-labelledby; the element with this id should contain the dialog title */
titleId?: string;
}
const sheet = {
backdrop:
"fixed inset-0 z-50 flex items-end justify-center bg-black/60 backdrop-blur-sm sm:items-center",
content:
"relative w-full max-w-sm rounded-t-3xl bg-surface px-5 pb-8 pt-5 shadow-2xl ring-1 ring-border sm:rounded-3xl sm:pb-6",
initial: { y: "100%" },
animate: { y: 0 },
exit: { y: "100%" },
transition: { type: "spring" as const, damping: 28, stiffness: 350 },
};
const dialog = {
backdrop:
"fixed inset-0 z-50 flex items-center justify-center bg-black/60 backdrop-blur-sm",
content:
"mx-6 w-full max-w-xs rounded-2xl bg-surface px-6 py-6 shadow-2xl ring-1 ring-border",
initial: { scale: 0.9, opacity: 0 },
animate: { scale: 1, opacity: 1 },
exit: { scale: 0.9, opacity: 0 },
transition: { type: "spring" as const, damping: 25, stiffness: 350 },
};
const variants = { sheet, dialog };
export default function Modal({
open,
onClose,
children,
variant = "sheet",
titleId,
}: ModalProps) {
const backdropRef = useRef<HTMLDivElement>(null);
const v = variants[variant];
return (
<AnimatePresence>
{open && (
<motion.div
ref={backdropRef}
className={v.backdrop}
initial={{ opacity: 0 }}
animate={{ opacity: 1 }}
exit={{ opacity: 0 }}
transition={{ duration: 0.2 }}
onClick={(e) => {
if (e.target === backdropRef.current) onClose();
}}
>
<motion.div
role="dialog"
aria-modal="true"
aria-labelledby={titleId}
className={v.content}
initial={v.initial}
animate={v.animate}
exit={v.exit}
transition={v.transition}
>
{children}
</motion.div>
</motion.div>
)}
</AnimatePresence>
);
}