@@ -32,6 +32,7 @@ import { useConnectStore } from "@/stores/connectStore";
3232import platformAdapter from "@/utils/platformAdapter" ;
3333import VisibleKey from "../Common/VisibleKey" ;
3434import { useShortcutsStore } from "@/stores/shortcutsStore" ;
35+ import { useKeyPress } from "ahooks" ;
3536
3637interface ChatHeaderProps {
3738 onCreateNewChat : ( ) => void ;
@@ -85,7 +86,8 @@ export function ChatHeader({
8586
8687 const fetchServers = useCallback (
8788 async ( resetSelection : boolean ) => {
88- platformAdapter . commands ( "list_coco_servers" )
89+ platformAdapter
90+ . commands ( "list_coco_servers" )
8991 . then ( ( res : any ) => {
9092 const enabledServers = ( res as IServer [ ] ) . filter (
9193 ( server ) => server . enabled !== false
@@ -164,6 +166,33 @@ export function ChatHeader({
164166 platformAdapter . emitEvent ( "open_settings" , "connect" ) ;
165167 } ;
166168
169+ useKeyPress ( [ "uparrow" , "downarrow" ] , ( _ , key ) => {
170+ const isOpen = serverListButtonRef . current ?. dataset [ "open" ] != null ;
171+ const length = serverList . length ;
172+
173+ if ( ! isOpen || length <= 1 ) return ;
174+
175+ const currentIndex = serverList . findIndex ( ( server ) => {
176+ return server . id === currentService ?. id ;
177+ } ) ;
178+
179+ let nextIndex = currentIndex ;
180+
181+ if ( key === "uparrow" ) {
182+ nextIndex = currentIndex > 0 ? currentIndex - 1 : length - 1 ;
183+ } else if ( key === "downarrow" ) {
184+ nextIndex = currentIndex < serverList . length - 1 ? currentIndex + 1 : 0 ;
185+ }
186+
187+ switchServer ( serverList [ nextIndex ] ) ;
188+ } ) ;
189+
190+ const handleRefresh = async ( ) => {
191+ setIsRefreshing ( true ) ;
192+ await fetchServers ( false ) ;
193+ setTimeout ( ( ) => setIsRefreshing ( false ) , 1000 ) ;
194+ } ;
195+
167196 return (
168197 < header
169198 className = "flex items-center justify-between py-2 px-3"
@@ -280,22 +309,22 @@ export function ChatHeader({
280309 onClick = { openSettings }
281310 className = "p-1 rounded-md hover:bg-gray-100 dark:hover:bg-gray-800 text-gray-500 dark:text-gray-400"
282311 >
283- < Settings className = "h-4 w-4 text-[#0287FF]" />
312+ < VisibleKey shortcut = "," >
313+ < Settings className = "h-4 w-4 text-[#0287FF]" />
314+ </ VisibleKey >
284315 </ button >
285316 < button
286- onClick = { async ( ) => {
287- setIsRefreshing ( true ) ;
288- await fetchServers ( false ) ;
289- setTimeout ( ( ) => setIsRefreshing ( false ) , 1000 ) ;
290- } }
317+ onClick = { handleRefresh }
291318 className = "p-1 rounded-md hover:bg-gray-100 dark:hover:bg-gray-800 text-gray-500 dark:text-gray-400"
292319 disabled = { isRefreshing }
293320 >
294- < RefreshCw
295- className = { `h-4 w-4 text-[#0287FF] transition-transform duration-1000 ${
296- isRefreshing ? "animate-spin" : ""
297- } `}
298- />
321+ < VisibleKey shortcut = "R" onKeypress = { handleRefresh } >
322+ < RefreshCw
323+ className = { `h-4 w-4 text-[#0287FF] transition-transform duration-1000 ${
324+ isRefreshing ? "animate-spin" : ""
325+ } `}
326+ />
327+ </ VisibleKey >
299328 </ button >
300329 </ div >
301330 </ div >
0 commit comments