Skip to content

Commit

Permalink
feat: add key up enter import (#432)
Browse files Browse the repository at this point in the history
thx
  • Loading branch information
Layouwen authored Dec 31, 2024
1 parent 7b28f92 commit 0c345fa
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions src/renderer/src/pages/profiles.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ import ProfileItem from '@renderer/components/profiles/profile-item'
import { useProfileConfig } from '@renderer/hooks/use-profile-config'
import { useAppConfig } from '@renderer/hooks/use-app-config'
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 {
DndContext,
Expand Down Expand Up @@ -52,6 +53,7 @@ const Profiles: React.FC = () => {
const [updating, setUpdating] = useState(false)
const [fileOver, setFileOver] = useState(false)
const [url, setUrl] = useState('')
const isUrlEmpty = url.trim() === ''
const sensors = useSensors(useSensor(PointerSensor))
const { data: subs = [], mutate: mutateSubs } = useSWR(
useSubStore ? 'subStoreSubs' : undefined,
Expand Down Expand Up @@ -142,6 +144,14 @@ const Profiles: React.FC = () => {
}
}

const handleInputKeyUp = useCallback(
(e: KeyboardEvent<HTMLInputElement>) => {
if (e.key !== 'Enter' || isUrlEmpty) return
handleImport()
},
[isUrlEmpty]
)

useEffect(() => {
pageRef.current?.addEventListener('dragover', (e) => {
e.preventDefault()
Expand Down Expand Up @@ -218,6 +228,7 @@ const Profiles: React.FC = () => {
size="sm"
value={url}
onValueChange={setUrl}
onKeyUp={handleInputKeyUp}
endContent={
<>
<Button
Expand Down Expand Up @@ -247,7 +258,7 @@ const Profiles: React.FC = () => {
size="sm"
color="primary"
className="ml-2"
isDisabled={url === ''}
isDisabled={isUrlEmpty}
isLoading={importing}
onPress={handleImport}
>
Expand Down

0 comments on commit 0c345fa

Please sign in to comment.