From 7fc12b4b13a66169852d38cc00919a115273fd6c Mon Sep 17 00:00:00 2001 From: Tulir Asokan Date: Mon, 14 Oct 2019 21:30:21 +0300 Subject: [PATCH] Simplify onChangeFilter category updating Signed-off-by: Tulir Asokan --- src/components/views/emojipicker/EmojiPicker.js | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/src/components/views/emojipicker/EmojiPicker.js b/src/components/views/emojipicker/EmojiPicker.js index c5e16ff601..f5a977f930 100644 --- a/src/components/views/emojipicker/EmojiPicker.js +++ b/src/components/views/emojipicker/EmojiPicker.js @@ -173,14 +173,17 @@ class EmojiPicker extends React.Component { } onChangeFilter(filter) { - for (let [id, emojis] of Object.entries(this.memoizedDataByCategory)) { + for (const cat of this.categories) { + let emojis; // If the new filter string includes the old filter string, we don't have to re-filter the whole dataset. - if (!filter.includes(this.state.filter)) { - emojis = id === "recent" ? this.recentlyUsed : DATA_BY_CATEGORY[id]; + if (filter.includes(this.state.filter)) { + emojis = this.memoizedDataByCategory[cat.id]; + } else { + emojis = cat.id === "recent" ? this.recentlyUsed : DATA_BY_CATEGORY[cat.id]; } - this.memoizedDataByCategory[id] = emojis.filter(emoji => emoji.filterString.includes(filter)); - const cat = this.categories.find(cat => cat.id === id); - cat.enabled = this.memoizedDataByCategory[id].length > 0; + emojis = emojis.filter(emoji => emoji.filterString.includes(filter)); + this.memoizedDataByCategory[cat.id] = emojis; + cat.enabled = emojis.length > 0; // The setState below doesn't re-render the header and we already have the refs for updateVisibility, so... cat.ref.current.disabled = !cat.enabled; }