Skip to content

Commit fd8e3e3

Browse files
committed
feat(rating): adds url to external ratings
1 parent 58aeddb commit fd8e3e3

File tree

8 files changed

+99
-43
lines changed

8 files changed

+99
-43
lines changed

src/components/common/buttons/ButtonLinkExternal.vue

+13-2
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,11 @@ defineProps({
2626
required: false,
2727
default: IconExternalLinkRounded,
2828
},
29+
disabled: {
30+
type: Boolean,
31+
required: false,
32+
default: false,
33+
},
2934
});
3035
3136
const anchor = ref();
@@ -34,7 +39,7 @@ const anchor = ref();
3439
<template>
3540
<NTooltip
3641
class="button-link-external-tooltip"
37-
:disabled="!label"
42+
:disabled="disabled || !label || !href"
3843
:show-arrow="false"
3944
placement="bottom"
4045
:delay="300"
@@ -46,8 +51,10 @@ const anchor = ref();
4651
<a ref="anchor" class="anchor-link" :href="href" :title="title" tabindex="-1">
4752
<NButton
4853
tertiary
54+
:disabled="disabled"
55+
:focusable="!!href?.length"
4956
class="external-link"
50-
:class="{ slotted: $slots.default }"
57+
:class="{ slotted: $slots.default, 'no-link': !href?.length }"
5158
v-bind="$attrs"
5259
>
5360
<slot />
@@ -68,6 +75,10 @@ const anchor = ref();
6875
color: inherit;
6976
text-decoration: none;
7077
78+
.no-link {
79+
cursor: default;
80+
}
81+
7182
.external-link {
7283
height: unset;
7384
min-height: var(--n-height);

src/components/common/list/use-list-scroll.ts

-1
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,6 @@ export const useBufferedListScroll = <T extends ListScrollSourceItemWithDate<D>,
252252
return {
253253
paused,
254254
list: computed<ListScrollItem[]>(() => {
255-
console.info('paused', paused.value, { previous, list: list.value });
256255
if (paused.value) return previous;
257256
return list.value;
258257
}),

src/components/views/panel/PanelMovieStatistics.vue

+2-1
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,12 @@ import { computed, onMounted, type PropType, toRefs, watch } from 'vue';
1010
import type { RatingItem } from '~/models/rating.model';
1111
1212
import PanelStatistics from '~/components/views/panel/PanelStatistics.vue';
13+
import { DataSource, getUrlFromSource } from '~/models/source.model';
1314
import { ResolveExternalLinks } from '~/settings/external.links';
1415
import { useRatingsStore } from '~/stores/data/ratings.store';
1516
import { useSimklStore } from '~/stores/data/simkl.store';
1617
import { useExtensionSettingsStoreRefs } from '~/stores/settings/extension.store';
1718
import { useI18n } from '~/utils/i18n.utils';
18-
import { DataSource } from '~/utils/icon.utils';
1919
2020
const i18n = useI18n('panel', 'statistics');
2121
@@ -85,6 +85,7 @@ const ratings = computed<RatingItem[]>(() => {
8585
votes: value.votes,
8686
rating: value.rating,
8787
loading: simklMovieLoading.value,
88+
url: getUrlFromSource(key, simklMovie?.value?.ids, { type: 'movie' }),
8889
},
8990
});
9091
});

src/components/views/panel/PanelRatings.vue

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import type { DropdownOption } from 'naive-ui';
77
import type { RatingItem } from '~/models/rating.model';
88
99
import PanelRating from '~/components/views/panel/PanelRating.vue';
10-
import { getIconFromSource } from '~/utils/icon.utils';
10+
import { getIconFromSource } from '~/models/source.model';
1111
1212
const props = defineProps({
1313
ratings: {

src/components/views/panel/PanelShowStatistics.vue

+3-1
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,14 @@ import { computed, type PropType, toRefs } from 'vue';
1212
import type { RatingItem } from '~/models/rating.model';
1313
1414
import PanelStatistics from '~/components/views/panel/PanelStatistics.vue';
15+
import { DataSource } from '~/models/source.model';
1516
import { ResolveExternalLinks } from '~/settings/external.links';
1617
import { useRatingsStore } from '~/stores/data/ratings.store';
1718
1819
import { useShowStore } from '~/stores/data/show.store';
1920
import { useSimklStore } from '~/stores/data/simkl.store';
2021
import { useExtensionSettingsStoreRefs } from '~/stores/settings/extension.store';
2122
import { useI18n } from '~/utils/i18n.utils';
22-
import { DataSource } from '~/utils/icon.utils';
2323
2424
const i18n = useI18n('panel', 'statistics');
2525
@@ -178,6 +178,8 @@ const ratings = computed<RatingItem[]>(() => {
178178
votes: value.votes,
179179
rating: value.rating,
180180
loading: simklShowLoading.value,
181+
url:
182+
key === 'mal' ? `https://myanimelist.net/anime/${simklShow.value}` : undefined,
181183
},
182184
});
183185
});

src/models/source.model.ts

