import React, { FC, forwardRef, ForwardRefRenderFunction, useImperativeHandle, useRef, useState, } from 'react'; import { useTranslation } from 'next-i18next'; import { IFocusable } from '~/client/interfaces/focusable'; import { TypeaheadProps } from '~/client/interfaces/react-bootstrap-typeahead'; import { IPageWithSearchMeta } from '~/interfaces/search'; import SearchTypeahead from './SearchTypeahead'; import styles from './SearchForm.module.scss'; type SearchFormHelpProps = { isReachable: boolean, } const SearchFormHelp: FC = React.memo((props: SearchFormHelpProps) => { const { t } = useTranslation(); const { isReachable } = props; if (!isReachable) { return ( <>
Error occured on Search Service
Try to reconnect from management page. ); } return (
search{ t('search_help.title') }
word1 word2

({ t('search_help.and.syntax help') })
{ t('search_help.and.desc', { word1: 'word1', word2: 'word2' }) }
"This is GROWI"

({ t('search_help.phrase.syntax help') })
{ t('search_help.phrase.desc', { phrase: 'This is GROWI' }) }
-keyword
{ t('search_help.exclude.desc', { word: 'keyword' }) }
prefix:/user/
{ t('search_help.prefix.desc', { path: '/user/' }) }
-prefix:/user/
{ t('search_help.exclude_prefix.desc', { path: '/user/' }) }
tag:wiki
{ t('search_help.tag.desc', { tag: 'wiki' }) }
-tag:wiki
{ t('search_help.exclude_tag.desc', { tag: 'wiki' }) }
); }); SearchFormHelp.displayName = 'SearchFormHelp'; type Props = TypeaheadProps & { isSearchServiceReachable: boolean, keywordOnInit?: string, disableIncrementalSearch?: boolean, onChange?: (data: IPageWithSearchMeta[]) => void, onSubmit?: (input: string) => void, }; const SearchForm: ForwardRefRenderFunction = (props: Props, ref) => { const { t } = useTranslation(); const { isSearchServiceReachable, keywordOnInit, disableIncrementalSearch, dropup, onChange, onBlur, onFocus, onSubmit, onInputChange, } = props; const [searchError, setSearchError] = useState(null); const searchTyheaheadRef = useRef(null); // publish focus() useImperativeHandle(ref, () => ({ focus() { const instance = searchTyheaheadRef?.current; if (instance != null) { instance.focus(); } }, })); const placeholder = isSearchServiceReachable ? 'Search ...' : 'Error on Search Service'; const emptyLabel = (searchError != null) ? 'Error on searching.' : t('search.search page bodies'); return ( setSearchError(err)} onBlur={onBlur} onFocus={onFocus} keywordOnInit={keywordOnInit} disableIncrementalSearch={disableIncrementalSearch} helpElement={} /> ); }; export default forwardRef(SearchForm);