import React, { Dispatch, SetStateAction, useEffect, useRef, useState, } from 'react'; import { SearchIcon } from '@blocksuite/icons'; import { StyledInputContent, StyledLabel } from './style'; import { Command } from 'cmdk'; export const Input = (props: { query: string; setQuery: Dispatch>; setLoading: Dispatch>; }) => { const [isComposition, setIsComposition] = useState(false); const [inputValue, setInputValue] = useState(''); const inputRef = useRef(null); useEffect(() => { return inputRef.current?.focus(); }, [inputRef]); useEffect(() => { return setInputValue(props.query); }, []); return ( { setIsComposition(true); }} onCompositionEnd={e => { props.setQuery(e.data); setIsComposition(false); props.setLoading(true); }} onValueChange={str => { setInputValue(str); if (!isComposition) { props.setQuery(str); props.setLoading(true); } }} onKeyDown={(e: React.KeyboardEvent) => { if (isComposition) { if ( e.key === 'ArrowDown' || e.key === 'ArrowUp' || e.key === 'Enter' ) { e.stopPropagation(); } } }} placeholder="Quick Search..." /> ); };