feat: add key up enter import (#432)

thx
This commit is contained in:
Avan 2025-01-01 00:13:37 +08:00 committed by xishang0128
parent 00d8ad9a9c
commit 29906b0f8a

View File

@ -14,7 +14,8 @@ import ProfileItem from '@renderer/components/profiles/profile-item'
import { useProfileConfig } from '@renderer/hooks/use-profile-config' import { useProfileConfig } from '@renderer/hooks/use-profile-config'
import { useAppConfig } from '@renderer/hooks/use-app-config' import { useAppConfig } from '@renderer/hooks/use-app-config'
import { getFilePath, readTextFile, subStoreCollections, subStoreSubs } from '@renderer/utils/ipc' import { getFilePath, readTextFile, subStoreCollections, subStoreSubs } from '@renderer/utils/ipc'
import { ReactNode, useEffect, useMemo, useRef, useState } from 'react' import type { KeyboardEvent } from 'react'
import { ReactNode, useCallback, useEffect, useMemo, useRef, useState } from 'react'
import { MdContentPaste } from 'react-icons/md' import { MdContentPaste } from 'react-icons/md'
import { import {
DndContext, DndContext,
@ -52,6 +53,7 @@ const Profiles: React.FC = () => {
const [updating, setUpdating] = useState(false) const [updating, setUpdating] = useState(false)
const [fileOver, setFileOver] = useState(false) const [fileOver, setFileOver] = useState(false)
const [url, setUrl] = useState('') const [url, setUrl] = useState('')
const isUrlEmpty = url.trim() === ''
const sensors = useSensors(useSensor(PointerSensor)) const sensors = useSensors(useSensor(PointerSensor))
const { data: subs = [], mutate: mutateSubs } = useSWR( const { data: subs = [], mutate: mutateSubs } = useSWR(
useSubStore ? 'subStoreSubs' : undefined, useSubStore ? 'subStoreSubs' : undefined,
@ -142,6 +144,14 @@ const Profiles: React.FC = () => {
} }
} }
const handleInputKeyUp = useCallback(
(e: KeyboardEvent<HTMLInputElement>) => {
if (e.key !== 'Enter' || isUrlEmpty) return
handleImport()
},
[isUrlEmpty]
)
useEffect(() => { useEffect(() => {
pageRef.current?.addEventListener('dragover', (e) => { pageRef.current?.addEventListener('dragover', (e) => {
e.preventDefault() e.preventDefault()
@ -218,6 +228,7 @@ const Profiles: React.FC = () => {
size="sm" size="sm"
value={url} value={url}
onValueChange={setUrl} onValueChange={setUrl}
onKeyUp={handleInputKeyUp}
endContent={ endContent={
<> <>
<Button <Button
@ -247,7 +258,7 @@ const Profiles: React.FC = () => {
size="sm" size="sm"
color="primary" color="primary"
className="ml-2" className="ml-2"
isDisabled={url === ''} isDisabled={isUrlEmpty}
isLoading={importing} isLoading={importing}
onPress={handleImport} onPress={handleImport}
> >