1
1
<script lang="ts" setup>
2
2
import { computed , type PropType , toRefs } from ' vue' ;
3
3
4
+ import type { SimklIdsExtended } from ' @dvcol/simkl-http-client/models' ;
4
5
import type { TraktApiIds } from ' @dvcol/trakt-http-client/models' ;
5
6
import type { TagLink } from ' ~/models/tag.model' ;
6
7
7
8
import TextField from ' ~/components/common/typography/TextField.vue' ;
8
9
import IconExternalLinkRounded from ' ~/components/icons/IconExternalLinkRounded.vue' ;
9
- import IconIMDb from ' ~/components/icons/IconIMDb.vue' ;
10
- import IconTMDb from ' ~/components/icons/IconTMDb.vue' ;
11
- import IconTVDb from ' ~/components/icons/IconTVDb.vue' ;
12
- import IconTrakt from ' ~/components/icons/IconTrakt.vue' ;
13
10
14
- import { ResolveExternalLinks } from ' ~/settings/external.links' ;
11
+ import {
12
+ DataSource ,
13
+ getIconFromSource ,
14
+ getLabelKeyFromSource ,
15
+ getSortedDataSources ,
16
+ getUrlFromSource ,
17
+ isKnownSource ,
18
+ } from ' ~/models/source.model' ;
15
19
import { resolveLinkUrl , useLinksStore } from ' ~/stores/settings/links.store' ;
16
20
import { useI18n } from ' ~/utils/i18n.utils' ;
17
21
18
22
const props = defineProps ({
19
23
ids: {
20
- type: Object as PropType <Partial <TraktApiIds >>,
24
+ type: Object as PropType <Partial <TraktApiIds & SimklIdsExtended >>,
21
25
required: false ,
22
26
},
23
27
mode: {
@@ -47,15 +51,6 @@ const { ids, mode, season, episode, alias, title } = toRefs(props);
47
51
48
52
const i18n = useI18n (' panel' , ' detail' );
49
53
50
- const labelKey = computed (() => {
51
- const label = [' show' , ' episode' , ' season' ].includes (mode .value )
52
- ? ` open_${mode .value }_in `
53
- : ' open_in' ;
54
- return (source : string ) => {
55
- return i18n ({ key: label , substitutions: [source ] }, ' common' , ' tooltip' );
56
- };
57
- });
58
-
59
54
const { getLinks } = useLinksStore ();
60
55
61
56
const customLinksTemplate = getLinks (mode );
@@ -77,69 +72,20 @@ const customLinks = computed(() => {
77
72
const links = computed (() => {
78
73
if (! ids ?.value ) return ;
79
74
const _links: TagLink [] = [];
80
- if (ids .value .trakt ) {
81
- _links .push ({
82
- label: ' Trakt' ,
83
- title: labelKey .value (' Trakt.tv' ),
84
- url: ResolveExternalLinks .search ({
85
- type: mode .value ,
86
- source: ' trakt' ,
87
- id: ids .value .trakt ,
88
- }),
89
- icon: IconTrakt ,
90
- iconProps: {
91
- style: {
92
- ' --trakt-icon-path' : ' white' ,
93
- ' --trakt-icon-circle' : ' transparent' ,
94
- },
95
- },
96
- });
97
- }
98
- if (ids .value .imdb ) {
99
- _links .push ({
100
- label: ' IMDb' ,
101
- title: labelKey .value (' IMDb.com' ),
102
- url: ResolveExternalLinks .imdb (ids .value .imdb ),
103
- icon: IconIMDb ,
104
- iconProps: {
105
- style: {
106
- ' --imdb-icon-background' : ' white' ,
107
- ' --imdb-icon-height' : ' 575' ,
108
- },
109
- },
110
- });
111
- }
112
- if (ids .value .tmdb ) {
113
- _links .push ({
114
- label: ' TMDb' ,
115
- title: labelKey .value (' TheMovieDb.org' ),
116
- url: ResolveExternalLinks .tmdb ({
117
- id: ids .value .tmdb ,
118
- type: mode .value ,
119
- season: season ?.value ,
120
- episode: episode ?.value ,
121
- }),
122
- icon: IconTMDb ,
123
- iconProps: {
124
- style: {
125
- ' --tmdb-icon-background' : ' white' ,
126
- },
127
- },
128
- });
129
- }
130
- if (ids .value .tvdb ) {
131
- _links .push ({
132
- label: ' TVDb' ,
133
- title: labelKey .value (' TheTVDB.com' ),
134
- url: ResolveExternalLinks .tvdb (ids .value .tvdb , mode .value ),
135
- icon: IconTVDb ,
136
- iconProps: {
137
- style: {
138
- ' --tvdb-icon-background' : ' white' ,
139
- },
140
- },
75
+ getSortedDataSources (ids .value )
76
+ .filter (isKnownSource )
77
+ .forEach (key => {
78
+ _links [key === DataSource .Trakt ? ' unshift' : ' push' ]({
79
+ label: i18n (key , ' common' , ' source' , ' name' ),
80
+ title: getLabelKeyFromSource (i18n , key , mode .value ),
81
+ url: getUrlFromSource (key , ids .value , {
82
+ type: mode .value ,
83
+ season: season ?.value ,
84
+ episode: episode ?.value ,
85
+ }),
86
+ icon: getIconFromSource (key ),
87
+ });
141
88
});
142
- }
143
89
if (customLinks .value ) _links .push (... customLinks .value );
144
90
return _links ;
145
91
});
0 commit comments