mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-09-13 04:42:56 +08:00
feat(core): automatically focus on the Readwise token input when the window is focused (#11112)
This commit is contained in:
+17
-1
@@ -4,7 +4,13 @@ import { IntegrationService } from '@affine/core/modules/integration';
|
|||||||
import { Trans, useI18n } from '@affine/i18n';
|
import { Trans, useI18n } from '@affine/i18n';
|
||||||
import { ReadwiseLogoDuotoneIcon } from '@blocksuite/icons/rc';
|
import { ReadwiseLogoDuotoneIcon } from '@blocksuite/icons/rc';
|
||||||
import { useService } from '@toeverything/infra';
|
import { useService } from '@toeverything/infra';
|
||||||
import { type FormEvent, useCallback, useState } from 'react';
|
import {
|
||||||
|
type FormEvent,
|
||||||
|
useCallback,
|
||||||
|
useEffect,
|
||||||
|
useRef,
|
||||||
|
useState,
|
||||||
|
} from 'react';
|
||||||
|
|
||||||
import { IntegrationCardIcon } from '../card';
|
import { IntegrationCardIcon } from '../card';
|
||||||
import {
|
import {
|
||||||
@@ -27,6 +33,7 @@ const ConnectDialog = ({
|
|||||||
onSuccess: (token: string) => void;
|
onSuccess: (token: string) => void;
|
||||||
}) => {
|
}) => {
|
||||||
const t = useI18n();
|
const t = useI18n();
|
||||||
|
const inputRef = useRef<HTMLInputElement>(null);
|
||||||
const [status, setStatus] = useState<'idle' | 'verifying' | 'error'>('idle');
|
const [status, setStatus] = useState<'idle' | 'verifying' | 'error'>('idle');
|
||||||
const [token, setToken] = useState('');
|
const [token, setToken] = useState('');
|
||||||
const readwise = useService(IntegrationService).readwise;
|
const readwise = useService(IntegrationService).readwise;
|
||||||
@@ -82,6 +89,14 @@ const ConnectDialog = ({
|
|||||||
[handleResult, readwise]
|
[handleResult, readwise]
|
||||||
);
|
);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
const onFocus = () => inputRef.current?.focus();
|
||||||
|
window.addEventListener('focus', onFocus);
|
||||||
|
return () => {
|
||||||
|
window.removeEventListener('focus', onFocus);
|
||||||
|
};
|
||||||
|
}, []);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Modal
|
<Modal
|
||||||
open={true}
|
open={true}
|
||||||
@@ -111,6 +126,7 @@ const ConnectDialog = ({
|
|||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
<Input
|
<Input
|
||||||
|
ref={inputRef}
|
||||||
value={token}
|
value={token}
|
||||||
onInput={handleInput}
|
onInput={handleInput}
|
||||||
placeholder={t['com.affine.integration.readwise.connect.placeholder']()}
|
placeholder={t['com.affine.integration.readwise.connect.placeholder']()}
|
||||||
|
|||||||
Reference in New Issue
Block a user