recent artists from query data

This commit is contained in:
Violet Caulfield
2025-02-23 11:19:04 -06:00
parent d74b7ce3f5
commit e3655a5689
2 changed files with 6 additions and 5 deletions

View File

@@ -4,7 +4,8 @@ import { fetchRecentlyPlayed, fetchRecentlyPlayedArtists } from "../../api/queri
import { CarPlay, ListTemplate } from "react-native-carplay";
import { CarPlayRecentlyPlayed } from "./RecentlyPlayed";
import { CarPlayRecentArtists } from "./RecentArtists";
import { queryClient } from "@/constants/query-client";
import { queryClient } from "../../constants/query-client";
import { BaseItemDto } from "@jellyfin/sdk/lib/generated-client/models";
const CarPlayHome : ListTemplate = new ListTemplate({
id: 'Home',
@@ -24,7 +25,7 @@ const CarPlayHome : ListTemplate = new ListTemplate({
switch (index) {
case 0:
const artists = await fetchRecentlyPlayedArtists();
const artists = queryClient.getQueryData<BaseItemDto[]>([QueryKeys.RecentlyPlayedArtists]);
CarPlay.pushTemplate(CarPlayRecentArtists(artists))
break;
case 1:

View File

@@ -3,11 +3,11 @@ import { BaseItemDto, ImageType } from "@jellyfin/sdk/lib/generated-client/model
import { ListTemplate } from "react-native-carplay"
import { QueryKeys } from "../../enums/query-keys"
export const CarPlayRecentArtists = (artists : BaseItemDto[]) => new ListTemplate({
export const CarPlayRecentArtists = (artists : BaseItemDto[] | undefined) => new ListTemplate({
title: "Recently Played",
sections: [
{
items: artists.map(artist => {
items: artists ? artists.map(artist => {
return {
id: artist.Id!,
text: artist.Name ? artist.Name : "Untitled Track",
@@ -15,7 +15,7 @@ export const CarPlayRecentArtists = (artists : BaseItemDto[]) => new ListTemplat
uri: queryClient.getQueryData([ QueryKeys.ItemImage, ImageType.Primary ])
}
}
})
}) : []
}
]
})