From 35a470c4ae1f9de572c9bb30f923f24ef76b1fee Mon Sep 17 00:00:00 2001 From: simon Date: Sat, 7 Sep 2024 10:56:05 +0200 Subject: [PATCH 1/3] possible suggested episodes bandaid --- app/(auth)/(tabs)/(home)/index.tsx | 45 ++++++++++++++++++++++++------ 1 file changed, 36 insertions(+), 9 deletions(-) diff --git a/app/(auth)/(tabs)/(home)/index.tsx b/app/(auth)/(tabs)/(home)/index.tsx index 69733e9b..bb9fbc2a 100644 --- a/app/(auth)/(tabs)/(home)/index.tsx +++ b/app/(auth)/(tabs)/(home)/index.tsx @@ -245,15 +245,22 @@ export default function index() { { title: "Suggested Episodes", queryKey: ["suggestedEpisodes", user?.Id], - queryFn: async () => - ( - await getSuggestionsApi(api).getSuggestions({ - userId: user?.Id, - limit: 10, - mediaType: ["Video"], - type: ["Episode"], - }) - ).data.Items || [], + queryFn: async () =>{ + try { + const userId = user?.Id; + if (!userId) return []; + + const suggestions = await getSuggestions(api, userId); + const nextUpPromises = suggestions.map(series => getNextUp(api, userId, series.Id!)); + const nextUpResults = await Promise.all(nextUpPromises); + + return nextUpResults.filter(item => item !== null); + } catch (error) { + console.error('Error fetching data:', error); + return []; + } + } + , type: "ScrollingCollectionList", orientation: "horizontal", }, @@ -371,3 +378,23 @@ export default function index() { ); } + +// Function to get suggestions +async function getSuggestions(api: any, userId: string) { + const response = await getSuggestionsApi(api).getSuggestions({ + userId, + limit: 10, + mediaType: ["Unknown"], + type: ["Series"], + }); + return response.data.Items ?? []; +} + +// Function to get the next up TV show for a series +async function getNextUp(api: any, userId: string, seriesId: string) { + const response = await getTvShowsApi(api).getNextUp({ + userId, + seriesId, + }); + return response.data.Items?.[0] ?? null; +} \ No newline at end of file From 4a1ea7ea708591d2850300806f408ace8180331c Mon Sep 17 00:00:00 2001 From: Fredrik Burmester Date: Sat, 7 Sep 2024 18:15:12 +0300 Subject: [PATCH 2/3] fix: add api type and better undefined handling --- app/(auth)/(tabs)/(home)/index.tsx | 33 +++++++++++++++++------------- 1 file changed, 19 insertions(+), 14 deletions(-) diff --git a/app/(auth)/(tabs)/(home)/index.tsx b/app/(auth)/(tabs)/(home)/index.tsx index bb9fbc2a..057664c7 100644 --- a/app/(auth)/(tabs)/(home)/index.tsx +++ b/app/(auth)/(tabs)/(home)/index.tsx @@ -7,6 +7,7 @@ import { MediaListSection } from "@/components/medialists/MediaListSection"; import { apiAtom, userAtom } from "@/providers/JellyfinProvider"; import { useSettings } from "@/utils/atoms/settings"; import { Ionicons } from "@expo/vector-icons"; +import { Api } from "@jellyfin/sdk"; import { BaseItemDto } from "@jellyfin/sdk/lib/generated-client/models"; import { getItemsApi, @@ -245,22 +246,20 @@ export default function index() { { title: "Suggested Episodes", queryKey: ["suggestedEpisodes", user?.Id], - queryFn: async () =>{ + queryFn: async () => { try { - const userId = user?.Id; - if (!userId) return []; - - const suggestions = await getSuggestions(api, userId); - const nextUpPromises = suggestions.map(series => getNextUp(api, userId, series.Id!)); + const suggestions = await getSuggestions(api, user.Id); + const nextUpPromises = suggestions.map((series) => + getNextUp(api, user.Id, series.Id) + ); const nextUpResults = await Promise.all(nextUpPromises); - - return nextUpResults.filter(item => item !== null); + + return nextUpResults.filter((item) => item !== null) || []; } catch (error) { - console.error('Error fetching data:', error); + console.error("Error fetching data:", error); return []; } - } - , + }, type: "ScrollingCollectionList", orientation: "horizontal", }, @@ -380,7 +379,8 @@ export default function index() { } // Function to get suggestions -async function getSuggestions(api: any, userId: string) { +async function getSuggestions(api: Api, userId: string | undefined) { + if (!userId) return []; const response = await getSuggestionsApi(api).getSuggestions({ userId, limit: 10, @@ -391,10 +391,15 @@ async function getSuggestions(api: any, userId: string) { } // Function to get the next up TV show for a series -async function getNextUp(api: any, userId: string, seriesId: string) { +async function getNextUp( + api: Api, + userId: string | undefined, + seriesId: string | undefined +) { + if (!userId || !seriesId) return null; const response = await getTvShowsApi(api).getNextUp({ userId, seriesId, }); return response.data.Items?.[0] ?? null; -} \ No newline at end of file +} From dbaba93fbfd08ba4af60d2550ef5b48b9173ab72 Mon Sep 17 00:00:00 2001 From: Fredrik Burmester Date: Sat, 7 Sep 2024 18:16:59 +0300 Subject: [PATCH 3/3] fix: add limit don't know if nessesary since there can only be 1 next up...? --- app/(auth)/(tabs)/(home)/index.tsx | 1 + 1 file changed, 1 insertion(+) diff --git a/app/(auth)/(tabs)/(home)/index.tsx b/app/(auth)/(tabs)/(home)/index.tsx index 057664c7..f46bf058 100644 --- a/app/(auth)/(tabs)/(home)/index.tsx +++ b/app/(auth)/(tabs)/(home)/index.tsx @@ -400,6 +400,7 @@ async function getNextUp( const response = await getTvShowsApi(api).getNextUp({ userId, seriesId, + limit: 1, }); return response.data.Items?.[0] ?? null; }