mirror of
https://github.com/Jellify-Music/App.git
synced 2026-02-21 19:28:59 -06:00
add function for retrieving artist image ig?
This commit is contained in:
@@ -3,6 +3,17 @@ import { ImageFormat, ImageType } from "@jellyfin/sdk/lib/generated-client/model
|
||||
import { getImageApi } from "@jellyfin/sdk/lib/utils/api"
|
||||
import _ from "lodash"
|
||||
|
||||
export function fetchArtistImage(api: Api, artistId: string, imageType?: ImageType) {
|
||||
return getImageApi(api).getArtistImage({
|
||||
name: "",
|
||||
imageIndex: 1,
|
||||
imageType: imageType ? imageType : ImageType.Primary
|
||||
})
|
||||
.then((response) => {
|
||||
console.log(response.data)
|
||||
return response.data;
|
||||
})
|
||||
}
|
||||
|
||||
export function fetchItemImage(api: Api, itemId: string, imageType?: ImageType, width?: number) {
|
||||
|
||||
|
||||
@@ -1,10 +1,15 @@
|
||||
import { useQuery } from "@tanstack/react-query";
|
||||
import { QueryKeys } from "../../enums/query-keys";
|
||||
import { Api } from "@jellyfin/sdk";
|
||||
import { fetchItemImage } from "./functions/images";
|
||||
import { fetchArtistImage, fetchItemImage } from "./functions/images";
|
||||
import { ImageType } from "@jellyfin/sdk/lib/generated-client/models";
|
||||
|
||||
export const useArtistImage = (api: Api, artistName: string, imageType?: ImageType) => useQuery({
|
||||
queryKey: [QueryKeys.ArtistImage, api, artistName, imageType],
|
||||
queryFn: ({ queryKey }) => fetchArtistImage(queryKey[1] as Api, queryKey[2] as string, queryKey[3] as ImageType | undefined)
|
||||
})
|
||||
|
||||
export const useItemImage = (api: Api, itemId: string, imageType?: ImageType, width?: number) => useQuery({
|
||||
queryKey: [QueryKeys.ItemImage, api, itemId, imageType, width],
|
||||
queryFn: ({ queryKey }) => fetchItemImage(queryKey[1] as Api, queryKey[2] as string, imageType, width)
|
||||
queryFn: ({ queryKey }) => fetchItemImage(queryKey[1] as Api, queryKey[2] as string, queryKey[3] as ImageType | undefined, queryKey[4] as number | undefined)
|
||||
});
|
||||
@@ -4,16 +4,11 @@ import { H3, Image, Card as TamaguiCard, ZStack } from "tamagui";
|
||||
import { LinearGradient } from "tamagui/linear-gradient";
|
||||
import { useApiClientContext } from "../jellyfin-api-provider";
|
||||
import { cardDimensions } from "./component.config";
|
||||
import { useItemImage } from "../../api/queries/image";
|
||||
import { useArtistImage, useItemImage } from "../../api/queries/image";
|
||||
import { Colors } from "../../enums/colors";
|
||||
|
||||
export enum CardType {
|
||||
Artist = "ARTIST",
|
||||
Album = "ALBUM"
|
||||
}
|
||||
|
||||
interface CardProps extends TamaguiCardProps {
|
||||
cardType?: CardType;
|
||||
artistName?: string;
|
||||
children?: string;
|
||||
itemId: string;
|
||||
footer?: ReactNode;
|
||||
@@ -22,9 +17,9 @@ interface CardProps extends TamaguiCardProps {
|
||||
export function Card(props: CardProps) {
|
||||
|
||||
const { apiClient } = useApiClientContext();
|
||||
const { data, isPending } = useItemImage(apiClient!, props.itemId)
|
||||
const { data, isPending } = props.artistName ? useArtistImage(apiClient!, props.artistName) : useItemImage(apiClient!, props.itemId)
|
||||
|
||||
const dimensions = props.cardType === CardType.Artist ? cardDimensions.artist : cardDimensions.album;
|
||||
const dimensions = props.artistName ? cardDimensions.artist : cardDimensions.album;
|
||||
|
||||
return (
|
||||
<TamaguiCard
|
||||
|
||||
@@ -4,7 +4,7 @@ import { useHomeContext } from "../provider";
|
||||
import { H2 } from "../../Global/text";
|
||||
import { ProvidedHomeProps } from "../types";
|
||||
import { FlatList } from "react-native";
|
||||
import { Card, CardType } from "../../Global/card";
|
||||
import { Card } from "../../Global/card";
|
||||
|
||||
export default function RecentArtists({ navigation }: ProvidedHomeProps): React.JSX.Element {
|
||||
|
||||
@@ -24,7 +24,7 @@ export default function RecentArtists({ navigation }: ProvidedHomeProps): React.
|
||||
renderItem={({ item: recentArtist}) => {
|
||||
return (
|
||||
<Card
|
||||
cardType={CardType.Artist}
|
||||
artistName={recentArtist.Name!}
|
||||
itemId={recentArtist.Id!}
|
||||
onPress={() => {
|
||||
navigation.navigate('Artist',
|
||||
|
||||
@@ -24,4 +24,5 @@ export enum QueryKeys {
|
||||
RecentlyPlayed = "RecentlyPlayed",
|
||||
RecentlyPlayedArtists = "RecentlyPlayedArtists",
|
||||
ArtistFeaturedAlbums = "ArtistFeaturedAlbums",
|
||||
ArtistImage = "ArtistImage",
|
||||
}
|
||||
Reference in New Issue
Block a user