1
1
<script setup lang="ts">
2
2
import { deCapitalise } from ' @dvcol/common-utils/common/string' ;
3
- import { TraktRatingType , type TraktRatingTypes } from ' @dvcol/trakt-http-client/models' ;
3
+ import {
4
+ TraktRatingType ,
5
+ type TraktRatingTypes ,
6
+ type TraktSyncRatingValue ,
7
+ } from ' @dvcol/trakt-http-client/models' ;
4
8
import { NFlex , NSkeleton } from ' naive-ui' ;
5
9
6
10
import { computed , onMounted , toRefs , watch } from ' vue' ;
@@ -352,7 +356,8 @@ const onCheckin = async (cancel: boolean) => {
352
356
await fetchShowProgress (showId .value , { force: true });
353
357
};
354
358
355
- const { loadRatings, getRatings, getLoading } = useRatingsStore ();
359
+ const { loadRatings, getRatings, getLoading, addRating, removeRating } =
360
+ useRatingsStore ();
356
361
357
362
const ratingLoading = computed (() => {
358
363
if (panelType .value === ' episode' ) {
@@ -361,8 +366,8 @@ const ratingLoading = computed(() => {
361
366
return getEpisodesLoading (showId .value , seasonNb .value , episodeNb .value ).value ;
362
367
}
363
368
if (panelType .value === ' season' ) {
364
- if (! showId ?.value || seasonNb . value === undefined ) return false ;
365
- return getSeasonsLoading (showId .value , seasonNb . value ).value ;
369
+ if (! showId ?.value ) return false ;
370
+ return getSeasonsLoading (showId .value ).value ;
366
371
}
367
372
if (! showId ?.value ) return false ;
368
373
return getShowLoading (showId .value ).value ;
@@ -427,6 +432,61 @@ const ratingUrl = computed(() => {
427
432
});
428
433
});
429
434
435
+ const votes = computed (() => {
436
+ if (panelType .value === ' episode' ) return episode .value ?.votes ;
437
+ if (panelType .value === ' season' ) return season .value ?.votes ;
438
+ return show .value ?.votes ;
439
+ });
440
+
441
+ const rating = computed (() => {
442
+ if (panelType .value === ' episode' ) return episode .value ?.rating ;
443
+ if (panelType .value === ' season' ) return season .value ?.rating ;
444
+ return show .value ?.rating ;
445
+ });
446
+
447
+ const onScoreEdit = async (_score : TraktSyncRatingValue ) => {
448
+ if (! show .value ?.ids ?.trakt ) return ;
449
+ const addOrRemove = _score ? addRating : removeRating ;
450
+ if (panelType .value === ' episode' ) {
451
+ if (! episode .value ?.ids ?.trakt ) return ;
452
+ return addOrRemove (
453
+ TraktRatingType .Episodes ,
454
+ {
455
+ episodes: [
456
+ {
457
+ ids: episode .value .ids ,
458
+ rating: _score ,
459
+ },
460
+ ],
461
+ },
462
+ show .value .ids .trakt ,
463
+ );
464
+ }
465
+ if (panelType .value === ' season' ) {
466
+ if (! season .value ?.ids ?.trakt ) return ;
467
+ return addOrRemove (
468
+ TraktRatingType .Seasons ,
469
+ {
470
+ seasons: [
471
+ {
472
+ ids: season .value .ids ,
473
+ rating: _score ,
474
+ },
475
+ ],
476
+ },
477
+ show .value .ids .trakt ,
478
+ );
479
+ }
480
+ return addOrRemove (TraktRatingType .Shows , {
481
+ shows: [
482
+ {
483
+ ids: show .value .ids ,
484
+ rating: _score ,
485
+ },
486
+ ],
487
+ });
488
+ };
489
+
430
490
onMounted (() => {
431
491
watch (
432
492
[showId , seasonNb , episodeNb ],
@@ -459,18 +519,6 @@ onMounted(() => {
459
519
);
460
520
});
461
521
462
- const votes = computed (() => {
463
- if (panelType .value === ' episode' ) return episode .value ?.votes ;
464
- if (panelType .value === ' season' ) return season .value ?.votes ;
465
- return show .value ?.votes ;
466
- });
467
-
468
- const rating = computed (() => {
469
- if (panelType .value === ' episode' ) return episode .value ?.rating ;
470
- if (panelType .value === ' season' ) return season .value ?.rating ;
471
- return show .value ?.rating ;
472
- });
473
-
474
522
const { openTab } = useLinksStore ();
475
523
</script >
476
524
@@ -499,6 +547,7 @@ const { openTab } = useLinksStore();
499
547
:url =" ratingUrl"
500
548
:loading-score =" scoreLoading"
501
549
:loading-rating =" ratingLoading"
550
+ @on-score-edit =" onScoreEdit"
502
551
>
503
552
<PanelPoster
504
553
:tmdb =" show?.ids.tmdb"
0 commit comments