From 2dcc855da07e7b3489f3dfcbae68e1a2e9aabbcf Mon Sep 17 00:00:00 2001 From: Violet Caulfield Date: Tue, 18 Feb 2025 22:39:11 -0600 Subject: [PATCH] Horizontal card list adjustments Adding recently added albums to discover --- api/queries/functions/recents.ts | 21 +++++ components/Albums/component.tsx | 10 ++- components/Discover/component.tsx | 7 +- components/Discover/helpers/just-added.tsx | 45 ++++++++++ components/Discover/stack.tsx | 6 ++ .../Global/components/horizontal-list.tsx | 16 ++-- components/Home/helpers/recent-artists.tsx | 2 +- components/Home/helpers/recently-played.tsx | 83 ++++++++++--------- components/types.d.ts | 4 +- enums/query-keys.ts | 2 + 10 files changed, 141 insertions(+), 55 deletions(-) diff --git a/api/queries/functions/recents.ts b/api/queries/functions/recents.ts index b491a9b2..1e4c95bc 100644 --- a/api/queries/functions/recents.ts +++ b/api/queries/functions/recents.ts @@ -2,6 +2,27 @@ import { BaseItemDto, BaseItemKind, ItemSortBy, SortOrder } from "@jellyfin/sdk/ import { getItemsApi } from "@jellyfin/sdk/lib/utils/api/items-api"; import { QueryConfig } from "../query.config"; import Client from "../../client"; +import { getUserLibraryApi } from "@jellyfin/sdk/lib/utils/api"; + +export function fetchRecentlyAdded(offset?: number | undefined) : Promise { + return new Promise(async (resolve, reject) => { + + if (!!!Client.api) + return reject("Client not set") + + if (!!!Client.library) + return reject("Library not set") + else + getUserLibraryApi(Client.api) + .getLatestMedia({ + parentId: Client.library.musicLibraryId, + limit: QueryConfig.limits.recents, + }) + .then(({ data }) => { + resolve(data); + }); + }) +} export function fetchRecentlyPlayed(offset?: number | undefined): Promise { diff --git a/components/Albums/component.tsx b/components/Albums/component.tsx index 4e95c486..c41eef9c 100644 --- a/components/Albums/component.tsx +++ b/components/Albums/component.tsx @@ -5,11 +5,15 @@ import { FlatList, RefreshControl } from "react-native"; import { useQuery } from "@tanstack/react-query"; import { QueryKeys } from "../../enums/query-keys"; import { fetchFavoriteAlbums } from "../../api/queries/functions/favorites"; +import { fetchRecentlyAdded } from "../../api/queries/functions/recents"; + +export default function Albums({ navigation, route }: AlbumsProps) : React.JSX.Element { + + const fetchRecentlyAddedAlbums = route.params.query === QueryKeys.RecentlyAdded; -export default function Albums({ navigation }: AlbumsProps) : React.JSX.Element { const { data: albums, refetch, isPending } = useQuery({ - queryKey: [QueryKeys.FavoriteAlbums], - queryFn: () => fetchFavoriteAlbums() + queryKey: [route.params.query], + queryFn: () => fetchRecentlyAddedAlbums ? fetchRecentlyAdded(20) : fetchFavoriteAlbums() }); const { width } = useSafeAreaFrame(); diff --git a/components/Discover/component.tsx b/components/Discover/component.tsx index c6cfdd5f..17f6370a 100644 --- a/components/Discover/component.tsx +++ b/components/Discover/component.tsx @@ -1,12 +1,15 @@ import React from "react"; import { SafeAreaView } from "react-native-safe-area-context"; import { ScrollView } from "tamagui"; +import RecentlyAdded from "./helpers/just-added"; +import { NativeStackNavigationProp } from "@react-navigation/native-stack"; +import { StackParamList } from "../types"; -export default function Index() : React.JSX.Element { +export default function Index({ navigation }: { navigation : NativeStackNavigationProp }) : React.JSX.Element { return ( - + ) diff --git a/components/Discover/helpers/just-added.tsx b/components/Discover/helpers/just-added.tsx index e69de29b..81c10cc3 100644 --- a/components/Discover/helpers/just-added.tsx +++ b/components/Discover/helpers/just-added.tsx @@ -0,0 +1,45 @@ +import { useQuery } from "@tanstack/react-query"; +import { StackParamList } from "../../../components/types"; +import { NativeStackNavigationProp } from "@react-navigation/native-stack"; +import { QueryKeys } from "../../../enums/query-keys"; +import { fetchRecentlyAdded } from "../../../api/queries/functions/recents"; +import HorizontalCardList from "../../../components/Global/components/horizontal-list"; +import { ItemCard } from "@/components/Global/components/item-card"; + +export default function RecentlyAdded({ + navigation +} : { + navigation: NativeStackNavigationProp +}) : React.JSX.Element { + + const { data } = useQuery({ + queryKey: [QueryKeys.RecentlyAdded], + queryFn: () => fetchRecentlyAdded() + }); + + return ( + { + navigation.navigate("Albums", { + query: QueryKeys.RecentlyAdded + }) + }} + renderItem={({ item }) => + { + navigation.navigate("Album", { + album: item + }) + }} + /> + } + /> + ) +} \ No newline at end of file diff --git a/components/Discover/stack.tsx b/components/Discover/stack.tsx index e64ac1a6..3bd47598 100644 --- a/components/Discover/stack.tsx +++ b/components/Discover/stack.tsx @@ -3,6 +3,7 @@ import { StackParamList } from "../types"; import Index from "./component"; import DetailsScreen from "../ItemDetail/screen"; import Player from "../Player/stack"; +import Albums from "../Albums/component"; export const DiscoverStack = createNativeStackNavigator(); @@ -24,6 +25,11 @@ export function Discover(): React.JSX.Element { } }} /> + + | null | undefined - +interface HorizontalCardListProps extends FlatListProps { squared?: boolean | undefined; /** * The number of items that will be displayed before @@ -24,20 +21,19 @@ interface HorizontalCardListProps { * @returns */ export default function HorizontalCardList({ - items, - renderItem, cutoff = horizontalCardLimit, onSeeMore, squared = false, + ...props } : HorizontalCardListProps) : React.JSX.Element { return ( { - return items ? ( + return props.data ? ( Recent Artists { navigation.navigate("Artists", { query: QueryKeys.RecentlyPlayedArtists diff --git a/components/Home/helpers/recently-played.tsx b/components/Home/helpers/recently-played.tsx index b04c6558..a7a7b23d 100644 --- a/components/Home/helpers/recently-played.tsx +++ b/components/Home/helpers/recently-played.tsx @@ -17,47 +17,54 @@ export default function RecentlyPlayed({ navigation: NativeStackNavigationProp }): React.JSX.Element { - const { usePlayNewQueue } = usePlayerContext(); + const { nowPlaying, usePlayNewQueue } = usePlayerContext(); const { recentTracks } = useHomeContext(); return ( - -

