possible suggested episodes bandaid

This commit is contained in:
simon
2024-09-07 10:56:05 +02:00
parent fced376a68
commit 35a470c4ae

View File

@@ -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() {
</ScrollView>
);
}
// 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;
}