diff --git a/src/components/layout/Sidebar.tsx b/src/components/layout/Sidebar.tsx index 7102c87..d76d171 100644 --- a/src/components/layout/Sidebar.tsx +++ b/src/components/layout/Sidebar.tsx @@ -2,14 +2,15 @@ import Link from 'next/link'; import { usePathname, useRouter } from 'next/navigation'; -import { Plus, PanelLeft, Trash2, MoreHorizontal, Loader2, Pencil, Check, X, Bot, Bookmark } from 'lucide-react'; +import { Plus, PanelLeft, Trash2, MoreHorizontal, Loader2, Pencil, Check, X, Bot, Bookmark, Search } from 'lucide-react'; import { UserMenu } from '@/components/ui/UserMenu'; import { NewChatModal } from '@/components/features/NewChatModal'; +import { SearchModal } from '@/components/features/SearchModal'; import { cn } from '@/lib/utils'; import { useConversations } from '@/hooks/useConversations'; import { useAuth } from '@/providers/AuthProvider'; import type { Conversation } from '@/drizzle/schema'; -import { useState, useRef, useEffect } from 'react'; +import { useState, useRef, useEffect, useCallback } from 'react'; interface SidebarProps { isOpen?: boolean; @@ -26,6 +27,7 @@ export function Sidebar({ isOpen = true }: SidebarProps) { const [editingTitle, setEditingTitle] = useState(''); const [isSubmitting, setIsSubmitting] = useState(false); const [showNewChatModal, setShowNewChatModal] = useState(false); + const [showSearchModal, setShowSearchModal] = useState(false); const inputRef = useRef(null); const menuRef = useRef(null); @@ -52,6 +54,22 @@ export function Sidebar({ isOpen = true }: SidebarProps) { }; }, [menuOpen]); + // 全局键盘快捷键:⌘K / Ctrl+K 打开搜索 + useEffect(() => { + const handleKeyDown = (e: KeyboardEvent) => { + // ⌘K (Mac) 或 Ctrl+K (Windows/Linux) + if ((e.metaKey || e.ctrlKey) && e.key === 'k') { + e.preventDefault(); + setShowSearchModal(true); + } + }; + + document.addEventListener('keydown', handleKeyDown); + return () => { + document.removeEventListener('keydown', handleKeyDown); + }; + }, []); + // 创建新对话 - 显示选择助手弹框 const handleNewChat = () => { setShowNewChatModal(true); @@ -142,6 +160,21 @@ export function Sidebar({ isOpen = true }: SidebarProps) { + {/* 搜索入口按钮 */} +
+ +
+ {/* 助手库入口 */}
setShowNewChatModal(false)} /> + + {/* 搜索弹框 */} + setShowSearchModal(false)} + /> ); }