From 57e8631e100b59d7ccffe71a39051e162323beee Mon Sep 17 00:00:00 2001 From: gaoziman <2942894660@qq.com> Date: Wed, 24 Dec 2025 22:50:45 +0800 Subject: [PATCH] =?UTF-8?q?feat(=E4=BE=A7=E8=BE=B9=E6=A0=8F):=20=E9=9B=86?= =?UTF-8?q?=E6=88=90=E6=B6=88=E6=81=AF=E6=90=9C=E7=B4=A2=E5=85=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 添加搜索入口按钮显示快捷键提示 - 支持全局快捷键 ⌘K / Ctrl+K 打开搜索 - 集成 SearchModal 搜索弹框组件 --- src/components/layout/Sidebar.tsx | 43 +++++++++++++++++++++++++++++-- 1 file changed, 41 insertions(+), 2 deletions(-) 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)} + /> ); }