1
1
<script setup lang="ts">
2
2
import { NFlex , NSkeleton } from ' naive-ui' ;
3
- import { computed , onMounted , onUnmounted , ref , toRefs , watch } from ' vue' ;
4
-
5
- import type {
6
- TraktEpisodeExtended ,
7
- TraktEpisodeShort ,
8
- } from ' ~/models/trakt/trakt-episode.model' ;
9
- import type { TraktShowExtended } from ' ~/models/trakt/trakt-show.model' ;
3
+ import { computed , onMounted , toRefs , watch } from ' vue' ;
10
4
11
5
import TitleLink from ' ~/components/common/buttons/TitleLink.vue' ;
12
6
import PanelPoster from ' ~/components/views/panel/PanelPoster.vue' ;
@@ -16,7 +10,7 @@ import ShowPanelOverview from '~/components/views/panel/ShowPanelOverview.vue';
16
10
import ShowPanelPicker from ' ~/components/views/panel/ShowPanelPicker.vue' ;
17
11
import { ResolveExternalLinks } from ' ~/settings/external.links' ;
18
12
import { useListsStoreRefs , useListStore } from ' ~/stores/data/list.store' ;
19
- import { type ShowSeasons , useShowStore } from ' ~/stores/data/show.store' ;
13
+ import { useShowStore } from ' ~/stores/data/show.store' ;
20
14
import { useExtensionSettingsStore } from ' ~/stores/settings/extension.store' ;
21
15
import { useI18n } from ' ~/utils' ;
22
16
import { deCapitalise } from ' ~/utils/string.utils' ;
@@ -36,14 +30,17 @@ const props = defineProps({
36
30
},
37
31
});
38
32
39
- const show = ref <TraktShowExtended >();
40
- const seasons = ref <ShowSeasons >();
41
- const episodes = ref <TraktEpisodeShort []>();
42
- const episode = ref <TraktEpisodeExtended >();
43
-
44
33
const { showId, seasonNumber, episodeNumber } = toRefs (props );
45
34
46
35
const {
36
+ getShow,
37
+ fetchShow,
38
+ getShowSeasons,
39
+ fetchShowSeasons,
40
+ getShowSeasonEpisodes,
41
+ fetchShowSeasonEpisodes,
42
+ getShowEpisode,
43
+ fetchShowEpisode,
47
44
getShowWatchedProgress,
48
45
getShowCollectionProgress,
49
46
getShowProgressLoading,
@@ -92,6 +89,31 @@ const panelType = computed<'show' | 'season' | 'episode'>(() => {
92
89
return ' show' ;
93
90
});
94
91
92
+ const show = computed (() => {
93
+ if (! showId ?.value ) return ;
94
+ return getShow (showId .value ).value ;
95
+ });
96
+
97
+ const seasons = computed (() => {
98
+ if (! showId ?.value ) return ;
99
+ return getShowSeasons (showId .value ).value ;
100
+ });
101
+
102
+ const episodes = computed (() => {
103
+ if (! showId ?.value || seasonNb ?.value === undefined ) return ;
104
+ return getShowSeasonEpisodes (showId .value , seasonNb .value ).value ;
105
+ });
106
+
107
+ const episode = computed (() => {
108
+ if (! showId ?.value || seasonNb ?.value === undefined || episodeNb ?.value === undefined )
109
+ return ;
110
+ return getShowEpisode ({
111
+ id: showId .value ,
112
+ season: seasonNb .value ,
113
+ episode: episodeNb .value ,
114
+ }).value ;
115
+ });
116
+
95
117
const season = computed (() => {
96
118
if (seasonNb ?.value === undefined ) return ;
97
119
return seasons .value ?.[seasonNb .value ];
@@ -162,66 +184,25 @@ const titleUrl = computed(() => {
162
184
});
163
185
});
164
186
165
- const subscriptions = new Set <() => void >();
166
-
167
- const { getShowRef, getShowSeasonsRef, getShowSeasonEpisodesRef, getShowEpisodeRef } =
168
- useShowStore ();
169
-
170
- const watchData = () =>
187
+ onMounted (() => {
171
188
watch (
172
189
[showId , seasonNb , episodeNb ],
173
- (next , prev ) => {
174
- // show changes
175
- if (next .at (0 ) !== prev ?.at (0 )) {
176
- show .value = undefined ;
177
- seasons .value = undefined ;
178
- episodes .value = undefined ;
179
- episode .value = undefined ;
180
- }
181
- // season changes
182
- else if (next .at (1 ) !== prev ?.at (1 )) {
183
- episode .value = undefined ;
184
- episodes .value = undefined ;
185
- }
186
- // episode changes
187
- else if (next .at (2 ) !== prev ?.at (2 )) {
188
- episode .value = undefined ;
189
- }
190
+ ([_showId , _seasonNb , _episodeNb ]) => {
191
+ if (_showId !== undefined ) {
192
+ fetchShow (_showId );
193
+ fetchShowSeasons (_showId );
190
194
191
- if (showId ?.value ) {
192
- subscriptions .add (getShowRef (showId .value , show ).unsub );
193
- subscriptions .add (getShowSeasonsRef (showId .value , seasons ).unsub );
194
-
195
- if (seasonNb ?.value !== undefined ) {
196
- subscriptions .add (
197
- getShowSeasonEpisodesRef (showId .value , seasonNb ?.value , episodes ).unsub ,
198
- );
195
+ if (_seasonNb !== undefined ) {
196
+ fetchShowSeasonEpisodes (_showId , _seasonNb );
199
197
}
200
198
201
- if (seasonNb ?.value !== undefined && episodeNb ?.value !== undefined ) {
202
- subscriptions .add (
203
- getShowEpisodeRef (
204
- {
205
- id: showId .value ,
206
- season: seasonNb .value ,
207
- episode: episodeNb .value ,
208
- },
209
- episode ,
210
- ).unsub ,
211
- );
199
+ if (_seasonNb !== undefined && _episodeNb !== undefined ) {
200
+ fetchShowEpisode (_showId , _seasonNb , _episodeNb );
212
201
}
213
202
}
214
203
},
215
204
{ immediate: true },
216
205
);
217
-
218
- onMounted (() => {
219
- subscriptions .add (watchData ());
220
- });
221
-
222
- onUnmounted (() => {
223
- subscriptions .forEach (unsub => unsub ());
224
- subscriptions .clear ();
225
206
});
226
207
227
208
const { openTab } = useExtensionSettingsStore ();
0 commit comments