From eb546619496d327af8e056c87c570084158c5ae4 Mon Sep 17 00:00:00 2001 From: chadmin Date: Sat, 26 Oct 2024 19:25:21 -0700 Subject: [PATCH] feat(emoji-picker) add lazy loading to improve initial load performance --- src/tools/emoji-picker/emoji-picker.vue | 64 +++++++++++++++++++++---- src/tools/emoji-picker/index.ts | 4 +- 2 files changed, 57 insertions(+), 11 deletions(-) diff --git a/src/tools/emoji-picker/emoji-picker.vue b/src/tools/emoji-picker/emoji-picker.vue index a12b10c2..2110579a 100644 --- a/src/tools/emoji-picker/emoji-picker.vue +++ b/src/tools/emoji-picker/emoji-picker.vue @@ -2,6 +2,7 @@ import emojiUnicodeData from 'unicode-emoji-json'; import emojiKeywords from 'emojilib'; import _ from 'lodash'; +import { IconChevronRight, IconSearch } from '@tabler/icons-vue'; import type { EmojiInfo } from './emoji.types'; import { useFuzzySearch } from '@/composable/fuzzySearch'; import useDebouncedRef from '@/composable/debouncedref'; @@ -36,10 +37,36 @@ const { searchResult } = useFuzzySearch({ isCaseSensitive: false, }, }); + +const emojisPerPage = 30; // Number of emojis to load per group initially + +// Tracks how many emojis are shown per group and the collapsed state of each group +const groupLoadLimits = ref( + emojisGroups.reduce((acc, group) => { + acc[group.group] = { limit: emojisPerPage, collapsed: false }; + return acc; + }, {} as Record), +); + +// Toggles the visibility of the emoji group +function toggleGroup(group: string) { + groupLoadLimits.value[group].collapsed = !groupLoadLimits.value[group].collapsed; +}; + +// Loads more emojis incrementally +function loadMoreEmojis(group: string) { + groupLoadLimits.value[group].limit += emojisPerPage; +}; + +// Loads all emojis in the group at once +function loadAllEmojis(group: string) { + groupLoadLimits.value[group].limit = emojisGroups.find(g => g.group === group)?.emojiInfos.length || 0; +}; diff --git a/src/tools/emoji-picker/index.ts b/src/tools/emoji-picker/index.ts index 3a28cf0f..adad179a 100644 --- a/src/tools/emoji-picker/index.ts +++ b/src/tools/emoji-picker/index.ts @@ -1,4 +1,4 @@ -import { MoodSmile } from '@vicons/tabler'; +import { IconMoodSmile } from '@tabler/icons-vue'; import { defineTool } from '../tool'; import { translate } from '@/plugins/i18n.plugin'; @@ -8,6 +8,6 @@ export const tool = defineTool({ description: translate('tools.emoji-picker.description'), keywords: ['emoji', 'picker', 'unicode', 'copy', 'paste'], component: () => import('./emoji-picker.vue'), - icon: MoodSmile, + icon: IconMoodSmile, createdAt: new Date('2023-08-07'), });