笔记本页面

This commit is contained in:
董宏凯 committed 2026-05-21 19:40:54 +08:00
1 parent d639b24c2d
commit 125e8b271b
10 files changed
+689 -11

No files matched your search

+44 -7
View File
@@ -1,17 +1,43 @@
"use client";
import { useMemo, useState } from "react";
import { ArrowRight, NotebookPen, Sparkles } from "lucide-react";
import { ArrowRight, Loader2, NotebookPen, Sparkles } from "lucide-react";
import { toast } from "sonner";
import { useTheme } from "@/contexts/ThemeContext";
import { createSearchSpace } from "@/core/note/api";
import { useNoteAuth } from "@/hooks/useNoteAuth";
import { cn } from "@/lib/utils";
export default function LightAppNewNotePage() {
const { theme } = useTheme();
const isDark = theme === "dark";
const { loading: authLoading, error: authError } = useNoteAuth();
const [titleInput, setTitleInput] = useState("");
const [creating, setCreating] = useState(false);
const hasTitle = useMemo(() => titleInput.trim().length > 0, [titleInput]);
const isBusy = authLoading || creating;
const handleCreate = async () => {
const name = titleInput.trim();
if (!name || isBusy || authError) {
return;
}
setCreating(true);
try {
const searchSpace = await createSearchSpace({ name });
toast.success(`笔记「${searchSpace.name}」创建成功`);
setTitleInput("");
} catch (error) {
const message =
error instanceof Error ? error.message : "创建笔记失败,请稍后重试";
toast.error(message);
} finally {
setCreating(false);
}
};
return (
<div
@@ -21,7 +47,6 @@ export default function LightAppNewNotePage() {
)}
>
<div className="w-full max-w-[720px] -translate-y-12 space-y-8">
{/* 固定标题:新建笔记 */}
<div className="flex items-center gap-3">
<NotebookPen
className={cn("h-5 w-5 shrink-0", isDark ? "text-slate-400" : "text-black/70")}
@@ -36,12 +61,18 @@ export default function LightAppNewNotePage() {
</h1>
</div>
{/* 标题输入框 */}
<div className="flex items-center gap-3">
<input
value={titleInput}
onChange={(e) => setTitleInput(e.target.value)}
onKeyDown={(e) => {
if (e.key === "Enter") {
e.preventDefault();
void handleCreate();
}
}}
placeholder="新建笔记"
disabled={isBusy}
className={cn(
"min-w-0 flex-1 bg-transparent text-[42px] leading-tight font-normal tracking-tight outline-none",
hasTitle
@@ -56,20 +87,25 @@ export default function LightAppNewNotePage() {
{hasTitle && (
<button
type="button"
onClick={() => void handleCreate()}
disabled={isBusy || !!authError}
className={cn(
"inline-flex h-9 w-9 shrink-0 items-center justify-center rounded-full transition-colors",
"inline-flex h-9 w-9 shrink-0 items-center justify-center rounded-full transition-colors disabled:cursor-not-allowed disabled:opacity-70",
isDark
? "bg-blue-500 text-white hover:bg-blue-400"
: "bg-sky-200 text-slate-700 hover:bg-sky-300",
)}
aria-label="进入笔记"
aria-label="创建笔记"
>
<ArrowRight className="h-4 w-4" />
{creating || authLoading ? (
<Loader2 className="h-4 w-4 animate-spin" />
) : (
<ArrowRight className="h-4 w-4" />
)}
</button>
)}
</div>
{/* 说明文字 */}
<div
className={cn(
"flex h-11 items-center gap-2.5 rounded-xl px-4",
@@ -88,6 +124,7 @@ export default function LightAppNewNotePage() {
)}
>
新建笔记开始使用
{authError ? `(${authError})` : ""}
</p>
</div>
</div>