fix: Series cards and posters not linking to correct pages

This commit is contained in:
Aleksi Lassila
2023-08-31 17:16:47 +03:00
parent 8a056a3045
commit 3234019dcb
4 changed files with 34 additions and 19 deletions

View File

@@ -66,7 +66,7 @@ export const getJellyfinItems = async () =>
}
}
})
.then((r) => r.data?.Items || []);
.then((r) => r.data?.Items || []) || Promise.resolve([]);
// export const getJellyfinSeries = () =>
// JellyfinApi.get('/Users/{userId}/Items', {

View File

@@ -1,7 +1,6 @@
import { browser } from '$app/environment';
import { TMDB_API_KEY } from '$lib/constants';
import { settings } from '$lib/stores/settings.store';
import { formatDateToYearMonthDay } from '$lib/utils';
import createClient from 'openapi-fetch';
import { get } from 'svelte/store';
import type { operations, paths } from './tmdb.generated';

View File

@@ -9,6 +9,8 @@
import CarouselPlaceholderItems from '$lib/components/Carousel/CarouselPlaceholderItems.svelte';
import EpisodeCard from '$lib/components/EpisodeCard/EpisodeCard.svelte';
import TitleShowcase from '$lib/components/TitleShowcase/TitleShowcase.svelte';
import { jellyfinItemsStore } from '$lib/stores/data.store';
import { log } from '$lib/utils';
let continueWatchingVisible = true;
@@ -21,11 +23,16 @@
let nextUpProps = Promise.all([nextUpP, continueWatchingP])
.then(([nextUp, continueWatching]) => [...(continueWatching || []), ...(nextUp || [])])
.then(log)
.then((items) =>
items?.map(
(item) =>
({
tmdbId: Number(item.ProviderIds?.Tmdb) || 0,
Promise.all(
items?.map(async (item) => {
const parentSeries = await jellyfinItemsStore.promise.then((items) =>
items.find((i) => i.Id === item.SeriesId)
);
return {
tmdbId: Number(item.ProviderIds?.Tmdb) || Number(parentSeries?.ProviderIds?.Tmdb) || 0,
jellyfinId: item.Id,
backdropUrl: getJellyfinBackdrop(item),
title: item.Name || '',
@@ -43,7 +50,8 @@
item.Genres?.join(', ') ||
''
})
} as const)
} as const;
})
)
);
@@ -103,13 +111,6 @@
on:click={() => (window.location.href = `/${prop.type}/${prop.tmdbId}`)}
{...prop}
/>
<!-- <Poster {...prop}>
<div slot="bottom-left" class="text-sm font-medium text-zinc-300">
{#if prop.progress}
{(prop.runtime - (prop.runtime / 100) * prop.progress).toFixed()} Minutes Left
{/if}
</div>
</Poster> -->
{/each}
{/await}
</Carousel>

View File

@@ -12,6 +12,7 @@
import { genres, networks } from '$lib/discover';
import { jellyfinItemsStore } from '$lib/stores/data.store';
import { settings } from '$lib/stores/settings.store';
import type { TitleType } from '$lib/types';
import { formatDateToYearMonthDay } from '$lib/utils';
import type { ComponentProps } from 'svelte';
import { _ } from 'svelte-i18n';
@@ -25,7 +26,15 @@
});
const fetchCardProps = async (
items: { name?: string; title?: string; id?: number; vote_average?: number }[]
items: {
name?: string;
title?: string;
id?: number;
vote_average?: number;
number_of_seasons?: number;
first_air_date?: string;
}[],
type: TitleType | undefined = undefined
): Promise<ComponentProps<Poster>[]> => {
const filtered = $settings.discover.excludeLibraryItems
? items.filter(
@@ -37,13 +46,19 @@
return Promise.all(
filtered.map(async (item) => {
const backdropUri = await getTmdbMovieBackdrop(item.id || 0);
const t =
type ||
(item?.number_of_seasons === undefined && item?.first_air_date === undefined
? 'movie'
: 'series');
return {
tmdbId: item.id || 0,
title: item.title || item.name || '',
// subtitle: item.subtitle || '',
rating: item.vote_average || undefined,
size: 'md',
backdropUrl: backdropUri ? TMDB_BACKDROP_SMALL + backdropUri : ''
backdropUrl: backdropUri ? TMDB_BACKDROP_SMALL + backdropUri : '',
type: t
} as const;
})
).then((props) => props.filter((p) => p.backdropUrl));
@@ -110,7 +125,7 @@
}
})
.then((res) => res.data?.results || [])
.then(fetchCardProps);
.then((i) => fetchCardProps(i, 'series'));
const fetchDigitalReleases = () =>
TmdbApiOpen.get('/3/discover/movie', {
@@ -141,7 +156,7 @@
}
})
.then((res) => res.data?.results || [])
.then(fetchCardProps);
.then((i) => fetchCardProps(i, 'series'));
function parseIncludedLanguages(includedLanguages: string) {
return includedLanguages.replace(' ', '').split(',').join('|');
@@ -166,7 +181,7 @@
<CarouselPlaceholderItems size="lg" />
{:then props}
{#each props as prop (prop.tmdbId)}
<Poster size="lg" {...prop} />
<Poster {...prop} size="lg" />
{/each}
{/await}
</Carousel>