diff options
Diffstat (limited to 'packages/gitbook-plugin-search/src/index.js')
-rw-r--r-- | packages/gitbook-plugin-search/src/index.js | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/packages/gitbook-plugin-search/src/index.js b/packages/gitbook-plugin-search/src/index.js new file mode 100644 index 0000000..f8c59aa --- /dev/null +++ b/packages/gitbook-plugin-search/src/index.js @@ -0,0 +1,33 @@ +const GitBook = require('gitbook-core'); + +const SearchInput = require('./components/Input'); +const SearchResults = require('./components/Results'); +const reducers = require('./reducers'); +const Search = require('./actions/search'); + +/** + * Url of the page changed, we update the search according to this. + * @param {GitBook.Location} location + * @param {Function} dispatch + */ +const onLocationChange = (location, dispatch) => { + const { query } = location; + const q = query.get('q'); + + dispatch(Search.handleQuery(q)); +}; + +module.exports = GitBook.createPlugin({ + activate: (dispatch, getState, { History, Components }) => { + // Register the navigation handler + dispatch(History.listen(onLocationChange)); + + // Register components + dispatch(Components.registerComponent(SearchInput, { role: 'search:container:input' })); + dispatch(Components.registerComponent(SearchResults, { role: 'search:container:results' })); + }, + reduce: reducers, + actions: { + Search + } +}); |