mirror of
https://github.com/GitbookIO/gitbook.git
synced 2026-09-25 11:52:10 +00:00
Fix search not refreshed when adding an handler
This commit is contained in:
@@ -66,6 +66,20 @@ function handleQuery(q) {
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Refresh current search (when handlers have changed)
|
||||
* @return {Action}
|
||||
*/
|
||||
function refresh() {
|
||||
return (dispatch, getState) => {
|
||||
const q = getState().search.query;
|
||||
console.log('refresh search with', q);
|
||||
if (q) {
|
||||
dispatch(handleQuery(q));
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Clear the whole search
|
||||
* @return {Action}
|
||||
@@ -81,7 +95,10 @@ function clear() {
|
||||
* @return {Action}
|
||||
*/
|
||||
function registerHandler(name, handler) {
|
||||
return { type: TYPES.REGISTER_HANDLER, name, handler };
|
||||
return (dispatch) => {
|
||||
dispatch({ type: TYPES.REGISTER_HANDLER, name, handler });
|
||||
dispatch(refresh());
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -90,7 +107,10 @@ function registerHandler(name, handler) {
|
||||
* @return {Action}
|
||||
*/
|
||||
function unregisterHandler(name) {
|
||||
return { type: TYPES.UNREGISTER_HANDLER, name };
|
||||
return (dispatch) => {
|
||||
dispatch({ type: TYPES.UNREGISTER_HANDLER, name });
|
||||
dispatch(refresh());
|
||||
};
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
|
||||
@@ -11,7 +11,9 @@ const Result = React.createClass({
|
||||
|
||||
return (
|
||||
<div className="Search-Result">
|
||||
<h3>{result.title}</h3>
|
||||
<h3>
|
||||
<GitBook.Link to={result.url}>{result.title}</GitBook.Link>
|
||||
</h3>
|
||||
<p>{result.body}</p>
|
||||
</div>
|
||||
);
|
||||
@@ -36,7 +38,7 @@ const SearchResults = React.createClass({
|
||||
return (
|
||||
<div className="Search-ResultsContainer">
|
||||
<h1>{i18n.t('SEARCH_RESULTS_TITLE', { query, count: results.size })}</h1>
|
||||
<div className="Search/Results">
|
||||
<div className="Search-Results">
|
||||
{results.map((result, i) => {
|
||||
return <Result key={i} result={result} />;
|
||||
})}
|
||||
|
||||
Reference in New Issue
Block a user