fix(emoji-picker): debounced search input (#1181)
* fix(Emoji picker): fix lags Fix #1176 using debounced ref * chore: fix strange corepack message Fix corepack claiming strange thing : UsageError: This project is configured to use yarn because /home/runner/work/it-tools/it-tools/package.json has a "packageManager" field
This commit is contained in:
		
							parent
							
								
									b430baef40
								
							
						
					
					
						commit
						76a19d218d
					
				| @ -138,5 +138,6 @@ | |||||||
|     "vitest": "^0.34.0", |     "vitest": "^0.34.0", | ||||||
|     "workbox-window": "^7.0.0", |     "workbox-window": "^7.0.0", | ||||||
|     "zx": "^7.2.1" |     "zx": "^7.2.1" | ||||||
|   } |   }, | ||||||
|  |   "packageManager": "pnpm@8.15.3" | ||||||
| } | } | ||||||
|  | |||||||
							
								
								
									
										21
									
								
								src/composable/debouncedref.ts
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										21
									
								
								src/composable/debouncedref.ts
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,21 @@ | |||||||
|  | import _ from 'lodash'; | ||||||
|  | 
 | ||||||
|  | function useDebouncedRef<T>(initialValue: T, delay: number, immediate: boolean = false) { | ||||||
|  |   const state = ref(initialValue); | ||||||
|  |   const debouncedRef = customRef((track, trigger) => ({ | ||||||
|  |     get() { | ||||||
|  |       track(); | ||||||
|  |       return state.value; | ||||||
|  |     }, | ||||||
|  |     set: _.debounce( | ||||||
|  |       (value) => { | ||||||
|  |         state.value = value; | ||||||
|  |         trigger(); | ||||||
|  |       }, | ||||||
|  |       delay, | ||||||
|  |       { leading: immediate }, | ||||||
|  |     ), | ||||||
|  |   })); | ||||||
|  |   return debouncedRef; | ||||||
|  | } | ||||||
|  | export default useDebouncedRef; | ||||||
| @ -4,6 +4,7 @@ import emojiKeywords from 'emojilib'; | |||||||
| import _ from 'lodash'; | import _ from 'lodash'; | ||||||
| import type { EmojiInfo } from './emoji.types'; | import type { EmojiInfo } from './emoji.types'; | ||||||
| import { useFuzzySearch } from '@/composable/fuzzySearch'; | import { useFuzzySearch } from '@/composable/fuzzySearch'; | ||||||
|  | import useDebouncedRef from '@/composable/debouncedref'; | ||||||
| 
 | 
 | ||||||
| const escapeUnicode = ({ emoji }: { emoji: string }) => emoji.split('').map(unit => `\\u${unit.charCodeAt(0).toString(16).padStart(4, '0')}`).join(''); | const escapeUnicode = ({ emoji }: { emoji: string }) => emoji.split('').map(unit => `\\u${unit.charCodeAt(0).toString(16).padStart(4, '0')}`).join(''); | ||||||
| const getEmojiCodePoints = ({ emoji }: { emoji: string }) => emoji.codePointAt(0) ? `0x${emoji.codePointAt(0)?.toString(16)}` : undefined; | const getEmojiCodePoints = ({ emoji }: { emoji: string }) => emoji.codePointAt(0) ? `0x${emoji.codePointAt(0)?.toString(16)}` : undefined; | ||||||
| @ -23,7 +24,7 @@ const emojisGroups: { emojiInfos: EmojiInfo[]; group: string }[] = _ | |||||||
|   .map((emojiInfos, group) => ({ group, emojiInfos })) |   .map((emojiInfos, group) => ({ group, emojiInfos })) | ||||||
|   .value(); |   .value(); | ||||||
| 
 | 
 | ||||||
| const searchQuery = ref(''); | const searchQuery = useDebouncedRef('', 500); | ||||||
| 
 | 
 | ||||||
| const { searchResult } = useFuzzySearch({ | const { searchResult } = useFuzzySearch({ | ||||||
|   search: searchQuery, |   search: searchQuery, | ||||||
|  | |||||||
		Loading…
	
		Reference in New Issue
	
	Block a user