OLD | NEW |
1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 /** | 5 /** |
6 * @fileoverview Utility functions for the Bookmarks page. | 6 * @fileoverview Utility functions for the Bookmarks page. |
7 */ | 7 */ |
8 | 8 |
9 cr.define('bookmarks.util', function() { | 9 cr.define('bookmarks.util', function() { |
10 /** | 10 /** |
11 * @param {!BookmarksPageState} state | 11 * @param {!BookmarksPageState} state |
12 * @return {!Array<string>} | 12 * @return {!Array<string>} |
13 */ | 13 */ |
14 function getDisplayedList(state) { | 14 function getDisplayedList(state) { |
15 if (state.selectedFolder) | 15 if (!isShowingSearch(state)) |
16 return assert(state.nodes[state.selectedFolder].children); | 16 return assert(state.nodes[assert(state.selectedFolder)].children); |
17 | 17 |
18 return state.search.results; | 18 return state.search.results; |
19 } | 19 } |
20 | 20 |
21 /** | 21 /** |
22 * @param {BookmarkTreeNode} rootNode | 22 * @param {BookmarkTreeNode} rootNode |
23 * @return {NodeList} | 23 * @return {NodeList} |
24 */ | 24 */ |
25 function normalizeNodes(rootNode) { | 25 function normalizeNodes(rootNode) { |
26 /** @type {NodeList} */ | 26 /** @type {NodeList} */ |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
60 inProgress: false, | 60 inProgress: false, |
61 results: [], | 61 results: [], |
62 }, | 62 }, |
63 selection: { | 63 selection: { |
64 items: {}, | 64 items: {}, |
65 anchor: null, | 65 anchor: null, |
66 }, | 66 }, |
67 }; | 67 }; |
68 } | 68 } |
69 | 69 |
| 70 /** |
| 71 * @param {BookmarksPageState} state |
| 72 * @return boolean |
| 73 */ |
| 74 function isShowingSearch(state) { |
| 75 return !state.selectedFolder; |
| 76 } |
| 77 |
| 78 /** |
| 79 * @param {string} id |
| 80 * @param {NodeList} nodes |
| 81 * @return {boolean} |
| 82 */ |
| 83 function hasChildFolders(id, nodes) { |
| 84 var children = nodes[id].children; |
| 85 for (var i = 0; i < children.length; i++) { |
| 86 if (nodes[children[i]].children) |
| 87 return true; |
| 88 } |
| 89 return false; |
| 90 } |
| 91 |
70 return { | 92 return { |
71 createEmptyState: createEmptyState, | 93 createEmptyState: createEmptyState, |
72 getDisplayedList: getDisplayedList, | 94 getDisplayedList: getDisplayedList, |
| 95 hasChildFolders: hasChildFolders, |
| 96 isShowingSearch: isShowingSearch, |
73 normalizeNodes: normalizeNodes, | 97 normalizeNodes: normalizeNodes, |
| 98 ROOT_NODE_ID: '0', |
74 }; | 99 }; |
75 }); | 100 }); |
OLD | NEW |