|
3 | 3 | - SPDX-License-Identifier: AGPL-3.0-or-later |
4 | 4 | --> |
5 | 5 |
|
6 | | -<template> |
7 | | - <RecycleScroller |
8 | | - ref="scroller" |
9 | | - item-tag="ul" |
10 | | - :items="participants" |
11 | | - :item-size="PARTICIPANT_ITEM_SIZE" |
12 | | - key-field="attendeeId"> |
13 | | - <template #default="{ item }"> |
14 | | - <ParticipantItem :participant="item" /> |
15 | | - </template> |
16 | | - <template v-if="loading" #after> |
17 | | - <LoadingPlaceholder type="participants" :count="dummyParticipants" /> |
18 | | - </template> |
19 | | - </RecycleScroller> |
20 | | -</template> |
| 6 | +<script setup lang="ts"> |
| 7 | +import type { Participant } from '../../../types/index.ts' |
21 | 8 |
|
22 | | -<script> |
23 | | -import { RecycleScroller } from 'vue-virtual-scroller' |
| 9 | +import { useVirtualList } from '@vueuse/core' |
| 10 | +import { computed, toRef } from 'vue' |
24 | 11 | import LoadingPlaceholder from '../../UIShared/LoadingPlaceholder.vue' |
25 | 12 | import ParticipantItem from './ParticipantItem.vue' |
26 | 13 | import { AVATAR } from '../../../constants.ts' |
27 | 14 |
|
28 | | -import 'vue-virtual-scroller/dist/vue-virtual-scroller.css' |
| 15 | +const props = defineProps<{ |
| 16 | + participants: Participant[] |
| 17 | + loading?: boolean |
| 18 | +}>() |
29 | 19 |
|
30 | 20 | /* Consider: |
31 | 21 | * avatar size (and two lines of text) |
32 | 22 | * list-item padding |
33 | 23 | * list-item__wrapper padding |
34 | 24 | */ |
35 | | -const PARTICIPANT_ITEM_SIZE = AVATAR.SIZE.DEFAULT + 2 * 4 + 2 * 2 |
36 | | -
|
37 | | -export default { |
38 | | - name: 'ParticipantsListVirtual', |
39 | | -
|
40 | | - components: { |
41 | | - LoadingPlaceholder, |
42 | | - ParticipantItem, |
43 | | - RecycleScroller, |
44 | | - }, |
45 | | -
|
46 | | - props: { |
47 | | - participants: { |
48 | | - type: Array, |
49 | | - required: true, |
50 | | - }, |
| 25 | +const itemHeight = AVATAR.SIZE.DEFAULT + 2 * 4 + 2 * 2 |
51 | 26 |
|
52 | | - loading: { |
53 | | - type: Boolean, |
54 | | - default: false, |
55 | | - }, |
56 | | - }, |
| 27 | +const { list, containerProps, wrapperProps } = useVirtualList<Participant>(toRef(() => props.participants), { |
| 28 | + itemHeight, |
| 29 | + overscan: 10, |
| 30 | +}) |
57 | 31 |
|
58 | | - setup() { |
59 | | - return { |
60 | | - PARTICIPANT_ITEM_SIZE, |
61 | | - } |
62 | | - }, |
63 | | -
|
64 | | - computed: { |
65 | | - dummyParticipants() { |
66 | | - const dummies = 6 - this.participants.length |
67 | | - return dummies > 0 ? dummies : 0 |
68 | | - }, |
69 | | - }, |
70 | | -} |
| 32 | +const count = computed(() => props.loading ? Math.max(6 - props.participants.length, 0) : 0) |
71 | 33 | </script> |
| 34 | + |
| 35 | +<template> |
| 36 | + <li |
| 37 | + :ref="containerProps.ref" |
| 38 | + :style="containerProps.style" |
| 39 | + @scroll="containerProps.onScroll"> |
| 40 | + <LoadingPlaceholder v-if="loading" type="participants" :count /> |
| 41 | + <ul |
| 42 | + v-else |
| 43 | + :style="wrapperProps.style"> |
| 44 | + <ParticipantItem |
| 45 | + v-for="item in list" |
| 46 | + :key="item.data.attendeeId" |
| 47 | + :participant="item.data" /> |
| 48 | + </ul> |
| 49 | + </li> |
| 50 | +</template> |
0 commit comments