feat: add virtual scroll to links dropdown

Enhances dropdown performance by implementing virtual scrolling with VList from virtua/vue library. This optimization improves rendering efficiency for large link lists by only rendering visible items.
This commit is contained in:
ccbikai 2025-03-02 14:33:47 +08:00
parent dd7b898a11
commit 6070f2f5c3

View file

@ -1,7 +1,8 @@
<script setup> <script setup>
import { useUrlSearchParams } from '@vueuse/core' import { useUrlSearchParams, watchDebounced } from '@vueuse/core'
import { safeDestr } from 'destr' import { safeDestr } from 'destr'
import { Check, ChevronsUpDown } from 'lucide-vue-next' import { Check, ChevronsUpDown } from 'lucide-vue-next'
import { VList } from 'virtua/vue'
const emit = defineEmits(['change']) const emit = defineEmits(['change'])
@ -17,9 +18,9 @@ onMounted(() => {
getLinks() getLinks()
}) })
watch(selectedLinks, (value) => { watchDebounced(selectedLinks, (value) => {
emit('change', 'slug', value.join(',')) emit('change', 'slug', value.join(','))
}) }, { debounce: 500, maxWait: 1000 })
function restoreFilters() { function restoreFilters() {
const searchParams = useUrlSearchParams('history') const searchParams = useUrlSearchParams('history')
@ -57,11 +58,13 @@ onBeforeMount(() => {
<CommandEmpty>No link found.</CommandEmpty> <CommandEmpty>No link found.</CommandEmpty>
<CommandList> <CommandList>
<CommandGroup> <CommandGroup>
<VList
v-slot="{ item: link }"
:data="links"
:style="{ height: '292px' }"
>
<CommandItem <CommandItem
v-for="link in links"
:key="link.slug"
:value="link.slug" :value="link.slug"
@select="isOpen = false"
> >
<Check <Check
:class="cn( :class="cn(
@ -71,6 +74,7 @@ onBeforeMount(() => {
/> />
{{ link.slug }} {{ link.slug }}
</CommandItem> </CommandItem>
</VList>
</CommandGroup> </CommandGroup>
</CommandList> </CommandList>
</Command> </Command>