Chromium Code Reviews| Index: chrome/browser/resources/md_bookmarks/reducers.js |
| diff --git a/chrome/browser/resources/md_bookmarks/reducers.js b/chrome/browser/resources/md_bookmarks/reducers.js |
| index 4021761c094b21947500be1347b6c6434f1255cc..ca13ab5cd7c1e820662349656f45aae15251c25a 100644 |
| --- a/chrome/browser/resources/md_bookmarks/reducers.js |
| +++ b/chrome/browser/resources/md_bookmarks/reducers.js |
| @@ -10,6 +10,61 @@ |
| */ |
| cr.define('bookmarks', function() { |
| + var SearchState = {}; |
| + |
| + /** |
| + * @param {SearchState} search |
| + * @param {Action} action |
| + * @return {SearchState} |
| + */ |
| + SearchState.startSearch = function(search, action) { |
| + return { |
| + term: action.term, |
| + inProgress: true, |
| + results: [], |
| + }; |
| + }; |
| + |
| + /** |
| + * @param {SearchState} search |
| + * @param {Action} action |
| + * @return {SearchState} |
| + */ |
| + SearchState.finishSearch = function(search, action) { |
| + return /** @type {SearchState} */ (Object.assign({}, search, { |
| + inProgress: false, |
| + results: action.results, |
| + })); |
| + }; |
| + |
| + /** @return {SearchState} */ |
| + SearchState.clearSearch = function() { |
| + return { |
| + term: '', |
| + inProgress: false, |
| + results: [], |
| + }; |
| + }; |
| + |
| + /** |
| + * @param {SearchState} search |
| + * @param {Action} action |
| + * @return {SearchState} |
| + */ |
| + SearchState.updateSearch = function(search, action) { |
| + switch (action.name) { |
| + case 'start-search': |
| + return SearchState.startSearch(search, action); |
| + case 'select-folder': |
| + case 'clear-search': |
| + return SearchState.clearSearch(); |
| + case 'finish-search': |
| + return SearchState.finishSearch(search, action); |
| + default: |
| + return search; |
| + } |
| + }; |
| + |
| var NodeState = {}; |
| /** |
| @@ -112,6 +167,10 @@ cr.define('bookmarks', function() { |
| return action.id; |
| } |
| return selectedFolder; |
| + case 'finish-search': |
| + return null; |
| + case 'clear-search': |
| + return nodes['0'].children[0]; |
|
calamity
2017/03/13 04:50:36
Add a TODO to make this return to the previously s
tsergeant
2017/03/14 02:40:36
Done.
|
| default: |
| return selectedFolder; |
| } |
| @@ -183,6 +242,7 @@ cr.define('bookmarks', function() { |
| state.selectedFolder, action, state.nodes), |
| closedFolders: ClosedFolderState.updateClosedFolders( |
| state.closedFolders, action, state.nodes), |
| + search: SearchState.updateSearch(state.search, action), |
| }; |
| } |
| @@ -190,6 +250,7 @@ cr.define('bookmarks', function() { |
| reduceAction: reduceAction, |
| ClosedFolderState: ClosedFolderState, |
| NodeState: NodeState, |
| + SearchState: SearchState, |
| SelectedFolderState: SelectedFolderState, |
| }; |
| }); |