diff --git a/src/components/editor/ArticleList.tsx b/src/components/ArticleList.tsx similarity index 56% rename from src/components/editor/ArticleList.tsx rename to src/components/ArticleList.tsx index acc4de4..2aa6e1e 100644 --- a/src/components/editor/ArticleList.tsx +++ b/src/components/ArticleList.tsx @@ -23,9 +23,10 @@ import { AlertDialogTrigger, } from "@/components/ui/alert-dialog" import { ScrollArea } from '@/components/ui/scroll-area' -import { FileText, Trash2, Menu, Plus, Save } from 'lucide-react' +import { FileText, Trash2, Menu, Plus, Save, Edit2, Check } from 'lucide-react' import { useToast } from '@/components/ui/use-toast' import { ToastAction } from '@/components/ui/toast' +import { Input } from '@/components/ui/input' interface Article { id: string @@ -46,6 +47,9 @@ export function ArticleList({ onSelect, currentContent, onNew }: ArticleListProp const { toast } = useToast() const [articles, setArticles] = useState([]) const [articleToDelete, setArticleToDelete] = useState
(null) + const [editingId, setEditingId] = useState(null) + const [editingTitle, setEditingTitle] = useState('') + const [isOpen, setIsOpen] = useState(false) // 加载文章列表 useEffect(() => { @@ -119,6 +123,7 @@ export function ArticleList({ onSelect, currentContent, onNew }: ArticleListProp // 如果有外部传入的新建处理函数,优先使用 if (onNew) { onNew() + setIsOpen(false) return } @@ -126,23 +131,92 @@ export function ArticleList({ onSelect, currentContent, onNew }: ArticleListProp const newArticle: Article = { id: Date.now().toString(), title: '新文章', - content: '# 新文章\n\n开始写作...', + content: `# 新文章 + +## 简介 +在这里写文章的简介... + +## 正文 +开始写作你的精彩内容... + +## 总结 +在这里总结文章的主要观点... + +--- +> 作者:[你的名字] +> 日期:${new Date().toLocaleDateString()} +`, template: 'default', createdAt: Date.now(), updatedAt: Date.now() } + // 保存新文章到本地存储 + const updatedArticles = [newArticle, ...articles] + setArticles(updatedArticles) + localStorage.setItem('wechat_articles', JSON.stringify(updatedArticles)) + + // 选中新文章并关闭列表 onSelect(newArticle) + setIsOpen(false) + toast({ title: "新建成功", - description: "已创建新文章", + description: "已创建新文章,开始写作吧!", duration: 2000 }) } + // 开始重命名 + const startRename = (article: Article) => { + setEditingId(article.id) + setEditingTitle(article.title) + } + + // 保存重命名 + const saveRename = (article: Article) => { + if (!editingTitle.trim()) { + toast({ + variant: "destructive", + title: "重命名失败", + description: "文章标题不能为空", + duration: 2000 + }) + return + } + + const updatedArticles = articles.map(a => { + if (a.id === article.id) { + return { + ...a, + title: editingTitle.trim(), + updatedAt: Date.now() + } + } + return a + }) + + setArticles(updatedArticles) + localStorage.setItem('wechat_articles', JSON.stringify(updatedArticles)) + setEditingId(null) + setEditingTitle('') + + toast({ + title: "重命名成功", + description: `文章已重命名为"${editingTitle.trim()}"`, + duration: 2000 + }) + } + + // 取消重命名 + const cancelRename = () => { + setEditingId(null) + setEditingTitle('') + } + return ( <> - + - - + ) : ( + <> + +
+ + +
+ + )} ))} {articles.length === 0 && ( diff --git a/src/components/editor/components/EditorToolbar.tsx b/src/components/editor/components/EditorToolbar.tsx index 6f4c2bf..3866bbb 100644 --- a/src/components/editor/components/EditorToolbar.tsx +++ b/src/components/editor/components/EditorToolbar.tsx @@ -6,7 +6,7 @@ import { cn } from '@/lib/utils' import { WechatStylePicker } from '../../template/WechatStylePicker' import { TemplateManager } from '../../template/TemplateManager' import { StyleConfigDialog } from '../StyleConfigDialog' -import { ArticleList } from '../ArticleList' +import { ArticleList } from '@/components/ArticleList' import { type Article } from '../constants' import { type RendererOptions } from '@/lib/markdown' import { ThemeToggle } from '@/components/theme/ThemeToggle'