summaryrefslogtreecommitdiffstats
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
parent9aaf561c4195dd363e66667b3d697694ae134337 (diff)
downloadgitbook-24624f0d0e3f489a0430daa20a0ca59497b4e0d6.zip
gitbook-24624f0d0e3f489a0430daa20a0ca59497b4e0d6.tar.gz
gitbook-24624f0d0e3f489a0430daa20a0ca59497b4e0d6.tar.bz2
Fix clear of search
-rw-r--r--packages/gitbook-core/src/models/File.js9
-rw-r--r--packages/gitbook-core/src/shapes/Summary.js5
-rw-r--r--packages/gitbook-core/src/shapes/SummaryArticle.js7
-rw-r--r--packages/gitbook-core/src/shapes/SummaryPart.js5
-rw-r--r--packages/gitbook-plugin-search/src/actions/search.js4
-rw-r--r--packages/gitbook-plugin-search/src/actions/types.js4
-rw-r--r--packages/gitbook-plugin-search/src/reducers/search.js20
7 files changed, 36 insertions, 18 deletions
diff --git a/packages/gitbook-core/src/models/File.js b/packages/gitbook-core/src/models/File.js
index 09dfc1b..6f44700 100644
--- a/packages/gitbook-core/src/models/File.js
+++ b/packages/gitbook-core/src/models/File.js
@@ -3,17 +3,20 @@ const { Record } = require('immutable');
const DEFAULTS = {
type: '',
- mtime: '',
+ mtime: new Date(),
path: ''
};
class File extends Record(DEFAULTS) {
- constructor(file) {
+ constructor(file = {}) {
if (typeof file === 'string') {
file = { path: file };
}
- super(file);
+ super({
+ ...file,
+ mtime: new Date(file.mtime)
+ });
}
/**
diff --git a/packages/gitbook-core/src/shapes/Summary.js b/packages/gitbook-core/src/shapes/Summary.js
index 7efe4e0..f97e66c 100644
--- a/packages/gitbook-core/src/shapes/Summary.js
+++ b/packages/gitbook-core/src/shapes/Summary.js
@@ -1,6 +1,7 @@
const React = require('react');
+const { listOf } = require('react-immutable-proptypes');
+
const {
- arrayOf,
shape
} = React.PropTypes;
@@ -9,5 +10,5 @@ const Part = require('./SummaryPart');
module.exports = shape({
file: File.isRequired,
- parts: arrayOf(Part).isRequired
+ parts: listOf(Part).isRequired
});
diff --git a/packages/gitbook-core/src/shapes/SummaryArticle.js b/packages/gitbook-core/src/shapes/SummaryArticle.js
index d13bb31..c5aa717 100644
--- a/packages/gitbook-core/src/shapes/SummaryArticle.js
+++ b/packages/gitbook-core/src/shapes/SummaryArticle.js
@@ -1,8 +1,9 @@
/* eslint-disable no-use-before-define */
-const React = require('react');
+const React = require('react');
+const { list } = require('react-immutable-proptypes');
+
const {
- arrayOf,
string,
number,
shape
@@ -14,7 +15,7 @@ const Article = shape({
path: string,
ref: string,
level: string,
- articles: arrayOf(Article)
+ articles: list
});
module.exports = Article;
diff --git a/packages/gitbook-core/src/shapes/SummaryPart.js b/packages/gitbook-core/src/shapes/SummaryPart.js
index 75d5602..769ddd1 100644
--- a/packages/gitbook-core/src/shapes/SummaryPart.js
+++ b/packages/gitbook-core/src/shapes/SummaryPart.js
@@ -1,6 +1,7 @@
const React = require('react');
+const { listOf } = require('react-immutable-proptypes');
+
const {
- arrayOf,
string,
shape
} = React.PropTypes;
@@ -9,5 +10,5 @@ const Article = require('./SummaryArticle');
module.exports = shape({
title: string.isRequired,
- articles: arrayOf(Article)
+ articles: listOf(Article)
});
diff --git a/packages/gitbook-plugin-search/src/actions/search.js b/packages/gitbook-plugin-search/src/actions/search.js
index fe7fdfe..52afc3c 100644
--- a/packages/gitbook-plugin-search/src/actions/search.js
+++ b/packages/gitbook-plugin-search/src/actions/search.js
@@ -15,7 +15,7 @@ function query(q) {
return (dispatch, getState) => {
const { handlers } = getState().search;
- dispatch({ type: TYPES.UPDATE_QUERY, query: q });
+ dispatch({ type: TYPES.START, query: q });
return Promise.reduce(
handlers.toArray(),
@@ -27,7 +27,7 @@ function query(q) {
)
.then(
results => {
- dispatch({ type: TYPES.UPDATE_RESULTS, query: q, results });
+ dispatch({ type: TYPES.END, query: q, results });
}
);
};
diff --git a/packages/gitbook-plugin-search/src/actions/types.js b/packages/gitbook-plugin-search/src/actions/types.js
index ddbd086..6886098 100644
--- a/packages/gitbook-plugin-search/src/actions/types.js
+++ b/packages/gitbook-plugin-search/src/actions/types.js
@@ -3,6 +3,6 @@ module.exports = {
CLEAR: 'search/clear',
REGISTER_HANDLER: 'search/register_handler',
UNREGISTER_HANDLER: 'search/unregister_handler',
- UPDATE_QUERY: 'search/update_query',
- UPDATE_RESULTS: 'search/update_results'
+ START: 'search/start',
+ END: 'search/end'
};
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
});