+71
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
import type { Component } from 'vue';
2+
3+
import IconIMDb from '~/components/icons/IconIMDb.vue';
4+
import IconMyAnimeList from '~/components/icons/IconMyAnimeList.vue';
5+
import IconSimkl from '~/components/icons/IconSimkl.vue';
6+
import IconStarFilledHalf from '~/components/icons/IconStarFilledHalf.vue';
7+
import IconTMDb from '~/components/icons/IconTMDb.vue';
8+
import IconTVDb from '~/components/icons/IconTVDb.vue';
9+
import IconTrakt from '~/components/icons/IconTrakt.vue';
10+
import { ResolveExternalLinks } from '~/settings/external.links';
11+
12+
export const DataSource = {
13+
Trakt: 'trakt',
14+
Tmdb: 'tmdb',
15+
Imdb: 'imdb',
16+
Tvdb: 'tvdb',
17+
Simkl: 'simkl',
18+
Mal: 'mal',
19+
} as const;
20+
21+
export type DataSources = (typeof DataSource)[keyof typeof DataSource];
22+
23+
export const getIconFromSource = (source: DataSources | string): Component => {
24+
switch (source) {
25+
case DataSource.Trakt:
26+
return IconTrakt;
27+
case DataSource.Tmdb:
28+
return IconTMDb;
29+
case DataSource.Imdb:
30+
return IconIMDb;
31+
case DataSource.Tvdb:
32+
return IconTVDb;
33+
case DataSource.Simkl:
34+
return IconSimkl;
35+
case DataSource.Mal:
36+
return IconMyAnimeList;
37+
default:
38+
return IconStarFilledHalf;
39+
}
40+
};
41+
42+
export const getUrlFromSource = (
43+
source: DataSources | string,
44+
ids?: Record<DataSources | string, number | string>,
45+
metadata: {
46+
season?: string | number;
47+
episode?: string | number;
48+
type?: 'movie' | 'show' | 'season' | 'episode' | 'person' | 'anime';
49+
} = {},
50+
): string | undefined => {
51+
if (!ids) return undefined;
52+
switch (source) {
53+
case DataSource.Mal:
54+
if (!ids[source]) return undefined;
55+
return ResolveExternalLinks.mal(ids[source]);
56+
case DataSource.Tmdb:
57+
if (!metadata.type || !ids[source]) return undefined;
58+
return ResolveExternalLinks.tmdb({ id: ids[source], type: metadata.type, ...metadata });
59+
case DataSource.Tvdb:
60+
if (!metadata.type || !ids[source]) return undefined;
61+
return ResolveExternalLinks.tvdb(ids[source], metadata.type);
62+
case DataSource.Imdb:
63+
if (!ids[source]) return undefined;
64+
return ResolveExternalLinks.imdb(ids[source]);
65+
case DataSource.Simkl:
66+
if (!metadata.type || !ids[source]) return undefined;
67+
return ResolveExternalLinks.simkl.item(ids[source], metadata.type);
68+
default:
69+
return undefined;
70+
}
71+
};

src/settings/external.links.ts

+9-2
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ export const ExternaLinks = {
99
imdb: 'https://www.imdb.com/',
1010
tvdb: 'https://thetvdb.com/',
1111
simkl: 'https://simkl.com/',
12+
mal: 'https://myanimelist.net/',
1213
omdb: 'https://www.omdbapi.com/',
1314
fanart: 'https://fanart.tv/',
1415
justwatch: 'https://www.justwatch.com/',
@@ -93,26 +94,32 @@ export const ResolveExternalLinks = {
9394
id: string | number;
9495
season?: string | number;
9596
episode?: string | number;
96-
type: 'movie' | 'show' | 'season' | 'episode' | 'person';
97+
type: 'movie' | 'show' | 'season' | 'episode' | 'person' | string;
9798
}) => {
9899
if (type === 'person') return `${ExternaLinks.tmdb}person/${id}`;
99100
if (type === 'movie') return `${ExternaLinks.tmdb}movie/${id}`;
100101
if (type === 'show') return `${ExternaLinks.tmdb}tv/${id}`;
101102
if (type === 'season') return `${ExternaLinks.tmdb}tv/${id}/season/${season}`;
102103
if (type === 'episode') return `${ExternaLinks.tmdb}tv/${id}/season/${season}/episode/${episode}`;
103104
},
104-
tvdb: (id: string | number, type: 'movie' | 'show' | 'season' | 'episode' | 'person') => {
105+
tvdb: (id: string | number, type: 'movie' | 'show' | 'season' | 'episode' | 'person' | string) => {
105106
if (type === 'person') return `${ExternaLinks.tvdb}dereferrer/people/${id}`;
106107
if (type === 'movie') return `${ExternaLinks.tvdb}dereferrer/movies/${id}`;
107108
if (type === 'show') return `${ExternaLinks.tvdb}dereferrer/series/${id}`;
108109
if (type === 'season') return `${ExternaLinks.tvdb}dereferrer/season/${id}`;
109110
if (type === 'episode') return `${ExternaLinks.tvdb}dereferrer/episode/${id}`;
110111
},
112+
mal: (id: number | string) => `${ExternaLinks.mal}anime/${id}`,
111113
facebook: (id: string) => `${ExternaLinks.facebook}${id}`,
112114
twitter: (id: string) => `${ExternaLinks.twitter}${id}`,
113115
instagram: (id: string) => `${ExternaLinks.instagram}${id}`,
114116
wikipedia: (id: string) => `${ExternaLinks.wikipedia}wiki/${id}`,
115117
simkl: {
116118
settings: `${ExternaLinks.simkl}/settings/`,
119+
item: (id: string | number, type: 'movie' | 'show' | 'anime' | string) => {
120+
if (type === 'movie') return `${ExternaLinks.simkl}movies/${id}`;
121+
if (type === 'show') return `${ExternaLinks.simkl}tv/${id}`;
122+
if (type === 'anime') return `${ExternaLinks.simkl}anime/${id}`;
123+
},
117124
},
118125
};

src/utils/icon.utils.ts

-35
This file was deleted.

0 commit comments

Comments
 (0)