diff options
author | Samy Pesse <samypesse@gmail.com> | 2016-10-03 00:59:26 +0200 |
---|---|---|
committer | Samy Pesse <samypesse@gmail.com> | 2016-10-03 00:59:26 +0200 |
commit | 3ae72bb47c146212d40fc74d857880fa0616ae57 (patch) | |
tree | 28986218bb512580272f9709fbdee01f6ede52dd /packages/gitbook-plugin-search/src/index.js | |
parent | cd2d5e5101edb466b13ada19b09ea42ef726ad96 (diff) | |
download | gitbook-3ae72bb47c146212d40fc74d857880fa0616ae57.zip gitbook-3ae72bb47c146212d40fc74d857880fa0616ae57.tar.gz gitbook-3ae72bb47c146212d40fc74d857880fa0616ae57.tar.bz2 |
Sync search with querystring
Diffstat (limited to 'packages/gitbook-plugin-search/src/index.js')
-rw-r--r-- | packages/gitbook-plugin-search/src/index.js | 13 |
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' })); }, |