diff --git a/src/lib/components/CardGrid.svelte b/src/lib/components/CardGrid.svelte index e8b34c7..a73d724 100644 --- a/src/lib/components/CardGrid.svelte +++ b/src/lib/components/CardGrid.svelte @@ -4,46 +4,49 @@ import classNames from 'classnames'; import { getCardDimensions } from '../utils'; - export let direction: 'horizontal' | 'vertical' = 'vertical'; + // export let direction: 'horizontal' | 'vertical' = 'vertical'; + export let type: 'portrait' | 'landscape' = 'portrait'; - let cols = getCardDimensions(window.innerWidth).columns; + let cols = getCardDimensions(window.innerWidth, type).columns; $: console.log('cols', cols); // let cols: number = 1; - const calculateRows = () => { - const width = window.innerWidth; - if (direction === 'vertical') { - if (width >= 1536) { - cols = 6; - } else if (width >= 1280) { - cols = 5; - } else if (width >= 768) { - cols = 4; - } else { - cols = 3; - } - } else { - // if (width >= 1920) { - // cols = 4; - // } else - if (width >= 1536) { - cols = 3; - } else if (width >= 1280) { - cols = 2; - } else if (width >= 768) { - cols = 1; - } else { - cols = 1; - } - } - }; + // const calculateRows = () => { + // const width = window.innerWidth; + // if (direction === 'vertical') { + // if (width >= 1536) { + // cols = 6; + // } else if (width >= 1280) { + // cols = 5; + // } else if (width >= 768) { + // cols = 4; + // } else { + // cols = 3; + // } + // } else { + // // if (width >= 1920) { + // // cols = 4; + // // } else + // if (width >= 1536) { + // cols = 3; + // } else if (width >= 1280) { + // cols = 2; + // } else if (width >= 768) { + // cols = 1; + // } else { + // cols = 1; + // } + // } + // }; // onMount(() => { // calculateRows(); // }); - (cols = getCardDimensions(e.currentTarget.innerWidth).columns)} /> + (cols = getCardDimensions(e.currentTarget.innerWidth, type).columns)} +/> ; - let dimensions = getDimensions(window.innerWidth); - - function getDimensions(viewportWidth: number) { - const minWidth = 240; - - const margin = 128; - const gap = 32; - - const cols = Math.floor((gap - 2 * margin + viewportWidth) / (minWidth + gap)); - const scale = -(gap * (cols - 1) + 2 * margin - viewportWidth) / (cols * minWidth); - - const newWidth = minWidth * scale; - const newHeight = (3 / 2) * newWidth; - - return { - width: newWidth, - height: newHeight - }; - } + let dimensions = getCardDimensions(window.innerWidth, 'landscape'); - (dimensions = getDimensions(e.currentTarget.innerWidth))} /> + (dimensions = getCardDimensions(e.currentTarget.innerWidth, 'landscape'))} +/> {/each} - + {#if $tmdbSeasons?.[seasonIndex]?.episodes?.length} {#each $tmdbSeasons?.[seasonIndex]?.episodes || [] as episode} {@const jellyfinEpisode = awaitedJellyfinEpisodes?.find( diff --git a/src/lib/components/SeriesPage/ManageSeasonCard.svelte b/src/lib/components/SeriesPage/ManageSeasonCard.svelte index 835afd6..4e1f115 100644 --- a/src/lib/components/SeriesPage/ManageSeasonCard.svelte +++ b/src/lib/components/SeriesPage/ManageSeasonCard.svelte @@ -4,19 +4,25 @@ import AnimateScale from '../AnimateScale.svelte'; import classNames from 'classnames'; import { Plus, PlusCircled } from 'radix-icons-svelte'; + import { getCardDimensions } from '../../utils'; export let backdropUrl: string; let hasFocus: Readable; + + let dimensions = getCardDimensions(window.innerWidth, 'landscape'); + (dimensions = getCardDimensions(e.currentTarget.innerWidth, 'landscape'))} +/> []> = sonarrApi.getDownloads().then((items) => - items - .filter( - (value, index, self) => index === self.findIndex((t) => t.seriesId === value.seriesId) + const sonarrDownloads: Promise = sonarrApi + .getDownloads() + .then((items) => + Promise.all( + items + .filter( + (value, index, self) => index === self.findIndex((t) => t.seriesId === value.seriesId) + ) + .map((i) => tmdbApi.getTmdbSeriesFromTvdbId(String(i.series.tvdbId))) + ).then((i) => i.filter((i) => !!i) as TmdbSeries2[]) + ); + let radarrDownloads: Promise = radarrApi + .getDownloads() + .then((items) => + Promise.all(items.map((i) => tmdbApi.getTmdbMovie(i.movie.tmdbId || -1))).then( + (i) => i.filter((i) => !!i) as TmdbMovie2[] ) - .map((i) => ({ - backdropUrl: i.series.images?.find((i) => i.coverType === 'poster')?.remoteUrl || '', - group: true - })) - ); - let radarrDownloads: Promise[]> = radarrApi.getDownloads().then((items) => - items.map((i) => ({ - backdropUrl: i.movie.images?.find((i) => i.coverType === 'poster')?.remoteUrl || '' - })) - ); + ); settings.update((prev) => ({ ...prev, @@ -46,12 +51,12 @@ {#if sonarrDownloads?.length || radarrDownloads?.length} Downloading - {#each sonarrDownloads as props} - + {#each sonarrDownloads as item} + {/each} - {#each radarrDownloads as props} - + {#each radarrDownloads as item} + {/each} {/if} diff --git a/src/lib/utils.ts b/src/lib/utils.ts index 920fddc..5a4e788 100644 --- a/src/lib/utils.ts +++ b/src/lib/utils.ts @@ -134,8 +134,11 @@ export function subscribeUntil(store: Readable, fn: (value: T) => boolean) }); } -export function getCardDimensions(viewportWidth: number) { - const minWidth = 240; +export function getCardDimensions( + viewportWidth: number, + type: 'portrait' | 'landscape' = 'portrait' +) { + const minWidth = type === 'portrait' ? 240 : 400; const margin = 128; const gap = 32; @@ -144,7 +147,7 @@ export function getCardDimensions(viewportWidth: number) { const scale = -(gap * (cols - 1) + 2 * margin - viewportWidth) / (cols * minWidth); const newWidth = minWidth * scale; - const newHeight = (3 / 2) * newWidth; + const newHeight = (type === 'portrait' ? 3 / 2 : 9 / 16) * newWidth; return { width: newWidth,