From 8ae3adbe5a7a651ecc1b180bf9caa7b8dc301f61 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?marcin=20miko=C5=82ajczak?= Date: Wed, 16 Oct 2024 23:36:49 +0200 Subject: [PATCH] pl-fe: fix emoji search MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: marcin mikołajczak --- packages/pl-fe/src/features/emoji/search.ts | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/packages/pl-fe/src/features/emoji/search.ts b/packages/pl-fe/src/features/emoji/search.ts index 5e34595f42..c13f8ddb72 100644 --- a/packages/pl-fe/src/features/emoji/search.ts +++ b/packages/pl-fe/src/features/emoji/search.ts @@ -6,7 +6,14 @@ import type { CustomEmoji } from 'pl-api'; let emojis: EmojiData['emojis'] = {}; -import('./data').then(data => emojis = data.emojis).catch(() => { }); +import('./data').then(data => { + emojis = data.emojis; + + const sortedEmojis = Object.entries(emojis).sort((a, b) => a[0].localeCompare(b[0])); + for (const [key, emoji] of sortedEmojis) { + index.add('n' + key, `${emoji.id} ${emoji.name} ${emoji.keywords.join(' ')}`); + } +}).catch(() => { }); const index = new FlexSearch.Index({ tokenize: 'full', @@ -14,11 +21,6 @@ const index = new FlexSearch.Index({ context: true, }); -const sortedEmojis = Object.entries(emojis).sort((a, b) => a[0].localeCompare(b[0])); -for (const [key, emoji] of sortedEmojis) { - index.add('n' + key, `${emoji.id} ${emoji.name} ${emoji.keywords.join(' ')}`); -} - interface searchOptions { maxResults?: number; custom?: any;