diff --git a/shared/js/smart-screen/cards/folder.js b/shared/js/smart-screen/cards/folder.js index 165a68ca6252..a41b0b53cc02 100644 --- a/shared/js/smart-screen/cards/folder.js +++ b/shared/js/smart-screen/cards/folder.js @@ -58,6 +58,19 @@ return this._cardsInFolder; }; + Folder.prototype.getFilteredCardList = + function folder_getFilteredCardList(filterName) { + if (typeof this._cardsInFolder !== 'object') { + return; + } + if (filterName === 'all') { + return this._cardsInFolder; + } else if (filterName) { + return this._cardsInFolder.filter( + elem => (elem.group === filterName)); + } + }; + Folder.prototype.isEmpty = function folder_isEmpty() { return this._cardsInFolder.length === 0; }; diff --git a/tv_apps/smart-home/js/filter_manager.js b/tv_apps/smart-home/js/filter_manager.js index 63e1ffc4729a..9cb40da05637 100644 --- a/tv_apps/smart-home/js/filter_manager.js +++ b/tv_apps/smart-home/js/filter_manager.js @@ -1,4 +1,4 @@ -/* global CardFilter */ +/* global CardFilter, Folder */ (function(exports) { 'use strict'; @@ -167,7 +167,7 @@ window.requestAnimationFrame(this._performBubbleUp.bind(this)); } else { this._cardListElem.style.opacity = 1; - this._cardListElem.style.transition = undefined; + this._cardListElem.style.transition = ''; this._cardListElem.removeAttribute('smart-bubbles-direction'); this._smartBubblesElem.play( document.querySelectorAll('#card-list > .card > .app-button')); @@ -212,10 +212,22 @@ var that = this; var filter = this.getFilterByIconName(this._cardFilter.filter); - var gotFilteredCardList = function(filteredList) { + var gotCardLists = function(results) { + // results[0] is the main card list which has been filtered. + // results[1] is the main card list. + var filteredList = results[0]; + var cardList = results[1]; + + // Get filtered card list for each folder. + cardList.filter(elem => elem instanceof Folder).forEach(elem => { + filteredList = filteredList.concat( + elem.getFilteredCardList(filter.name)); + }); + filteredList.forEach(function(card) { that._cardScrollable.addNode(that._home.createCardNode(card)); }); + that._filteredCardList = (filter.name !== 'all') ? filteredList : undefined; that._cardListElem.style.opacity = 0; @@ -224,8 +236,10 @@ if (this._isBubbleSinking()) { this._cardScrollable.clean(); - this._cardManager.getFilteredCardList(filter.name).then( - gotFilteredCardList); + Promise.all([ + this._cardManager.getFilteredCardList(filter.name), + this._cardManager.getCardList() + ]).then(gotCardLists); } else { this._isFilterChanging = false; }