124 lines
4.9 KiB
TypeScript
124 lines
4.9 KiB
TypeScript
import { useState } from "react";
|
|
import { useNavigate } from "react-router-dom";
|
|
import { FileText, Code2, Sparkles, Loader2, PenLine } from "lucide-react";
|
|
|
|
import { Button } from "@/components/ui/button";
|
|
import { createCanvasThread } from "../api/threads";
|
|
|
|
const QUICK_START_ITEMS = [
|
|
{
|
|
type: "text" as const,
|
|
icon: FileText,
|
|
title: "新建文本文档",
|
|
description: "撰写和编辑 Markdown 文档,AI 实时协作修改",
|
|
},
|
|
{
|
|
type: "code" as const,
|
|
icon: Code2,
|
|
title: "新建代码",
|
|
description: "编写和重构多语言代码,AI 辅助生成与优化",
|
|
},
|
|
];
|
|
|
|
export default function CanvasHomePage() {
|
|
const navigate = useNavigate();
|
|
const [loading, setLoading] = useState(false);
|
|
|
|
async function handleQuickStart(type: "text" | "code") {
|
|
if (loading) return;
|
|
setLoading(true);
|
|
try {
|
|
const threadId = await createCanvasThread();
|
|
navigate(`${threadId}?type=${type}`);
|
|
} catch (err) {
|
|
console.error("[canvas] failed to create thread:", err);
|
|
setLoading(false);
|
|
}
|
|
}
|
|
|
|
async function handleBlankCanvas() {
|
|
if (loading) return;
|
|
setLoading(true);
|
|
try {
|
|
const threadId = await createCanvasThread();
|
|
navigate(threadId);
|
|
} catch (err) {
|
|
console.error("[canvas] failed to create thread:", err);
|
|
setLoading(false);
|
|
}
|
|
}
|
|
|
|
return (
|
|
<div className="h-full flex flex-col items-center justify-center bg-background px-6">
|
|
<div className="w-full max-w-xl space-y-10">
|
|
<div className="text-center space-y-3">
|
|
<div className="inline-flex items-center justify-center w-12 h-12 rounded-xl bg-primary/10 mb-2">
|
|
<Sparkles className="w-6 h-6 text-primary" />
|
|
</div>
|
|
<h1 className="text-3xl font-bold tracking-tight">Canvas 模式</h1>
|
|
<p className="text-muted-foreground text-base leading-relaxed">
|
|
在左侧聊天区与 AI 协作,右侧实时生成和编辑文档或代码
|
|
</p>
|
|
</div>
|
|
|
|
<div className="grid grid-cols-2 gap-4">
|
|
{QUICK_START_ITEMS.map(({ type, icon: Icon, title, description }) => (
|
|
<button
|
|
key={type}
|
|
onClick={() => void handleQuickStart(type)}
|
|
disabled={loading}
|
|
className="group flex flex-col gap-3 rounded-xl border bg-card p-5 text-left transition-all hover:border-primary/50 hover:shadow-md hover:bg-accent/30 focus:outline-none focus-visible:ring-2 focus-visible:ring-ring disabled:opacity-50 disabled:cursor-not-allowed"
|
|
>
|
|
<div className="flex items-center justify-center w-9 h-9 rounded-lg bg-muted group-hover:bg-primary/10 transition-colors">
|
|
{loading ? (
|
|
<Loader2 className="w-4 h-4 animate-spin text-muted-foreground" />
|
|
) : (
|
|
<Icon className="w-4 h-4 text-muted-foreground group-hover:text-primary transition-colors" />
|
|
)}
|
|
</div>
|
|
<div className="space-y-1">
|
|
<p className="font-medium text-sm">{title}</p>
|
|
<p className="text-xs text-muted-foreground leading-relaxed">
|
|
{description}
|
|
</p>
|
|
</div>
|
|
</button>
|
|
))}
|
|
</div>
|
|
|
|
{/* AI 智能写作入口 */}
|
|
<button
|
|
onClick={() => navigate('ai-writing')}
|
|
className="group w-full flex items-center gap-4 rounded-xl border border-orange-200 dark:border-orange-900/50 bg-orange-50/50 dark:bg-orange-950/20 p-5 text-left transition-all hover:border-orange-400/60 hover:shadow-md hover:bg-orange-50 dark:hover:bg-orange-950/30 focus:outline-none focus-visible:ring-2 focus-visible:ring-orange-400"
|
|
>
|
|
<div className="flex items-center justify-center w-10 h-10 rounded-xl bg-orange-100 dark:bg-orange-900/40 shrink-0 group-hover:bg-orange-200/80 dark:group-hover:bg-orange-800/40 transition-colors">
|
|
<PenLine className="w-5 h-5 text-orange-500 dark:text-orange-400" />
|
|
</div>
|
|
<div className="min-w-0 flex-1">
|
|
<p className="font-semibold text-sm text-orange-700 dark:text-orange-300">AI 智能写作</p>
|
|
<p className="text-xs text-orange-600/70 dark:text-orange-400/60 leading-relaxed mt-0.5">
|
|
多智能体协作——搜集素材、规划大纲、起草正文、编辑审核,全流程自动完成
|
|
</p>
|
|
</div>
|
|
<span className="text-orange-400/60 shrink-0 text-xs">→</span>
|
|
</button>
|
|
|
|
<div className="text-center">
|
|
<Button
|
|
variant="ghost"
|
|
size="sm"
|
|
className="text-muted-foreground text-xs"
|
|
onClick={() => void handleBlankCanvas()}
|
|
disabled={loading}
|
|
>
|
|
{loading ? (
|
|
<Loader2 className="w-3 h-3 animate-spin mr-1" />
|
|
) : null}
|
|
或直接开始空白 Canvas
|
|
</Button>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
);
|
|
}
|