summaryrefslogtreecommitdiffstats
path: root/packages/gitbook-plugin-search/src/reducers/search.js
diff options
context:
space:
mode:
authorSamy Pesse <samypesse@gmail.com>2016-10-02 00:15:59 +0200
committerSamy Pesse <samypesse@gmail.com>2016-10-02 00:15:59 +0200
commit24624f0d0e3f489a0430daa20a0ca59497b4e0d6 (patch)
tree30a6b8aac357d4effcdfdaa918f4ade49c964934 /packages/gitbook-plugin-search/src/reducers/search.js
parent9aaf561c4195dd363e66667b3d697694ae134337 (diff)
downloadgitbook-24624f0d0e3f489a0430daa20a0ca59497b4e0d6.zip
gitbook-24624f0d0e3f489a0430daa20a0ca59497b4e0d6.tar.gz
gitbook-24624f0d0e3f489a0430daa20a0ca59497b4e0d6.tar.bz2
Fix clear of search
Diffstat (limited to 'packages/gitbook-plugin-search/src/reducers/search.js')
-rw-r--r--packages/gitbook-plugin-search/src/reducers/search.js20
1 files changed, 16 insertions, 4 deletions
diff --git a/packages/gitbook-plugin-search/src/reducers/search.js b/packages/gitbook-plugin-search/src/reducers/search.js
index 4bf7b31..b960a77 100644
--- a/packages/gitbook-plugin-search/src/reducers/search.js
+++ b/packages/gitbook-plugin-search/src/reducers/search.js
@@ -4,6 +4,8 @@ const { Record, List, OrderedMap } = GitBook.Immutable;
const TYPES = require('../actions/types');
const SearchState = Record({
+ // Is the search being processed
+ loading: Boolean(false),
// Current query
query: String(''),
// Current list of results
@@ -16,15 +18,25 @@ module.exports = (state = SearchState(), action) => {
switch (action.type) {
case TYPES.CLEAR:
- return SearchState();
+ return state.merge({
+ loading: false,
+ query: '',
+ results: List()
+ });
- case TYPES.UPDATE_QUERY:
+ case TYPES.START:
return state.merge({
- query: action.query
+ loading: true,
+ query: action.query
});
- case TYPES.UPDATE_RESULTS:
+ case TYPES.END:
+ if (action.query !== state.query) {
+ return state;
+ }
+
return state.merge({
+ loading: false,
results: action.results
});