import React, {useEffect} from 'react'; import { List, ListItem, Toggle, Page, Navbar, NavRight, Link } from 'framework7-react'; import { SearchController, SearchView, SearchSettingsView } from '../../../../common/mobile/lib/controller/Search'; import { f7 } from 'framework7-react'; import { withTranslation } from 'react-i18next'; import { Device } from '../../../../common/mobile/utils/device'; import { observer, inject } from "mobx-react"; class SearchSettings extends SearchSettingsView { constructor(props) { super(props); } extraSearchOptions() { const anc_markup = super.extraSearchOptions(); const show_popover = !Device.phone; const { t } = this.props; const _t = t("View.Settings", {returnObjects: true}); const storeAppOptions = this.props.storeAppOptions; const isEdit = storeAppOptions.isEdit; const markup = ( {!show_popover && {_t.textDone} } this.onFindReplaceClick('find')} /> {isEdit ? [ this.onFindReplaceClick('replace')} />, this.onFindReplaceClick('replace-all')}>] : null} ); return {...anc_markup, ...markup}; } } class PESearchView extends SearchView { constructor(props) { super(props); } searchParams() { let params = super.searchParams(); const checkboxCaseSensitive = f7.toggle.get('.toggle-case-sensitive'); const searchOptions = { caseSensitive: checkboxCaseSensitive.checked, }; return {...params, ...searchOptions}; } // onSearchbarShow(isshowed, bar) { // super.onSearchbarShow(isshowed, bar); // } } const Search = withTranslation()(props => { const { t } = props; const _t = t('View.Settings', {returnObjects: true}); useEffect(() => { if (f7.searchbar.get('.searchbar')?.enabled && Device.phone) { const api = Common.EditorApi.get(); $$('.searchbar-input').focus(); api.asc_enableKeyEvents(false); } }); const onSearchQuery = params => { const api = Common.EditorApi.get(); f7.popover.close('.document-menu.modal-in', false); if (params.find && params.find.length) { var options = new AscCommon.CSearchSettings(); options.put_Text(params.find); options.put_MatchCase(params.caseSensitive); api.asc_findText(options, params.forward, function(resultCount) { !resultCount && f7.dialog.alert(null, _t.textNoTextFound); }); } }; const onchangeSearchQuery = params => { const api = Common.EditorApi.get(); if(params.length === 0) api.asc_selectSearchingResults(false); } const onReplaceQuery = params => { const api = Common.EditorApi.get(); if (params.find && params.find.length) { var options = new AscCommon.CSearchSettings(); options.put_Text(params.find); options.put_MatchCase(params.caseSensitive); api.asc_replaceText(options, params.replace || '', false); } } const onReplaceAllQuery = params => { const api = Common.EditorApi.get(); if (params.find && params.find.length) { var options = new AscCommon.CSearchSettings(); options.put_Text(params.find); options.put_MatchCase(params.caseSensitive); api.asc_replaceText(options, params.replace || '', true); } } return }); const SearchSettingsWithTranslation = inject("storeAppOptions")(observer(withTranslation()(SearchSettings))); export {Search, SearchSettingsWithTranslation as SearchSettings}