|
7 | 7 | type TraktShowExtended,
|
8 | 8 | type TraktSyncRatingValue,
|
9 | 9 | } from '@dvcol/trakt-http-client/models';
|
10 |
| -import { computed, type PropType, toRefs } from 'vue'; |
| 10 | +import { computed, onMounted, type PropType, toRefs, watch } from 'vue'; |
11 | 11 |
|
12 | 12 | import type { RatingItem } from '~/models/rating.model';
|
13 | 13 |
|
@@ -82,27 +82,34 @@ const scoreLoading = computed(() => {
|
82 | 82 | return getLoading(TraktRatingType.Shows);
|
83 | 83 | });
|
84 | 84 |
|
85 |
| -const score = computed(() => { |
86 |
| - if (!showId?.value) return null; |
| 85 | +const scoreIds = computed(() => { |
| 86 | + if (!enableRatings.value) return {}; |
87 | 87 |
|
88 |
| - let id: string; |
89 |
| - let type: TraktRatingTypes; |
| 88 | + let id: string | undefined; |
| 89 | + let type: TraktRatingTypes | undefined; |
90 | 90 |
|
| 91 | + if (!showId.value) return { id, type }; |
91 | 92 | if (mode.value === 'show') {
|
92 | 93 | id = showId.value.toString();
|
93 | 94 | type = TraktRatingType.Shows;
|
94 |
| - } else if (mode.value === 'season') { |
95 |
| - if (!seasonId.value) return null; |
96 |
| - id = `${showId.value}-${seasonId.value}`; |
| 95 | + return { id, type }; |
| 96 | + } |
| 97 | + if (mode.value === 'season') { |
97 | 98 | type = TraktRatingType.Seasons;
|
98 |
| - } else if (mode.value === 'episode') { |
99 |
| - if (!episodeId.value) return null; |
100 |
| - id = `${showId.value}-${episodeId.value}`; |
| 99 | + if (seasonId.value) id = `${showId.value}-${seasonId.value}`; |
| 100 | + return { id, type }; |
| 101 | + } |
| 102 | + if (mode.value === 'episode') { |
101 | 103 | type = TraktRatingType.Episodes;
|
102 |
| - } else { |
103 |
| - return null; |
| 104 | + if (episodeId.value) id = `${showId.value}-${episodeId.value}`; |
| 105 | + return { id, type }; |
104 | 106 | }
|
105 |
| - if (enableRatings.value) loadRatings(type, id); |
| 107 | + return { id, type }; |
| 108 | +}); |
| 109 | +
|
| 110 | +const score = computed(() => { |
| 111 | + const { id, type } = scoreIds.value; |
| 112 | + if (!id || !type) return null; |
106 | 113 | return getRatings(type, id);
|
107 | 114 | });
|
108 | 115 |
|
@@ -242,6 +249,13 @@ const onScoreEdit = async (_score: TraktSyncRatingValue) => {
|
242 | 249 | ],
|
243 | 250 | });
|
244 | 251 | };
|
| 252 | +
|
| 253 | +onMounted(() => { |
| 254 | + watch(scoreIds, ({ id, type }) => { |
| 255 | + if (!id || !type) return; |
| 256 | + loadRatings(type, id); |
| 257 | + }); |
| 258 | +}); |
245 | 259 | </script>
|
246 | 260 |
|
247 | 261 | <template>
|
|
0 commit comments