From 78c14dd93c544ce3687bd2814e300bccd434d5e4 Mon Sep 17 00:00:00 2001 From: tophf Date: Thu, 14 Dec 2017 00:49:11 +0300 Subject: [PATCH] also apply styleDeleted/Added to invisible search results --- popup/search-results.js | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/popup/search-results.js b/popup/search-results.js index 98f6e2f2..46fbbbda 100755 --- a/popup/search-results.js +++ b/popup/search-results.js @@ -111,6 +111,7 @@ window.addEventListener('showStyles:done', function _() { dom.list = $('#search-results-list'); addEventListener('scroll', loadMoreIfNeeded, {passive: true}); + if (FIREFOX) { let lastScrollbarWidth; addEventListener('resize', () => { @@ -125,22 +126,22 @@ window.addEventListener('showStyles:done', function _() { }); } - addEventListener('styleDeleted', ({detail}) => { - const entries = [...dom.list.children]; - const entry = entries.find(el => el._result.installedStyleId === detail.id); - if (entry) { - entry._result.installed = false; - renderActionButtons(entry); + addEventListener('styleDeleted', ({detail: {id}}) => { + const result = processedResults.find(r => r.installedStyleId === id); + if (result) { + result.installed = false; + result.installedStyleId = -1; + renderActionButtons($('#' + RESULT_ID_PREFIX + result.id)); } }); addEventListener('styleAdded', ({detail: {style: {id, md5Url}}}) => { - const usoId = md5Url && md5Url.match(/\d+|$/)[0]; - const entry = usoId && $('#' + RESULT_ID_PREFIX + usoId); - if (entry) { - entry._result.installed = true; - entry._result.installedStyleId = id; - renderActionButtons(entry); + const usoId = parseInt(md5Url && md5Url.match(/\d+|$/)[0]); + const result = usoId && processedResults.find(r => r.id === usoId); + if (result) { + result.installed = true; + result.installedStyleId = id; + renderActionButtons($('#' + RESULT_ID_PREFIX + usoId)); } }); } @@ -488,6 +489,9 @@ window.addEventListener('showStyles:done', function _() { } function renderActionButtons(entry) { + if (!entry) { + return; + } const result = entry._result; if (result.installed && !('installed' in entry.dataset)) {