summaryrefslogtreecommitdiffstats
path: root/packages/gitbook-plugin-search/src/components/Input.js
diff options
context:
space:
mode:
authorSamy Pesse <samypesse@gmail.com>2016-09-29 17:20:29 +0200
committerSamy Pesse <samypesse@gmail.com>2016-09-29 17:20:29 +0200
commit6015defe11bbdd3bc008cf194e7e88181fe165d0 (patch)
tree2dbb26295ada4de37a6a3778d99287ff8ad14e2e /packages/gitbook-plugin-search/src/components/Input.js
parent7f283791544195fa70c51003db9be3f029c014ef (diff)
downloadgitbook-6015defe11bbdd3bc008cf194e7e88181fe165d0.zip
gitbook-6015defe11bbdd3bc008cf194e7e88181fe165d0.tar.gz
gitbook-6015defe11bbdd3bc008cf194e7e88181fe165d0.tar.bz2
Integrate search in default theme
Diffstat (limited to 'packages/gitbook-plugin-search/src/components/Input.js')
-rw-r--r--packages/gitbook-plugin-search/src/components/Input.js36
1 files changed, 12 insertions, 24 deletions
diff --git a/packages/gitbook-plugin-search/src/components/Input.js b/packages/gitbook-plugin-search/src/components/Input.js
index c4d1288..71f8813 100644
--- a/packages/gitbook-plugin-search/src/components/Input.js
+++ b/packages/gitbook-plugin-search/src/components/Input.js
@@ -3,45 +3,33 @@ const { React } = GitBook;
const search = require('../actions/search');
-const DEBOUNCE_MS = 600;
-
const SearchInput = React.createClass({
propTypes: {
+ query: React.PropTypes.string,
dispatch: React.PropTypes.func
},
- onUpdateQuery(q) {
+ onChange(event) {
const { dispatch } = this.props;
-
- dispatch(search.query(q));
- },
-
- onKeyDown(event) {
const { value } = event.currentTarget;
- if (this.debouncedSearch) {
- clearTimeout(this.debouncedSearch);
- }
-
- this.debouncedSearch = setTimeout(() => {
- this.debouncedSearch = null;
- this.onUpdateQuery(value);
- }, DEBOUNCE_MS);
- },
-
- componentWillUnmount() {
- if (this.debouncedSearch) {
- clearTimeout(this.debouncedSearch);
- }
+ dispatch(search.query(value));
},
render() {
+ const { query } = this.props;
+
return (
<div className="Search/Input">
- <input type="text" placeholder="" onKeyDown={this.onKeyDown} />
+ <input type="text" value={query} onChange={this.onChange} />
</div>
);
}
});
-module.exports = GitBook.connect(SearchInput);
+const mapStateToProps = state => {
+ const { query } = state.search;
+ return { query };
+};
+
+module.exports = GitBook.connect(SearchInput, mapStateToProps);