mirror of
https://github.com/Jellify-Music/App.git
synced 2026-02-22 19:58:35 -06:00
Add recently played query and function
This commit is contained in:
17
api/queries/functions/recents.ts
Normal file
17
api/queries/functions/recents.ts
Normal file
@@ -0,0 +1,17 @@
|
||||
import { Api } from "@jellyfin/sdk/lib/api";
|
||||
import { BaseItemDto, ItemSortBy } from "@jellyfin/sdk/lib/generated-client/models";
|
||||
import { getItemsApi } from "@jellyfin/sdk/lib/utils/api/items-api";
|
||||
|
||||
export function fetchRecentlyPlayed(api: Api): Promise<BaseItemDto[] | undefined> {
|
||||
return new Promise(async (resolve, reject) => {
|
||||
getItemsApi(api).getItems({ sortBy: [ ItemSortBy.DatePlayed ], limit: 100 })
|
||||
.then((response) => {
|
||||
|
||||
if (response.data.Items)
|
||||
resolve(response.data.Items);
|
||||
else {
|
||||
resolve([]);
|
||||
}
|
||||
})
|
||||
})
|
||||
}
|
||||
@@ -1,11 +1,9 @@
|
||||
import { Api } from "@jellyfin/sdk";
|
||||
import { useQuery } from "@tanstack/react-query";
|
||||
import { QueryKeys } from "../../enums/query-keys";
|
||||
import { getItemsApi } from "@jellyfin/sdk/lib/utils/api/items-api";
|
||||
import { fetchRecentlyPlayed } from "./functions/recents";
|
||||
|
||||
export const useRecentlyPlayed = (api: Api) => useQuery({
|
||||
queryKey: [QueryKeys.RecentlyPlayed],
|
||||
queryFn: () => {
|
||||
|
||||
}
|
||||
queryFn: () => fetchRecentlyPlayed(api)
|
||||
})
|
||||
@@ -1,4 +1,4 @@
|
||||
import React from "react";
|
||||
import React, { useEffect } from "react";
|
||||
import { ScrollView } from "tamagui";
|
||||
import { useApiClientContext } from "../../jellyfin-api-provider";
|
||||
import { useRecentlyPlayed } from "../../../api/queries/recently-played";
|
||||
@@ -9,6 +9,12 @@ export default function RecentlyPlayed(): React.JSX.Element {
|
||||
|
||||
const { data, isError, refetch } = useRecentlyPlayed(apiClient!)
|
||||
|
||||
useEffect(() => {
|
||||
console.log(data);
|
||||
}, [
|
||||
data
|
||||
])
|
||||
|
||||
return (
|
||||
<ScrollView horizontal>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user