@@ -4,7 +4,6 @@ import { defineStore, storeToRefs } from 'pinia';
4
4
import { computed , reactive , ref } from 'vue' ;
5
5
6
6
import { ListScrollItemType } from '~/models/list-scroll.model' ;
7
-
8
7
import { ErrorService } from '~/services/error.service' ;
9
8
import { Logger } from '~/services/logger.service' ;
10
9
import { NotificationService } from '~/services/notification.service' ;
@@ -25,6 +24,22 @@ type CalendarState = {
25
24
extended ?: boolean ;
26
25
} ;
27
26
27
+ export const fetchCalendarData = async ( query : TraktCalendarQuery ) : Promise < CalendarItem [ ] > => {
28
+ const [ shows , movies ] = await Promise . all ( [ TraktService . calendar ( query , 'shows' ) , TraktService . calendar ( query , 'movies' ) ] ) ;
29
+ return [
30
+ ...( shows as TraktCalendarShow [ ] ) . map ( show => ( {
31
+ ...show ,
32
+ id : show . episode . ids . trakt ?? show . show . ids . trakt ,
33
+ date : new Date ( show . first_aired ) ,
34
+ } ) ) ,
35
+ ...( movies as TraktCalendarMovie [ ] ) . map ( movie => ( {
36
+ ...movie ,
37
+ id : movie . movie . ids . trakt ,
38
+ date : new Date ( movie . released ) ,
39
+ } ) ) ,
40
+ ] . sort ( ( a , b ) => a . date . getTime ( ) - b . date . getTime ( ) ) ;
41
+ } ;
42
+
28
43
export const useCalendarStore = defineStore ( CalendarStoreConstants . Store , ( ) => {
29
44
const firstLoad = ref ( true ) ;
30
45
const loading = ref ( true ) ;
@@ -104,21 +119,8 @@ export const useCalendarStore = defineStore(CalendarStoreConstants.Store, () =>
104
119
if ( extended . value ) query . extended = TraktApiExtended . Full ;
105
120
106
121
try {
107
- const [ shows , movies ] = await Promise . all ( [ TraktService . calendar ( query , 'shows' ) , TraktService . calendar ( query , 'movies' ) ] ) ;
122
+ const newData : CalendarItem [ ] = await fetchCalendarData ( query ) ;
108
123
delete calendarErrors [ JSON . stringify ( query ) ] ;
109
- const newData : CalendarItem [ ] = [
110
- ...( shows as TraktCalendarShow [ ] ) . map ( show => ( {
111
- ...show ,
112
- id : show . episode . ids . trakt ?? show . show . ids . trakt ,
113
- date : new Date ( show . first_aired ) ,
114
- } ) ) ,
115
- ...( movies as TraktCalendarMovie [ ] ) . map ( movie => ( {
116
- ...movie ,
117
- id : movie . movie . ids . trakt ,
118
- date : new Date ( movie . released ) ,
119
- } ) ) ,
120
- ] . sort ( ( a , b ) => a . date . getTime ( ) - b . date . getTime ( ) ) ;
121
-
122
124
const spacedData = spaceDate ( newData , startDate , endDate ) ;
123
125
124
126
if ( mode === 'reload' ) {
0 commit comments