web-apps/apps/common/mobile/lib/view/Search.jsx

170 lines
5.7 KiB
React
Raw Normal View History

2021-01-22 21:20:31 +00:00
import React, { Component } from 'react';
import { Searchbar, Popover, Popup, View, Page, List, ListItem, Navbar, NavRight, Link } from 'framework7-react';
2021-01-27 13:36:16 +00:00
import { Toggle } from 'framework7-react';
2021-01-28 10:27:18 +00:00
import { f7 } from 'framework7-react';
import { Dom7 } from 'framework7';
2021-01-22 21:20:31 +00:00
import { Device } from '../../../../common/mobile/utils/device';
2021-01-28 10:27:18 +00:00
import { observable } from "mobx";
import { observer } from "mobx-react";
const searchOptions = observable({
usereplace: false
});
2021-01-22 21:20:31 +00:00
const popoverStyle = {
height: '300px'
};
class SearchSettingsView extends Component {
constructor(props) {
super(props);
this.state = {
useReplace: false,
caseSensitive: false,
markResults: false
};
}
onFindReplaceClick(action) {
2021-01-28 10:27:18 +00:00
searchOptions.usereplace = action == 'replace';
2021-01-22 21:20:31 +00:00
this.setState({
2021-01-28 10:27:18 +00:00
useReplace: searchOptions.usereplace
2021-01-22 21:20:31 +00:00
});
2021-01-28 10:27:18 +00:00
if (this.onReplaceChecked) {}
2021-01-22 21:20:31 +00:00
}
render() {
const show_popover = true;
const navbar =
<Navbar title="Find and replace">
{!show_popover &&
<NavRight>
<Link popupClose=".search-settings-popup">Done</Link>
</NavRight>}
</Navbar>;
const content =
<View style={popoverStyle}>
<Page>
{navbar}
<List>
2021-01-27 13:36:16 +00:00
<ListItem radio title="Find" name="find-replace-checkbox" checked={!this.state.useReplace} onClick={e => this.onFindReplaceClick('find')} />
<ListItem radio title="Find and replace" name="find-replace-checkbox" checked={this.state.useReplace} onClick={e => this.onFindReplaceClick('replace')} />
</List>
<List>
<ListItem title="Case sensitive">
<Toggle slot="after" />
</ListItem>
<ListItem title="Highlight results">
<Toggle slot="after" />
</ListItem>
2021-01-22 21:20:31 +00:00
</List>
</Page>
</View>;
return (
show_popover ?
<Popover id="idx-search-settings" className="popover__titled">{content}</Popover> :
<Popup id="idx-search-settings">{content}</Popup>
)
}
}
2021-01-28 10:27:18 +00:00
@observer
2021-01-22 21:20:31 +00:00
class SearchView extends Component {
constructor(props) {
super(props);
$$(document).on('page:init', (e, page) => {
if ( page.name == 'home' ) {
2021-01-28 10:27:18 +00:00
this.searchbar = f7.searchbar.create({
2021-01-22 21:20:31 +00:00
el: '.searchbar',
customSearch: true,
expandable: true,
backdrop: false,
on: {
search: (bar, curval, prevval) => {
}
}
});
}
});
this.onSettingsClick = this.onSettingsClick.bind(this);
2021-01-28 10:27:18 +00:00
this.onSearchClick = this.onSearchClick.bind(this);
2021-01-22 21:20:31 +00:00
}
componentDidMount(){
2021-01-28 10:27:18 +00:00
const $$ = Dom7;
this.$repalce = $$('#idx-replace-val');
2021-01-22 21:20:31 +00:00
}
onSettingsClick(e) {
if ( Device.phone ) {
// f7.popup.open('.settings-popup');
2021-01-24 21:30:49 +00:00
} else f7.popover.open('#idx-search-settings', '#idx-btn-search-settings');
2021-01-22 21:20:31 +00:00
}
2021-01-28 10:27:18 +00:00
searchParams() {
let params = {
text: this.searchbar.query,
direction: action
};
}
onSearchClick(action) {
if ( this.searchbar && this.searchbar.query) {
if ( this.props.onSearchQuery ) {
let params = {
text: this.searchbar.query,
direction: action
};
if ( searchOptions.usereplace )
params.replace = this.$replace.val();
this.props.onSearchQuery(params);
}
}
}
2021-01-22 21:20:31 +00:00
render() {
2021-01-28 10:27:18 +00:00
const usereplace = searchOptions.usereplace;
const hidden = {display: "none"};
2021-01-22 21:20:31 +00:00
return (
<form className="searchbar">
<div className="searchbar-bg"></div>
<div className="searchbar-inner">
<div className="buttons-row">
<a id="idx-btn-search-settings" className="link icon-only" onClick={this.onSettingsClick}>
<i className="icon icon-settings" />
</a>
</div>
<div className="searchbar-input-wrap">
<input placeholder="Search" type="search" />
<i className="searchbar-icon" />
<span className="input-clear-button" />
</div>
2021-01-28 10:27:18 +00:00
<div className="searchbar-input-wrap" style={!usereplace ? hidden: null}>
<input placeholder="Replace" type="search" id="idx-replace-val" />
<i className="searchbar-icon" />
<span className="input-clear-button" />
</div>
2021-01-22 21:20:31 +00:00
<div className="buttons-row">
2021-01-28 10:27:18 +00:00
<a className="link icon-only prev disabled1" onClick={e => this.onSearchClick('back')}>
2021-01-22 21:20:31 +00:00
<i className="icon icon-prev" />
</a>
2021-01-28 10:27:18 +00:00
<a className="link icon-only next disabled1" onClick={e => this.onSearchClick('next')}>
2021-01-22 21:20:31 +00:00
<i className="icon icon-next" />
</a>
</div>
<span className="searchbar-disable-button">Cancel</span>
</div>
</form>
)
}
}
export {SearchView as default, SearchSettingsView};