首次发布git
This commit is contained in:
@@ -0,0 +1,306 @@
|
||||
"use client";
|
||||
|
||||
import { SidebarContent, ResizableSidebar } from "@/components/sidebar";
|
||||
import { Editor } from "@/components/editor";
|
||||
import { useEditorStore } from "@/lib/store";
|
||||
import { FileDown, Hash, X, Plus, ChevronLeft, ChevronRight, Sparkles, Lock, Unlock } from "lucide-react";
|
||||
import { useSettingsStore } from "@/lib/settings-store";
|
||||
import { exportPageAsMarkdown } from "@/lib/export";
|
||||
import { useState } from "react";
|
||||
import { cn, getTagColor } from "@/lib/utils";
|
||||
import { useSearchStore } from "@/lib/search-store";
|
||||
import { type Editor as TiptapEditor } from "@tiptap/react";
|
||||
|
||||
import { ImportProvider } from "@/components/import-context";
|
||||
import { AIChatPanel } from "@/components/chat/ai-chat-panel";
|
||||
|
||||
export default function Home() {
|
||||
const { activePageId, pages, updatePage } = useEditorStore();
|
||||
const { openSearchWithTag } = useSearchStore();
|
||||
const activePage = pages.find(p => p.id === activePageId);
|
||||
const [isChatOpen, setIsChatOpen] = useState(false);
|
||||
const [editor, setEditor] = useState<TiptapEditor | null>(null);
|
||||
const [isAddingTag, setIsAddingTag] = useState(false);
|
||||
const [tagInput, setTagInput] = useState("");
|
||||
|
||||
return (
|
||||
<ImportProvider>
|
||||
<div className="flex h-[100dvh] w-full bg-background overflow-hidden relative">
|
||||
{/* Mobile: Sidebar List View (Only visible when no page is active) */}
|
||||
<div className={cn(
|
||||
activePageId ? "hidden" : "flex-1 h-full md:hidden block"
|
||||
)}>
|
||||
<SidebarContent />
|
||||
</div>
|
||||
|
||||
{/* Desktop: Sidebar (Resizable) */}
|
||||
<ResizableSidebar />
|
||||
|
||||
{/* Main Content Area */}
|
||||
<main className={cn(
|
||||
"flex-1 h-full overflow-hidden flex flex-col relative z-0",
|
||||
// Mobile: Hidden when no page active (showing list instead)
|
||||
!activePageId && "hidden md:flex"
|
||||
)}>
|
||||
{activePage ? (
|
||||
<div className="flex-1 overflow-y-auto scroll-smooth">
|
||||
<div className="max-w-7xl mx-auto px-4 md:px-16 py-6 min-h-screen content-start">
|
||||
|
||||
{/* Mobile Back Button */}
|
||||
<div className="md:hidden mb-4 flex items-center text-muted-foreground" onClick={() => updatePage(null as any, {} as any)}>
|
||||
{/* Note: updatePage isn't the right way to clear selection. We need setPageId(null).
|
||||
But store only exposes updatePage. Let's fix store usage or use a store action if available.
|
||||
Actually, looking at store.ts, we need `setActivePageId`.
|
||||
*/}
|
||||
</div>
|
||||
|
||||
<div className="group mb-8 relative">
|
||||
{/* Mobile Back Button Integration in Header */}
|
||||
<div className="md:hidden absolute -top-12 left-0 flex items-center gap-1 py-2 text-muted-foreground hover:text-foreground cursor-pointer"
|
||||
onClick={() => useEditorStore.getState().setActivePageId(null)}>
|
||||
<ChevronLeft size={20} />
|
||||
<span>返回列表</span>
|
||||
</div>
|
||||
|
||||
{/* Breadcrumb Navigation */}
|
||||
<div className="flex items-center flex-wrap gap-1 text-sm text-muted-foreground mb-4">
|
||||
{(() => {
|
||||
const breadcrumbs = [];
|
||||
let current: typeof activePage | undefined = activePage;
|
||||
while (current) {
|
||||
breadcrumbs.unshift(current);
|
||||
if (current.parentId) {
|
||||
current = pages.find(p => p.id === current?.parentId);
|
||||
} else {
|
||||
current = undefined;
|
||||
}
|
||||
}
|
||||
return breadcrumbs.map((crumb, index) => (
|
||||
<div key={crumb.id} className="flex items-center gap-1">
|
||||
{index > 0 && <ChevronRight size={14} className="opacity-50" />}
|
||||
<button
|
||||
onClick={() => useEditorStore.getState().setActivePageId(crumb.id)}
|
||||
className={cn(
|
||||
"hover:underline hover:text-foreground transition-colors flex items-center gap-1",
|
||||
crumb.id === activePage.id && "font-medium text-foreground pointer-events-none"
|
||||
)}
|
||||
>
|
||||
{crumb.icon && <span>{crumb.icon}</span>}
|
||||
<span>{crumb.title || "无标题"}</span>
|
||||
</button>
|
||||
</div>
|
||||
));
|
||||
})()}
|
||||
</div>
|
||||
|
||||
<div className="flex items-center gap-2">
|
||||
{activePage.icon && (
|
||||
<span className="text-3xl select-none animate-in fade-in zoom-in-75 duration-300">
|
||||
{activePage.icon}
|
||||
</span>
|
||||
)}
|
||||
<input
|
||||
value={activePage.title}
|
||||
onChange={(e) => updatePage(activePage.id, { title: e.target.value })}
|
||||
placeholder="无标题"
|
||||
disabled={activePage.isLocked}
|
||||
className={cn(
|
||||
"w-full text-3xl font-bold bg-transparent border-none outline-none placeholder:text-muted-foreground/20 text-foreground transition-colors",
|
||||
activePage.isLocked && "opacity-80 cursor-not-allowed select-none"
|
||||
)}
|
||||
/>
|
||||
</div>
|
||||
|
||||
{/* Last Updated Info moved */}
|
||||
|
||||
<div className="absolute right-0 top-1/2 -translate-y-1/2 flex items-center gap-1 transition-opacity">
|
||||
{/* Buttons moved to Editors Toolbar */}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* Tags Section */}
|
||||
<div className="flex flex-wrap items-center gap-2 mb-6 animate-in fade-in slide-in-from-top-2 duration-300">
|
||||
{activePage.tags?.map((tag) => {
|
||||
const colors = getTagColor(tag);
|
||||
return (
|
||||
<span
|
||||
key={tag}
|
||||
onClick={() => openSearchWithTag(tag)}
|
||||
className={cn(
|
||||
"inline-flex items-center gap-1 px-2.5 py-1 rounded-[3px] text-[11px] font-medium transition-colors border shadow-sm",
|
||||
colors.bg, colors.text, colors.border
|
||||
)}>
|
||||
<Hash size={10} className="opacity-70" />
|
||||
{tag}
|
||||
<button
|
||||
onClick={(e) => {
|
||||
e.stopPropagation();
|
||||
const newTags = activePage.tags?.filter(t => t !== tag) || [];
|
||||
updatePage(activePage.id, { tags: newTags });
|
||||
}}
|
||||
className="ml-1 rounded-full p-0.5 hover:bg-black/10 dark:hover:bg-white/10 opacity-0 group-hover:opacity-100 transition-all"
|
||||
>
|
||||
<X size={10} />
|
||||
</button>
|
||||
</span>
|
||||
);
|
||||
})}
|
||||
<div className="relative">
|
||||
{isAddingTag ? (
|
||||
<input
|
||||
autoFocus
|
||||
type="text"
|
||||
value={tagInput}
|
||||
onChange={(e) => setTagInput(e.target.value)}
|
||||
onBlur={() => {
|
||||
if (tagInput.trim()) {
|
||||
const newTags = [...(activePage.tags || []), tagInput.trim()];
|
||||
updatePage(activePage.id, { tags: Array.from(new Set(newTags)) });
|
||||
}
|
||||
setTagInput("");
|
||||
setIsAddingTag(false);
|
||||
}}
|
||||
onKeyDown={(e) => {
|
||||
if (e.key === 'Enter') {
|
||||
e.preventDefault();
|
||||
if (tagInput.trim()) {
|
||||
const newTags = [...(activePage.tags || []), tagInput.trim()];
|
||||
updatePage(activePage.id, { tags: Array.from(new Set(newTags)) });
|
||||
}
|
||||
setTagInput("");
|
||||
setIsAddingTag(false);
|
||||
}
|
||||
if (e.key === 'Escape') {
|
||||
setTagInput("");
|
||||
setIsAddingTag(false);
|
||||
}
|
||||
}}
|
||||
className="w-24 px-2 py-0.5 text-xs bg-transparent border border-primary rounded-sm outline-none animate-in fade-in zoom-in-95 duration-200"
|
||||
placeholder="输入标签..."
|
||||
/>
|
||||
) : (
|
||||
<div className="flex items-center gap-2">
|
||||
<button
|
||||
onClick={() => setIsAddingTag(true)}
|
||||
className="inline-flex items-center gap-1 px-2 py-0.5 rounded-sm text-xs font-medium text-muted-foreground hover:bg-muted hover:text-foreground transition-all border border-transparent hover:border-border"
|
||||
>
|
||||
<Plus size={12} />
|
||||
添加标签
|
||||
</button>
|
||||
|
||||
{/* Icon Picker */}
|
||||
<div className="relative group/icon-picker">
|
||||
<button
|
||||
className="inline-flex items-center gap-1 px-2 py-0.5 rounded-sm text-xs font-medium text-muted-foreground hover:bg-muted hover:text-foreground transition-all border border-transparent hover:border-border"
|
||||
>
|
||||
<Sparkles size={12} />
|
||||
{activePage.icon ? '更改图标' : '添加图标'}
|
||||
</button>
|
||||
<div className="absolute left-0 top-full mt-1 z-50 hidden group-hover/icon-picker:block w-80 p-2 bg-popover border shadow-md rounded-md animate-in fade-in zoom-in-95">
|
||||
<div className="grid grid-cols-8 gap-1 h-64 overflow-y-auto p-1">
|
||||
{[
|
||||
"📄", "📝", "📁", "📂", "📊", "📈", "📉", "📅", "✅", "❌", "📌", "📍", "📎", "🗑️", "⚙️", "🔒",
|
||||
"✨", "💡", "🔥", "🚀", "🎨", "🎯", "🏆", "💎", "❤️", "👍", "👋", "🎉", "🌟", "⭐", "🌈", "⚡",
|
||||
"🤖", "🧠", "💻", "⌨️", "📱", "⌚", "📷", "🎥", "🎧", "🎮", "🕹️", "🎲", "🧩", "🎳", "🥋", "🥊",
|
||||
"🚗", "✈️", "🛸", "🌍", "🪐", "☀️", "🌙", "☁️", "🌧️", "❄️", "🌊", "💧", "🌀",
|
||||
"🏠", "🏢", "🏥", "🏫", "🏰", "🏯", "⛺", "🏕️", "🌲", "🌳", "🌴", "🌵", "🌷", "🌸", "🌹", "🌻",
|
||||
"🐶", "🐱", "🐭", "🐹", "🐰", "🦊", "🐻", "🐼", "🐨", "🐯", "🦁", "🐮", "🐷", "🐸", "🐵", "🐔",
|
||||
"🍎", "🍌", "🍇", "🍉", "🍊", "🍋", "🍍", "🥭", "🍓", "🍒", "🍑", "🥝", "🍅", "🥑", "🍆", "🥔",
|
||||
"🍔", "🍟", "🍕", "🌭", "🥪", "🌮", "🌯", "🥗", "🥘", "🍝", "🍜", "🍲", "🍛", "🍣", "🍱", "🥟",
|
||||
"🍺", "🍻", "🥂", "🍷", "🥃", "🍸", "🍹", "🍾", "☕", "🍵", "🥤", "🧃", "🧊", "🥄", "🍴", "🍽️"
|
||||
].map(icon => (
|
||||
<button
|
||||
key={icon}
|
||||
onClick={(e) => {
|
||||
e.stopPropagation();
|
||||
updatePage(activePage.id, { icon });
|
||||
}}
|
||||
className={cn(
|
||||
"w-8 h-8 flex items-center justify-center rounded-sm hover:bg-accent text-lg transition-colors",
|
||||
activePage.icon === icon && "bg-accent/50 ring-1 ring-primary/20"
|
||||
)}
|
||||
>
|
||||
{icon}
|
||||
</button>
|
||||
))}
|
||||
<button
|
||||
onClick={(e) => {
|
||||
e.stopPropagation();
|
||||
updatePage(activePage.id, { icon: null });
|
||||
}}
|
||||
className="w-8 h-8 flex items-center justify-center rounded-sm hover:bg-red-50 text-red-500 hover:text-red-600 transition-colors col-span-1"
|
||||
title="清除图标"
|
||||
>
|
||||
<X size={14} />
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* Lock Button */}
|
||||
<button
|
||||
onClick={() => updatePage(activePage.id, { isLocked: !activePage.isLocked })}
|
||||
className={cn(
|
||||
"inline-flex items-center gap-1 px-2 py-0.5 rounded-sm text-xs font-medium transition-all border border-transparent hover:border-border",
|
||||
activePage.isLocked
|
||||
? "text-orange-600 bg-orange-50 hover:bg-orange-100 border-orange-200"
|
||||
: "text-muted-foreground hover:bg-muted hover:text-foreground"
|
||||
)}
|
||||
title={activePage.isLocked ? "解锁编辑" : "锁定编辑 (防止误触)"}
|
||||
>
|
||||
{activePage.isLocked ? <Lock size={12} /> : <Unlock size={12} />}
|
||||
{activePage.isLocked ? "已锁定" : "锁定"}
|
||||
</button>
|
||||
|
||||
{/* Last Updated Info */}
|
||||
{activePage.updatedAt && (
|
||||
<div className="text-xs text-muted-foreground/40 select-none flex items-center gap-1 border-l pl-2 ml-1 h-4">
|
||||
<span>
|
||||
{new Date(activePage.updatedAt).toLocaleString('zh-CN', {
|
||||
timeZone: useSettingsStore.getState().timezone || 'Asia/Shanghai',
|
||||
hour12: false
|
||||
})}
|
||||
</span>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* Editor Area or Folder Placeholder */}
|
||||
{activePage.type === 'folder' ? (
|
||||
<div className="flex flex-col items-center justify-center h-[50vh] text-muted-foreground animate-in fade-in duration-500">
|
||||
{/* ... folder icon ... */}
|
||||
</div>
|
||||
) : (
|
||||
<div className="min-h-[60vh] pb-24">
|
||||
<Editor
|
||||
content={activePage.content}
|
||||
onChange={(content) => updatePage(activePage.id, { content })}
|
||||
onEditorReady={setEditor}
|
||||
onToggleAI={() => setIsChatOpen(!isChatOpen)}
|
||||
onExport={() => exportPageAsMarkdown(activePage)}
|
||||
editable={!activePage.isLocked}
|
||||
/>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
) : (
|
||||
<div className="h-full flex flex-col items-center justify-center text-muted-foreground gap-4 animate-in fade-in zoom-in-95 duration-500">
|
||||
<div className="w-16 h-16 bg-muted/50 rounded-2xl flex items-center justify-center">
|
||||
<span className="text-4xl">👋</span>
|
||||
</div>
|
||||
<div className="text-center space-y-1">
|
||||
<h3 className="text-lg font-semibold text-foreground">欢迎使用 NoteAI</h3>
|
||||
<p className="text-sm text-muted-foreground/80">在左侧选择一个页面,或创建一个新页面开始写作。</p>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
</main>
|
||||
<AIChatPanel editor={editor} isOpen={isChatOpen} onClose={() => setIsChatOpen(false)} />
|
||||
</div>
|
||||
</ImportProvider>
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user