@@ -15,7 +15,7 @@ import type { TraktClientPagination } from '~/models/trakt/trakt-client.model';
15
15
import ListEmpty from ' ~/components/common/list/ListEmpty.vue' ;
16
16
import ListItem from ' ~/components/common/list/ListItem.vue' ;
17
17
18
- const virtualList = ref <VirtualListRef >();
18
+ const listRef = ref <VirtualListRef >();
19
19
20
20
const props = defineProps ({
21
21
items: {
@@ -42,29 +42,48 @@ const props = defineProps({
42
42
type: Boolean ,
43
43
required: false ,
44
44
},
45
+ scrollThreshold: {
46
+ type: Number ,
47
+ required: false ,
48
+ default: 0 ,
49
+ },
45
50
});
46
51
47
52
const emits = defineEmits <{
48
53
(e : ' onScrollBottom' , listRef : Ref <VirtualListRef | undefined >): void ;
49
54
(e : ' onScrollTop' , listRef : Ref <VirtualListRef | undefined >): void ;
55
+ (e : ' onScroll' , listRef : Ref <VirtualListRef | undefined >): void ;
50
56
(e : ' onUpdated' , listRef : Ref <VirtualListRef | undefined >): void ;
51
57
}>();
52
58
53
- const { items, loading, pagination } = toRefs (props );
59
+ defineExpose ({
60
+ list: listRef ,
61
+ });
62
+
63
+ const { items, loading, pagination, scrollThreshold } = toRefs (props );
64
+
65
+ const scrolled = ref (false );
54
66
55
67
const onScrollHandler = async (e : Event ) => {
56
68
if (loading .value ) return ;
57
69
if (! e ?.target ) return ;
58
70
const { scrollTop, scrollHeight, clientHeight } = e .target as HTMLElement ;
59
71
if (scrollHeight === clientHeight ) return ;
60
- if (! scrollTop ) return emits (' onScrollTop' , virtualList );
72
+ if (! scrollTop ) {
73
+ scrolled .value = false ;
74
+ return emits (' onScrollTop' , listRef );
75
+ }
76
+ if (! scrolled .value && scrollTop > scrollThreshold .value ) {
77
+ emits (' onScroll' , listRef );
78
+ scrolled .value = true ;
79
+ }
61
80
if (scrollHeight !== scrollTop + clientHeight ) return ;
62
81
if (pagination ?.value ?.page === pagination ?.value ?.pageCount ) return ;
63
- return emits (' onScrollBottom' , virtualList );
82
+ return emits (' onScrollBottom' , listRef );
64
83
};
65
84
66
85
const onUpdatedHandler = () => {
67
- return emits (' onUpdated' , virtualList );
86
+ return emits (' onUpdated' , listRef );
68
87
};
69
88
70
89
const hoverDate = ref <string >();
@@ -77,7 +96,7 @@ const onHover = ({ item, hover }: { item: ListScrollItem; hover: boolean }) => {
77
96
<Transition name =" fade" mode =" out-in" >
78
97
<NVirtualList
79
98
v-if =" items.length || loading"
80
- ref =" virtualList "
99
+ ref =" listRef "
81
100
class =" list-scroll"
82
101
:data-length =" items.length"
83
102
:data-page-size =" pageSize"
@@ -89,7 +108,7 @@ const onHover = ({ item, hover }: { item: ListScrollItem; hover: boolean }) => {
89
108
...listOptions?.visibleItemsProps,
90
109
}"
91
110
:padding-top =" listOptions?.paddingTop ?? 60"
92
- :padding-bottom =" listOptions?.paddingBottom ?? 16 "
111
+ :padding-bottom =" listOptions?.paddingBottom ?? 32 "
93
112
@scroll =" onScrollHandler"
94
113
@vue:updated =" onUpdatedHandler"
95
114
>
0 commit comments