import { KB_HOST } from '@constants'; import { useKnowledgeBaseStore } from '@help-center/state/knowledge-base.js'; import { useRef } from '@wordpress/element'; import { __ } from '@wordpress/i18n'; import { closeSmall, Icon, search as sIcon } from '@wordpress/icons'; import classNames from 'classnames'; export const SearchForm = ({ onChange }) => { const { searchTerm, clearSearchTerm, reset } = useKnowledgeBaseStore(); const warmed = useRef(false); const searchRef = useRef(); return (
e.preventDefault()} className="relative h-10 w-full" > onChange(e.target.value)} onFocus={() => { if (warmed.current) return; warmed.current = true; fetch(`${KB_HOST}/api/posts?boot=true`, { method: 'POST' }); }} placeholder={__('What do you need help with?', 'extendify-local')} className="input border-text-800 h-10 w-full border px-3 text-sm placeholder-gray-600" />
{ reset(); clearSearchTerm(); searchRef.current?.focus(); }} size={24} />
); };