mirror of
https://github.com/element-hq/element-web
synced 2024-11-23 09:46:09 +03:00
Simplify onChangeFilter category updating
Signed-off-by: Tulir Asokan <tulir@maunium.net>
This commit is contained in:
parent
bb1a242ef0
commit
7fc12b4b13
1 changed files with 9 additions and 6 deletions
|
@ -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;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue