1 import { c } from 'ttag';
3 import isSearchFeatureEnabled from '../../utils/isSearchFeatureEnabled';
4 import { useSearchLibrary } from '../_search';
6 export default function useSearchControl() {
7 const searchEnabled = isSearchFeatureEnabled();
8 const { cacheIndexedDB, esStatus, enableEncryptedSearch, esDelete } = useSearchLibrary();
9 const { dbExists, isEnablingEncryptedSearch, esSupported } = esStatus;
12 * prepareSearchData starts initial sync to create db.
14 const prepareSearchData = async () => {
15 if (!esSupported || isEnablingEncryptedSearch) {
20 return cacheIndexedDB();
23 await enableEncryptedSearch();
26 const deleteData = () => esDelete();
28 const isDisabled = !esSupported || isEnablingEncryptedSearch;
31 disabledReason = isEnablingEncryptedSearch
32 ? c('Info').t`Indexing search results…`
33 : c('Info').t`Search cannot be enabled in this browser`;
38 isEnablingEncryptedSearch,