mirror of
https://github.com/Jellify-Music/App.git
synced 2026-04-22 01:28:28 -05:00
ADd playlists to home screen
lots of backend player adjustments to get lastfm scrobbling
This commit is contained in:
@@ -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)
|
||||
})
|
||||
})
|
||||
}
|
||||
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
})
|
||||
Reference in New Issue
Block a user