Partial improvements to typescript types

This commit is contained in:
Aleksi Lassila
2023-07-04 20:50:52 +03:00
parent 109caab74d
commit a6be82c91f
11 changed files with 152 additions and 105 deletions

View File

@@ -3,6 +3,11 @@ import { RadarrApi } from '$lib/radarr/radarr';
import type { CardProps } from '../components/Card/card';
import { fetchCardProps } from '../components/Card/card';
interface DownloadingCardProps extends CardProps {
progress: number;
completionTime: string;
}
export const load = (() => {
const [downloading, available, unavailable] = getLibraryItems();
@@ -22,7 +27,7 @@ export const load = (() => {
async function getLibraryInfo(): Promise<any> {}
function getLibraryItems() {
function getLibraryItems(): [Promise<DownloadingCardProps[]>, Promise<CardProps[]>, Promise<CardProps[]>] {
const radarrMovies = RadarrApi.get('/api/v3/movie', {
params: {}
}).then((r) => r.data);
@@ -71,17 +76,22 @@ function getLibraryItems() {
);
});
const downloading: Promise<CardProps[]> = downloadingRadarrMovies.then(async (movies) => {
return Promise.all(
movies
?.filter((m) => m?.movie?.tmdbId)
?.map(async (m) => ({
...(await fetchCardProps(m.movie as any)),
progress: m.sizeleft && m.size ? ((m.size - m.sizeleft) / m.size) * 100 : 0,
completionTime: m.estimatedCompletionTime
})) || []
);
});
const downloading: Promise<DownloadingCardProps[]> = downloadingRadarrMovies.then(
async (movies) => {
return Promise.all(
movies
?.filter((m) => m?.movie?.tmdbId)
?.map(
async (m) =>
({
...(await fetchCardProps(m.movie as any)),
progress: m.sizeleft && m.size ? ((m.size - m.sizeleft) / m.size) * 100 : 0,
completionTime: m.estimatedCompletionTime
} as DownloadingCardProps)
) || []
);
}
);
return [downloading, available, unavailable];
}