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

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: Remove selection from this CL 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
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,
};
});

Powered by Google App Engine
This is Rietveld 408576698