Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1400)

Unified Diff: chrome/browser/resources/md_bookmarks/reducers.js

Issue 2740863003: MD Bookmarks: Implement search and selection in new data flow system (Closed)
Patch Set: Review round 2 Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/browser/resources/md_bookmarks/list.js ('k') | chrome/browser/resources/md_bookmarks/toolbar.js » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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..629017b21a1d806e8b8a0ef2d13ba761f72ba49d 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,12 @@ cr.define('bookmarks', function() {
return action.id;
}
return selectedFolder;
+ case 'finish-search':
+ return null;
+ case 'clear-search':
+ // TODO(tsergeant): Return to the folder that was selected before the
+ // search.
+ return nodes['0'].children[0];
default:
return selectedFolder;
}
@@ -183,6 +244,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 +252,7 @@ cr.define('bookmarks', function() {
reduceAction: reduceAction,
ClosedFolderState: ClosedFolderState,
NodeState: NodeState,
+ SearchState: SearchState,
SelectedFolderState: SelectedFolderState,
};
});
« no previous file with comments | « chrome/browser/resources/md_bookmarks/list.js ('k') | chrome/browser/resources/md_bookmarks/toolbar.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698