ADd playlists to home screen

lots of backend player adjustments to get lastfm scrobbling
This commit is contained in:
Violet Caulfield
2025-01-07 06:56:05 -06:00
parent d8ab107a2f
commit 1dd0c06d05
10 changed files with 138 additions and 12 deletions
+32
View File
@@ -0,0 +1,32 @@
import { Api } from "@jellyfin/sdk";
import { BaseItemDto, ItemSortBy, SortOrder } from "@jellyfin/sdk/lib/generated-client/models";
import { getItemsApi } from "@jellyfin/sdk/lib/utils/api";
export function fetchUserPlaylists(api: Api, userId: string, playlistLibraryId: string): Promise<BaseItemDto[]> {
console.debug("Fetching user playlists");
return new Promise(async (resolve, reject) => {
getItemsApi(api)
.getItems({
userId: userId,
parentId: playlistLibraryId,
sortBy: [
ItemSortBy.IsFolder,
ItemSortBy.SortName
],
sortOrder: [
SortOrder.Ascending
]
})
.then((response) => {
if (response.data.Items)
resolve(response.data.Items)
else
resolve([]);
})
.catch((error) => {
console.error(error);
reject(error)
})
})
}
+2 -2
View File
@@ -29,9 +29,9 @@ export function fetchRecentlyPlayed(api: Api, libraryId: string): Promise<BaseIt
if (response.data.Items)
resolve(response.data.Items);
else {
else
resolve([]);
}
}).catch((error) => {
console.error(error);
reject(error);
+15
View File
@@ -0,0 +1,15 @@
import { QueryKeys } from "@/enums/query-keys";
import { Api } from "@jellyfin/sdk";
import { useQuery } from "@tanstack/react-query";
import { fetchUserPlaylists } from "./functions/playlists";
export const useUserPlaylists = (api: Api, userId: string, playlistLibraryId: string) => useQuery({
queryKey: [QueryKeys.UserPlaylists, api, userId, playlistLibraryId],
queryFn: ({ queryKey }) => {
const api: Api = queryKey[1] as Api;
const userId: string = queryKey[2] as string;
const playlistLibraryId: string = queryKey[3] as string;
return fetchUserPlaylists(api, userId, playlistLibraryId);
}
})