@@ -12,6 +12,7 @@ import { ErrorService } from '~/services/error.service';
12
12
import { Logger } from '~/services/logger.service' ;
13
13
import { NotificationService } from '~/services/notification.service' ;
14
14
import { TraktService } from '~/services/trakt.service' ;
15
+ import { useAuthSettingsStoreRefs } from '~/stores/settings/auth.store' ;
15
16
import { storage } from '~/utils/browser/browser-storage.utils' ;
16
17
import { debounceLoading , useBelowThreshold , useLoadingPlaceholder , useSearchFilter } from '~/utils/store.utils' ;
17
18
import { clearProxy } from '~/utils/vue.utils' ;
@@ -29,9 +30,10 @@ const HistoryStoreConstants = {
29
30
30
31
type HistoryState = {
31
32
pageSize : number ;
33
+ extended : boolean ;
34
+ init : boolean ;
32
35
historyStart ?: Date | number ;
33
36
historyEnd ?: Date | number ;
34
- extended ?: boolean ;
35
37
} ;
36
38
37
39
export const useHistoryStore = defineStore ( HistoryStoreConstants . Store , ( ) => {
@@ -42,6 +44,7 @@ export const useHistoryStore = defineStore(HistoryStoreConstants.Store, () => {
42
44
const historyDictionary = reactive < HistoryDictionary > ( { } ) ;
43
45
const pagination = ref < TraktClientPagination > ( ) ;
44
46
const extended = ref ( false ) ;
47
+ const init = ref ( false ) ;
45
48
46
49
const searchHistory = ref ( '' ) ;
47
50
@@ -59,6 +62,7 @@ export const useHistoryStore = defineStore(HistoryStoreConstants.Store, () => {
59
62
historyStart : historyStart . value ?. getTime ( ) ,
60
63
historyEnd : historyEnd . value ?. getTime ( ) ,
61
64
extended : extended . value ,
65
+ init : init . value ,
62
66
} ) ;
63
67
64
68
const restoreState = async ( ) => {
@@ -68,6 +72,7 @@ export const useHistoryStore = defineStore(HistoryStoreConstants.Store, () => {
68
72
if ( restored ?. historyStart ) historyStart . value = new Date ( restored . historyStart ) ;
69
73
if ( restored ?. historyEnd ) historyEnd . value = new Date ( restored . historyEnd ) ;
70
74
if ( restored ?. extended ) extended . value = restored . extended ;
75
+ if ( restored ?. init ) init . value = restored . init ;
71
76
} ;
72
77
73
78
const clearState = ( ) => {
@@ -133,6 +138,7 @@ export const useHistoryStore = defineStore(HistoryStoreConstants.Store, () => {
133
138
const getMovieHistory = ( id : number ) => getHistory ( id , 'movie' ) ;
134
139
const getEpisodeHistory = ( id : number ) => getHistory ( id , 'episode' ) ;
135
140
141
+ const { isAuthenticated } = useAuthSettingsStoreRefs ( ) ;
136
142
const initHistoryStore = async ( ) => {
137
143
await restoreState ( ) ;
138
144
@@ -154,6 +160,10 @@ export const useHistoryStore = defineStore(HistoryStoreConstants.Store, () => {
154
160
}
155
161
} ) ;
156
162
} ) ;
163
+
164
+ if ( ! init . value ) return ;
165
+ if ( ! isAuthenticated . value ) return ;
166
+ await fetchHistory ( ) ;
157
167
} ;
158
168
159
169
return {
@@ -182,6 +192,14 @@ export const useHistoryStore = defineStore(HistoryStoreConstants.Store, () => {
182
192
saveState ( ) . catch ( e => Logger . error ( 'Failed to save history extended state' , e ) ) ;
183
193
} ,
184
194
} ) ,
195
+ init : computed ( {
196
+ get : ( ) => init . value ,
197
+ set : ( value : boolean ) => {
198
+ init . value = value ;
199
+ saveState ( ) . catch ( e => Logger . error ( 'Failed to save history init state' , e ) ) ;
200
+ if ( value ) return fetchHistory ( ) ;
201
+ } ,
202
+ } ) ,
185
203
} ;
186
204
} ) ;
187
205
0 commit comments