@@ -12,6 +12,7 @@ import {
12
12
type VirtualListRef ,
13
13
type VirtualListScrollToOptions ,
14
14
} from '~/models/list-scroll.model' ;
15
+ import { defaultDebounceLoadingDelay } from '~/utils/store.utils' ;
15
16
16
17
export type CalendarItem = ( TraktCalendarShow | TraktCalendarMovie | Record < never , never > ) & {
17
18
id : ListScrollItem [ 'id' ] ;
@@ -29,7 +30,7 @@ export const getPlaceholder = (date: Date) => ({ ...CalendarPlaceholder, id: `em
29
30
export const getLoadingPlaceholder = ( date : Date ) =>
30
31
( { ...getPlaceholder ( date ) , id : `loading-${ date . getTime ( ) } ` , type : ListScrollItemType . loading } ) as CalendarItem ;
31
32
32
- export const getEmptyWeeks = ( { startDate, loading = false , days = 14 } : { startDate : Date ; loading ?: boolean ; days ?: number } ) => {
33
+ export const getEmptyWeeks = ( { startDate, loading = false , days = 14 } : { startDate : Date ; loading ?: boolean ; days ?: number } ) : CalendarItem [ ] => {
33
34
return Array ( days )
34
35
. fill ( CalendarPlaceholder )
35
36
. map ( ( _ , index ) => {
@@ -162,10 +163,17 @@ export const useCalendar = ({
162
163
163
164
const onScrollTop = async ( ) => {
164
165
const first = list . value [ 0 ] ;
165
- await fetchData ( 'start' ) ;
166
+ const fetching = fetchData ( 'start' ) ;
166
167
168
+ const timeout = setTimeout ( ( ) => {
169
+ listRef . value ?. list . scrollTo ( { top : 145 } ) ;
170
+ } , defaultDebounceLoadingDelay ) ; // default debounceLoading delay
171
+
172
+ await fetching ;
173
+
174
+ clearTimeout ( timeout ) ;
167
175
listRef . value ?. list . scrollTo ( {
168
- top : ( list . value . findIndex ( item => item . id === first . id ) - 1 ) * 145 ,
176
+ top : list . value . findIndex ( item => item . id === first . id ) * 145 ,
169
177
} ) ;
170
178
} ;
171
179
0 commit comments