Skip to content

Commit 01f7d0f

Browse files
committed
fix(ParticipantsListVirtual): migrate to useVirtualList from vueuse/core
Signed-off-by: Maksim Sukharev <[email protected]>
1 parent c2a5f6b commit 01f7d0f

File tree

1 file changed

+31
-52
lines changed

1 file changed

+31
-52
lines changed

src/components/RightSidebar/Participants/ParticipantsListVirtual.vue

Lines changed: 31 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -3,69 +3,48 @@
33
- SPDX-License-Identifier: AGPL-3.0-or-later
44
-->
55

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'
218
22-
<script>
23-
import { RecycleScroller } from 'vue-virtual-scroller'
9+
import { useVirtualList } from '@vueuse/core'
10+
import { computed, toRef } from 'vue'
2411
import LoadingPlaceholder from '../../UIShared/LoadingPlaceholder.vue'
2512
import ParticipantItem from './ParticipantItem.vue'
2613
import { AVATAR } from '../../../constants.ts'
2714
28-
import 'vue-virtual-scroller/dist/vue-virtual-scroller.css'
15+
const props = defineProps<{
16+
participants: Participant[]
17+
loading?: boolean
18+
}>()
2919
3020
/* Consider:
3121
* avatar size (and two lines of text)
3222
* list-item padding
3323
* list-item__wrapper padding
3424
*/
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
5126
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+
})
5731
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)
7133
</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

Comments
 (0)