diff --git a/src/renderer/src/components/Game/Config/ManageMenu/NameEditorDialog.tsx b/src/renderer/src/components/Game/Config/ManageMenu/NameEditorDialog.tsx index e217947..639e736 100644 --- a/src/renderer/src/components/Game/Config/ManageMenu/NameEditorDialog.tsx +++ b/src/renderer/src/components/Game/Config/ManageMenu/NameEditorDialog.tsx @@ -26,6 +26,9 @@ export function NameEditorDialog({ onChange={(e) => { setGameName(e.target.value) }} + onKeyDown={(e) => { + if (e.key === 'Enter') setIsOpen(false) + }} /> diff --git a/src/renderer/src/components/contextMenu/CollectionCM/main.tsx b/src/renderer/src/components/contextMenu/CollectionCM/main.tsx index 20c54f0..90a38a4 100644 --- a/src/renderer/src/components/contextMenu/CollectionCM/main.tsx +++ b/src/renderer/src/components/contextMenu/CollectionCM/main.tsx @@ -32,7 +32,7 @@ export function CollectionCM({ const { renameCollection, removeCollection, collections } = useCollections() const [newName, setNewName] = useState('') const [isRenaming, setIsRenaming] = useState(false) - const [isDeleting, setisDeleting] = useState(false) + const [isDeleting, setIsDeleting] = useState(false) useEffect(() => { if (collections[collectionId].name !== newName) { @@ -52,7 +52,7 @@ export function CollectionCM({ setIsRenaming(true)}>重命名 - setisDeleting(true)}>删除 + setIsDeleting(true)}>删除 @@ -88,7 +88,7 @@ export function CollectionCM({ { - setisDeleting(false) + setIsDeleting(false) }} > 取消 diff --git a/src/renderer/src/pages/GameAdder/ScreenshotList.tsx b/src/renderer/src/pages/GameAdder/ScreenshotList.tsx index 0a4fe28..4ec9907 100644 --- a/src/renderer/src/pages/GameAdder/ScreenshotList.tsx +++ b/src/renderer/src/pages/GameAdder/ScreenshotList.tsx @@ -47,6 +47,39 @@ export function ScreenshotList(): JSX.Element { ) }, []) + useEffect(() => { + const handleKeyDown = (e: KeyboardEvent): void => { + const index = screenshotList.findIndex((image) => image === screenshotUrl) + if (index === -1) return + + if (e.key === 'Enter') { + addGameToDB() + return + } + + let targetIndex: number | null = null + if (e.key === 'ArrowRight') targetIndex = index + 1 + else if (e.key === 'ArrowDown') targetIndex = index + 2 + else if (e.key === 'ArrowLeft') targetIndex = index - 1 + screenshotList.length + else if (e.key === 'ArrowUp') targetIndex = index - 2 + screenshotList.length + + if (targetIndex !== null) { + const targetGame = screenshotList[targetIndex % screenshotList.length] + setScreenshotUrl(targetGame) + const targetElement = document.querySelector(`[data-image="${targetGame}"]`) + targetElement?.scrollIntoView({ + behavior: 'smooth', + block: 'center', + inline: 'center' + }) + } + } + window.addEventListener('keydown', handleKeyDown) + return (): void => { + window.removeEventListener('keydown', handleKeyDown) + } + }, [screenshotUrl, screenshotList]) + async function addGameToDB(): Promise { if (isAdding) return setIsAdding(true) @@ -84,6 +117,7 @@ export function ScreenshotList(): JSX.Element { screenshotList.map((image) => (
{ setScreenshotUrl(image) }} diff --git a/src/renderer/src/pages/GameAdder/Search.tsx b/src/renderer/src/pages/GameAdder/Search.tsx index a30b9e3..647e757 100644 --- a/src/renderer/src/pages/GameAdder/Search.tsx +++ b/src/renderer/src/pages/GameAdder/Search.tsx @@ -14,10 +14,22 @@ import { toast } from 'sonner' import { useGameAdderStore } from './store' import { ipcInvoke } from '~/utils' import { useNavigate } from 'react-router-dom' +import React from 'react' export function Search({ className }: { className?: string }): JSX.Element { const { dataSource, setDataSource, name, setName, id, setId, setGameList } = useGameAdderStore() const navigate = useNavigate() + + const gameNameInput = React.useRef(null) + const gameIdInput = React.useRef(null) + React.useEffect(() => { + setTimeout(() => { + if (gameNameInput.current) { + gameNameInput.current.focus() + } + }) + }, []) + async function searchGames(): Promise { if (!name) { toast.warning('请输入游戏名称') @@ -111,11 +123,13 @@ export function Search({ className }: { className?: string }): JSX.Element {
游戏名称
setName(e.target.value)} placeholder="请输入游戏名称" onKeyDown={(e) => { if (e.key === 'Enter') searchGames() + if (e.key === 'ArrowUp' || e.key === 'ArrowDown') gameIdInput.current?.focus() }} /> @@ -123,11 +137,13 @@ export function Search({ className }: { className?: string }): JSX.Element {
游戏ID
setId(e.target.value)} placeholder="请输入游戏ID" onKeyDown={(e) => { if (e.key === 'Enter') recognizeGame() + if (e.key === 'ArrowUp' || e.key === 'ArrowDown') gameNameInput.current?.focus() }} /> diff --git a/src/renderer/src/pages/GameAdder/main.tsx b/src/renderer/src/pages/GameAdder/main.tsx index f3b588f..4c3bd62 100644 --- a/src/renderer/src/pages/GameAdder/main.tsx +++ b/src/renderer/src/pages/GameAdder/main.tsx @@ -12,7 +12,7 @@ function GameAdderContent(): JSX.Element { return ( { e.preventDefault() }}