summaryrefslogtreecommitdiffstats
path: root/packages/gitbook-plugin-search/src/index.js
diff options
context:
space:
mode:
Diffstat (limited to 'packages/gitbook-plugin-search/src/index.js')
-rw-r--r--packages/gitbook-plugin-search/src/index.js13
1 files changed, 12 insertions, 1 deletions
diff --git a/packages/gitbook-plugin-search/src/index.js b/packages/gitbook-plugin-search/src/index.js
index f08d5d6..05c2056 100644
--- a/packages/gitbook-plugin-search/src/index.js
+++ b/packages/gitbook-plugin-search/src/index.js
@@ -5,8 +5,19 @@ const SearchResults = require('./components/Results');
const reducers = require('./reducers');
const Search = require('./actions/search');
+const onLocationChange = (location, dispatch) => {
+ const { query } = location;
+ const q = query.get('q');
+
+ dispatch(Search.handleQuery(q));
+};
+
module.exports = GitBook.createPlugin({
- init: (dispatch, getState, { Components }) => {
+ init: (dispatch, getState, { Navigation, Components }) => {
+ // Register the navigation handler
+ dispatch(Navigation.listen(onLocationChange));
+
+ // Register components
dispatch(Components.registerComponent(SearchInput, { role: 'search:input' }));
dispatch(Components.registerComponent(SearchResults, { role: 'search:results' }));
},