Cleanup - unused files / unused exports / duplicate exports
[ProtonMail-WebClient.git] / applications / drive / src / app / store / _views / useSearchControl.tsx
blob0e29247f90faf80ced62c695e3ff3dfbf530b561
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;
11     /**
12      * prepareSearchData starts initial sync to create db.
13      */
14     const prepareSearchData = async () => {
15         if (!esSupported || isEnablingEncryptedSearch) {
16             return;
17         }
19         if (dbExists) {
20             return cacheIndexedDB();
21         }
23         await enableEncryptedSearch();
24     };
26     const deleteData = () => esDelete();
28     const isDisabled = !esSupported || isEnablingEncryptedSearch;
29     let disabledReason;
30     if (isDisabled) {
31         disabledReason = isEnablingEncryptedSearch
32             ? c('Info').t`Indexing search results…`
33             : c('Info').t`Search cannot be enabled in this browser`;
34     }
36     return {
37         searchEnabled,
38         isEnablingEncryptedSearch,
39         isDisabled,
40         disabledReason,
41         hasData: dbExists,
42         prepareSearchData,
43         deleteData,
44     };