Skip to content

Commit ba0c3f6

Browse files
committed
feat(tags): adds open link on click
1 parent 425a9ed commit ba0c3f6

File tree

4 files changed

+66
-5
lines changed

4 files changed

+66
-5
lines changed

src/components/common/list/ListItemPanel.vue

+22-2
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import { type ListScrollItem } from '~/models/list-scroll.model';
1616
1717
import { useShowStore } from '~/stores/data/show.store';
1818
import { useI18n } from '~/utils';
19+
import { createTab } from '~/utils/browser/browser.utils';
1920
import { deCapitalise } from '~/utils/string.utils';
2021
2122
const i18n = useI18n('list', 'item', 'panel');
@@ -89,6 +90,11 @@ const tooltipOptions = computed<PopoverProps>(() => ({
8990
showArrow: false,
9091
delay: 500,
9192
}));
93+
94+
const onTagClick = (url?: string) => {
95+
if (!url) return;
96+
createTab({ url });
97+
};
9298
</script>
9399

94100
<template>
@@ -122,10 +128,12 @@ const tooltipOptions = computed<PopoverProps>(() => ({
122128
<NTag
123129
v-else
124130
class="tag"
125-
:class="{ meta: tag.meta }"
131+
:class="{ meta: tag.meta, link: !!tag.url }"
126132
size="small"
127-
:type="tag.type"
128133
:bordered="tag.bordered ?? false"
134+
:href="tag.url"
135+
v-bind="tag"
136+
@click="onTagClick(tag.url)"
129137
>
130138
{{ tag.label }}
131139
</NTag>
@@ -217,6 +225,18 @@ const tooltipOptions = computed<PopoverProps>(() => ({
217225
.tag {
218226
width: fit-content;
219227
}
228+
229+
.link {
230+
cursor: pointer;
231+
232+
&:hover {
233+
background-color: color-mix(
234+
in srgb,
235+
var(--n-close-icon-color-hover),
236+
transparent 90%
237+
);
238+
}
239+
}
220240
}
221241
222242
.panel-progress {

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

+11
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import type { TraktClientPagination } from '~/models/trakt/trakt-client.model';
77
import type { ImageQuery } from '~/stores/data/image.store';
88

99
import { type ListScrollItem, ListScrollItemType, type ListScrollSourceItem, type OnScroll, type OnUpdated } from '~/models/list-scroll.model';
10+
import { ResolveExternalLinks } from '~/settings/external.links';
1011
import { useI18n } from '~/utils';
1112

1213
export type ListScrollSourceItemWithDate<T extends string> = ListScrollSourceItem & Partial<Record<T, string | number | Date>>;
@@ -89,6 +90,11 @@ export const getTags = (item: Pick<ListScrollSourceItem, 'episode' | 'season'>,
8990
.padStart(2, '0')}`,
9091
type: 'warning',
9192
bordered: true,
93+
url: ResolveExternalLinks.search({
94+
type: 'episode',
95+
source: 'trakt',
96+
id: item.episode.ids.trakt,
97+
}),
9298
});
9399

94100
let premiere: 'season' | 'series' | 'mid_season' | null = null;
@@ -108,6 +114,11 @@ export const getTags = (item: Pick<ListScrollSourceItem, 'episode' | 'season'>,
108114
tags.push({
109115
label: `Season ${item.season.number.toString().padStart(2, '0')}`,
110116
type: 'warning',
117+
url: ResolveExternalLinks.search({
118+
type: 'season',
119+
source: 'trakt',
120+
id: item.season.ids.trakt,
121+
}),
111122
});
112123
}
113124

src/models/list-scroll.model.ts

+2-3
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,9 @@ export type ListScrollSourceItem = {
3838
export type ListScrollItemTag = {
3939
label: string;
4040
i18n?: boolean | string[];
41-
type?: TagProps['type'];
42-
bordered?: boolean;
4341
meta?: string;
44-
};
42+
url?: string;
43+
} & TagProps;
4544

4645
export type ListScrollItemProgressEpisode = BaseTraktProgressEpisode & {
4746
date: Date;

src/settings/external.links.ts

+31
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,34 @@ export const ExternaLinks = {
1919
reddit: 'https://www.reddit.com/',
2020
discord: 'https://discord.com/',
2121
} as const;
22+
23+
export const ResolveExternalLinks = {
24+
trakt: ({
25+
type,
26+
slug,
27+
season,
28+
episode,
29+
base = ExternaLinks.trakt.production,
30+
}: {
31+
type: 'movies' | 'shows' | 'season' | 'episode' | 'person' | 'comment' | 'list';
32+
slug: string;
33+
season?: number;
34+
episode?: number;
35+
base?: string;
36+
}) => {
37+
if (type === 'episode') return `${base}shows/${slug}/seasons/${season}/episodes/${episode}`;
38+
if (type === 'season') return `${base}shows/${slug}/seasons/${season}`;
39+
return `${base}${type}/${slug}`;
40+
},
41+
search: ({
42+
id,
43+
type,
44+
source,
45+
base = ExternaLinks.trakt.production,
46+
}: {
47+
id: string | number;
48+
type?: 'movie' | 'show' | 'season' | 'episode' | 'person';
49+
source: 'trakt' | 'imdb' | 'tmdb' | 'tvdb';
50+
base?: string;
51+
}) => `${base}search/${source}/${id}${type ? `?id_type=${type}` : ''}`,
52+
};

0 commit comments

Comments
 (0)