Play it again

+ useMemo(() => { + return ( + +

Play it again

- { - navigation.navigate("Tracks", { - query: QueryKeys.RecentlyPlayed - }) - }} - renderItem={({ index, item: recentlyPlayedTrack }) => - { - usePlayNewQueue.mutate({ - track: recentlyPlayedTrack, - index: index, - tracklist: recentTracks ?? [recentlyPlayedTrack], - queue: "Recently Played", - queuingType: QueuingType.FromSelection - }); - }} - onLongPress={() => { - trigger("impactMedium"); - navigation.navigate("Details", { - item: recentlyPlayedTrack, - isNested: false - }) - }} - /> - } - /> -
+ { + navigation.navigate("Tracks", { + query: QueryKeys.RecentlyPlayed + }) + }} + renderItem={({ index, item: recentlyPlayedTrack }) => + { + usePlayNewQueue.mutate({ + track: recentlyPlayedTrack, + index: index, + tracklist: recentTracks ?? [recentlyPlayedTrack], + queue: "Recently Played", + queuingType: QueuingType.FromSelection + }); + }} + onLongPress={() => { + trigger("impactMedium"); + navigation.navigate("Details", { + item: recentlyPlayedTrack, + isNested: false + }) + }} + /> + } + /> +
+ ) + }, [ + recentTracks, + nowPlaying + ]) ) } \ No newline at end of file diff --git a/components/types.d.ts b/components/types.d.ts index 8b48b6cd..5498fc57 100644 --- a/components/types.d.ts +++ b/components/types.d.ts @@ -32,7 +32,9 @@ export type StackParamList = { Artists: { query: QueryKeys.FavoriteArtists | QueryKeys.RecentlyPlayedArtists }; - Albums: undefined; + Albums: { + query: QueryKeys.FavoriteAlbums | QueryKeys.RecentlyAdded + }; Tracks: { query: QueryKeys.FavoriteTracks | QueryKeys.RecentlyPlayed }; diff --git a/enums/query-keys.ts b/enums/query-keys.ts index fbfae93f..b09fe3eb 100644 --- a/enums/query-keys.ts +++ b/enums/query-keys.ts @@ -40,4 +40,6 @@ export enum QueryKeys { SearchSuggestions = "SearchSuggestions", FavoritePlaylists = "FavoritePlaylists", UserViews = "UserViews", + Audio = "Audio", + RecentlyAdded = "RecentlyAdded", } \ No newline at end of file