@@ -8,8 +8,18 @@ import ShowPanelButtons from '~/components/views/panel/ShowPanelButtons.vue';
8
8
import ShowPanelDetails from ' ~/components/views/panel/ShowPanelDetails.vue' ;
9
9
import ShowPanelOverview from ' ~/components/views/panel/ShowPanelOverview.vue' ;
10
10
import ShowPanelPicker from ' ~/components/views/panel/ShowPanelPicker.vue' ;
11
+ import {
12
+ PanelButtonsOption ,
13
+ type PanelButtonsOptions ,
14
+ } from ' ~/components/views/panel/use-panel-buttons' ;
11
15
import { ResolveExternalLinks } from ' ~/settings/external.links' ;
12
- import { useListsStoreRefs , useListStore } from ' ~/stores/data/list.store' ;
16
+ import {
17
+ DefaultLists ,
18
+ type ListEntity ,
19
+ ListType ,
20
+ useListsStoreRefs ,
21
+ useListStore ,
22
+ } from ' ~/stores/data/list.store' ;
13
23
import { useShowStore } from ' ~/stores/data/show.store' ;
14
24
import { useExtensionSettingsStore } from ' ~/stores/settings/extension.store' ;
15
25
import { useI18n } from ' ~/utils' ;
@@ -35,6 +45,8 @@ const { showId, seasonNumber, episodeNumber } = toRefs(props);
35
45
const {
36
46
getShow,
37
47
fetchShow,
48
+ fetchShowProgress,
49
+ fetchShowCollectionProgress,
38
50
getShowSeasons,
39
51
fetchShowSeasons,
40
52
getShowSeasonEpisodes,
@@ -64,11 +76,6 @@ const collectionProgress = computed(() => {
64
76
return getShowCollectionProgress (showId .value ).value ;
65
77
});
66
78
67
- const collectionLoading = computed (() => {
68
- if (! showId ?.value ) return ;
69
- return getShowCollectionLoading (showId .value ).value ;
70
- });
71
-
72
79
const seasonNb = computed (() => {
73
80
if (seasonNumber ?.value === undefined ) return ;
74
81
const _seasonNumber = Number (seasonNumber .value );
@@ -83,12 +90,6 @@ const episodeNb = computed(() => {
83
90
return _episodeNumber ;
84
91
});
85
92
86
- const panelType = computed <' show' | ' season' | ' episode' >(() => {
87
- if (episodeNb ?.value !== undefined && seasonNb ?.value !== undefined ) return ' episode' ;
88
- if (seasonNb ?.value !== undefined ) return ' season' ;
89
- return ' show' ;
90
- });
91
-
92
93
const show = computed (() => {
93
94
if (! showId ?.value ) return ;
94
95
return getShow (showId .value ).value ;
@@ -119,6 +120,18 @@ const season = computed(() => {
119
120
return seasons .value ?.[seasonNb .value ];
120
121
});
121
122
123
+ const panelType = computed <' show' | ' season' | ' episode' >(() => {
124
+ if (episodeNb ?.value !== undefined && seasonNb ?.value !== undefined ) return ' episode' ;
125
+ if (seasonNb ?.value !== undefined ) return ' season' ;
126
+ return ' show' ;
127
+ });
128
+
129
+ const activeItem = computed (() => {
130
+ if (panelType .value === ' episode' ) return episode .value ;
131
+ if (panelType .value === ' season' ) return season .value ;
132
+ return show .value ;
133
+ });
134
+
122
135
const watchedProgressEntity = computed (() => {
123
136
if (! watchedProgress ?.value ) return ;
124
137
@@ -156,17 +169,36 @@ const collectionProgressEntity = computed(() => {
156
169
});
157
170
158
171
const { lists } = useListsStoreRefs ();
159
- const { isListLoading, isItemInList } = useListStore ();
172
+ const { isListTypeLoading, isItemInList, addToOrRemoveFromList, isItemListLoading } =
173
+ useListStore ();
174
+
175
+ const listLoading = computed (
176
+ () =>
177
+ isListTypeLoading (ListType .Watchlist ).value || isListTypeLoading (ListType .List ).value ,
178
+ );
179
+
180
+ const activeItemCollectionLoading = computed (() => {
181
+ const _id = activeItem .value ?.ids ?.trakt ;
182
+ if (_id === undefined ) return ;
183
+ return isItemListLoading ({
184
+ listType: ListType .Collection ,
185
+ itemType: panelType .value ,
186
+ itemId: _id ,
187
+ }).value ;
188
+ });
160
189
161
- const listLoading = computed (() => {
190
+ const collectionLoading = computed (() => {
162
191
if (! showId ?.value ) return ;
163
- return isListLoading (showId .value ).value ;
192
+ if (activeItemCollectionLoading .value ) return true ;
193
+ return getShowCollectionLoading (showId .value ).value ;
164
194
});
165
195
166
196
const activeLists = computed (() => {
167
- if (! showId ?.value ) return ;
197
+ const _id = activeItem ?.value ?.ids ?.trakt ;
198
+ const _type = panelType .value ;
199
+ if (_id === undefined || ! _type ) return ;
168
200
return lists .value
169
- ?.filter (list => isItemInList (list .id , showId . value ).value )
201
+ ?.filter (list => isItemInList (list .id , _type , _id ).value )
170
202
.map (list => list .id );
171
203
});
172
204
@@ -184,6 +216,42 @@ const titleUrl = computed(() => {
184
216
});
185
217
});
186
218
219
+ const onListUpdate = async (value : ListEntity [' id' ], remove : boolean ) => {
220
+ if (! panelType .value || ! activeItem .value ?.ids ) return ;
221
+ const _list = lists .value .find (list => list .id === value );
222
+ if (! _list ) return ;
223
+
224
+ await addToOrRemoveFromList ({
225
+ list: _list ,
226
+ itemType: panelType .value ,
227
+ itemIds: activeItem .value .ids ,
228
+ remove ,
229
+ });
230
+ };
231
+
232
+ const onCollectionUpdate = async (value : PanelButtonsOptions , date ? : number ) => {
233
+ if (! panelType .value || ! activeItem .value ?.ids ) return ;
234
+
235
+ await addToOrRemoveFromList ({
236
+ list: DefaultLists .ShowCollection ,
237
+ itemType: panelType .value ,
238
+ itemIds: activeItem .value .ids ,
239
+ date ,
240
+ remove: value === PanelButtonsOption .Remove ,
241
+ });
242
+ if (! showId .value ) return ;
243
+ await fetchShowCollectionProgress (showId .value , { force: true });
244
+ };
245
+
246
+ const onWatchedUpdate = async (value : PanelButtonsOptions , date ? : number ) => {
247
+ if (! panelType .value || ! activeItem .value ?.ids ) return ;
248
+
249
+ // TODO : implement add/remove from history
250
+ // addToOrRemoveFromList(DefaultLists.Watchlist, `${panelType.value}s`, activeItem.value.ids);
251
+ if (! showId .value ) return ;
252
+ await fetchShowProgress (showId .value , { force: true });
253
+ };
254
+
187
255
onMounted (() => {
188
256
watch (
189
257
[showId , seasonNb , episodeNb ],
@@ -244,6 +312,9 @@ const { openTab } = useExtensionSettingsStore();
244
312
:collection-loading =" collectionLoading"
245
313
:active-loading =" listLoading"
246
314
:active-lists =" activeLists"
315
+ @on-list-update =" onListUpdate"
316
+ @on-collection-update =" onCollectionUpdate"
317
+ @on-watched-update =" onWatchedUpdate"
247
318
/>
248
319
249
320
<ShowPanelPicker
0 commit comments