From fd7691495b7d726848eff665a4da30db8a716f17 Mon Sep 17 00:00:00 2001 From: Dark_Phoenix_ <92178883+0DarkPhoenix@users.noreply.github.com> Date: Sun, 8 Jun 2025 10:54:12 +0200 Subject: [PATCH] Improve hompage performance (#85) * Improved performance on the Unicode Search page: - Created new flexSearch component (Faster than fuzzySearch). For more information, see https://github.com/nextapps-de/flexsearch - Replaced fuzzySearch with the flexSearch component on the unicode search page - Fixed a bug where the search limit counter didn't have any effect - Reduced the default search limit from 100 to 40 to reduce lag from loading all the ui elements * Added clarification to comment * components.d.ts update * - Replaced FuzzySearch with FlexSearch on the ISO 3166 Searcher page - Reduced the debounce from 500ms to 250ms - Reduced the default search limit from 100 to 20, and fixed a bug where the search limit wasn't applied when the value changed - Added the `readonly` prop to the `input-copyable` field - Added the `readonly` flag to all input copyable fields on the unicode search and iso 3166 searcher pages * Merged new changes to flexSearch * chore: vercel optimisation tentative * Emoji Picker: - Replaced fuzzysearch with flexsearch - Reduced debounce from 500ms to 250ms - Increased search limit from 100 to 150 - Implemented a UI loading sequence where it will load an emoji group each 150ms instead of loading all groups at once. This eliminates the lag experienced when loading the page or when removing the search query - Updated unicode-emoji-json from version 0.4.0 to 0.8.0 Emoji Card: - Fixed an issue where the country flag emojis weren't being rendered - Added row which displays the emoji keywords, and uses a tooltip to display all keywords when they are truncated to fit in the card - Moved codepoints and unicode escape lines to seperate rows instead of occasionally being displayed on the same line * - Added logic to use an emoji in the search query * small change * - Replaced fuzzysearch with flexsearch in the command pallette - Improved the performance of the collapsible tool menu by rewriting the logic to prevent the DOM elements being destroyed and recreated each time a category is expanded or collapsed - Added logic to load the home page tool cards in batches instead of all at once * Fixed linter error * Fixed an issue where the weight of a search key wasn't properly being applied --------- Co-authored-by: ShareVB --- components.d.ts | 21 +++ src/components/CollapsibleToolMenu.vue | 146 +++++++++++------- src/composable/flexSearch.ts | 58 +++++-- .../command-palette/command-palette.store.ts | 5 +- src/pages/Home.page.vue | 66 +++++++- 5 files changed, 220 insertions(+), 76 deletions(-) diff --git a/components.d.ts b/components.d.ts index 04223256..d1320009 100644 --- a/components.d.ts +++ b/components.d.ts @@ -192,6 +192,7 @@ declare module '@vue/runtime-core' { IcoConverter: typeof import('./src/tools/ico-converter/ico-converter.vue')['default'] 'IconMdi:brushVariant': typeof import('~icons/mdi/brush-variant')['default'] 'IconMdi:kettleSteamOutline': typeof import('~icons/mdi/kettle-steam-outline')['default'] + IconMdiArrowDown: typeof import('~icons/mdi/arrow-down')['default'] IconMdiChevronDown: typeof import('~icons/mdi/chevron-down')['default'] IconMdiChevronRight: typeof import('~icons/mdi/chevron-right')['default'] IconMdiClose: typeof import('~icons/mdi/close')['default'] @@ -298,26 +299,46 @@ declare module '@vue/runtime-core' { MorseConverter: typeof import('./src/tools/morse-converter/morse-converter.vue')['default'] MultiLinkDownloader: typeof import('./src/tools/multi-link-downloader/multi-link-downloader.vue')['default'] MyIp: typeof import('./src/tools/my-ip/my-ip.vue')['default'] + NA: typeof import('naive-ui')['NA'] + NAlert: typeof import('naive-ui')['NAlert'] NanoidGenerator: typeof import('./src/tools/nanoid-generator/nanoid-generator.vue')['default'] NanoMemo: typeof import('./src/tools/nano-memo/nano-memo.vue')['default'] 'NanoMemo.content': typeof import('./src/tools/nano-memo/nano-memo.content.md')['default'] NavbarButtons: typeof import('./src/components/NavbarButtons.vue')['default'] NButton: typeof import('naive-ui')['NButton'] + NCard: typeof import('naive-ui')['NCard'] + NCheckbox: typeof import('naive-ui')['NCheckbox'] + NCode: typeof import('naive-ui')['NCode'] NCollapseTransition: typeof import('naive-ui')['NCollapseTransition'] NConfigProvider: typeof import('naive-ui')['NConfigProvider'] + NDivider: typeof import('naive-ui')['NDivider'] NEllipsis: typeof import('naive-ui')['NEllipsis'] + NFormItem: typeof import('naive-ui')['NFormItem'] + NGi: typeof import('naive-ui')['NGi'] NginxFormatter: typeof import('./src/tools/nginx-formatter/nginx-formatter.vue')['default'] NginxMemo: typeof import('./src/tools/nginx-memo/nginx-memo.vue')['default'] 'NginxMemo.content': typeof import('./src/tools/nginx-memo/nginx-memo.content.md')['default'] + NGrid: typeof import('naive-ui')['NGrid'] NH1: typeof import('naive-ui')['NH1'] NH3: typeof import('naive-ui')['NH3'] NIcon: typeof import('naive-ui')['NIcon'] + NInput: typeof import('naive-ui')['NInput'] + NInputGroup: typeof import('naive-ui')['NInputGroup'] + NInputNumber: typeof import('naive-ui')['NInputNumber'] NLayout: typeof import('naive-ui')['NLayout'] NLayoutSider: typeof import('naive-ui')['NLayoutSider'] NMenu: typeof import('naive-ui')['NMenu'] NP: typeof import('naive-ui')['NP'] + NRadio: typeof import('naive-ui')['NRadio'] + NRadioGroup: typeof import('naive-ui')['NRadioGroup'] + NScrollbar: typeof import('naive-ui')['NScrollbar'] + NSpace: typeof import('naive-ui')['NSpace'] + NSpin: typeof import('naive-ui')['NSpin'] + NStatistic: typeof import('naive-ui')['NStatistic'] + NSwitch: typeof import('naive-ui')['NSwitch'] NSpin: typeof import('naive-ui')['NSpin'] NTable: typeof import('naive-ui')['NTable'] + NTag: typeof import('naive-ui')['NTag'] NumberInput: typeof import('./src/tools/pomodoro-timer/app/components/NumberInput.vue')['default'] NumeronymGenerator: typeof import('./src/tools/numeronym-generator/numeronym-generator.vue')['default'] OcrImage: typeof import('./src/tools/ocr-image/ocr-image.vue')['default'] diff --git a/src/components/CollapsibleToolMenu.vue b/src/components/CollapsibleToolMenu.vue index bd3045cf..cf653daa 100644 --- a/src/components/CollapsibleToolMenu.vue +++ b/src/components/CollapsibleToolMenu.vue @@ -25,37 +25,40 @@ const collapsedCategories = useStorage>( }, ); +const isToggling = ref(false); + function toggleCategoryCollapse({ name }: { name: string }) { collapsedCategories.value[name] = !collapsedCategories.value[name]; } -/** - * areAllCollapsed (new) - * -------------------------------------------------------------------------- - * A computed property that checks if all categories are collapsed. - * - If even one category is expanded (false), this becomes false. - * - If no categories are found or all are collapsed (true), it becomes true. - */ const areAllCollapsed = computed(() => { return toolsByCategory.value.every(({ name }) => collapsedCategories.value[name] !== false); }); -/** - * toggleAllCategories (new) - * -------------------------------------------------------------------------- - * If all categories are collapsed, expand them all; otherwise, collapse them all. - */ -function toggleAllCategories() { - const nextState = !areAllCollapsed.value; +async function toggleAllCategories() { + if (isToggling.value) { + return; + } + + isToggling.value = true; + + const shouldCollapse = !areAllCollapsed.value; + const updates: Record = {}; + toolsByCategory.value.forEach(({ name }) => { - collapsedCategories.value[name] = nextState; + updates[name] = shouldCollapse; }); -}; + + Object.assign(collapsedCategories.value, updates); + + await nextTick(); + isToggling.value = false; +} const menuOptions = computed(() => toolsByCategory.value.map(({ name, components }) => ({ name, - isCollapsed: collapsedCategories.value[name] === undefined ? true : collapsedCategories.value[name], // default to collapsed if not set + isCollapsed: collapsedCategories.value[name] === undefined ? true : collapsedCategories.value[name], tools: components.map(tool => ({ label: makeLabel(tool), icon: makeIcon(tool), @@ -68,18 +71,18 @@ const themeVars = useThemeVars();