diff --git a/api/queries/functions/recents.ts b/api/queries/functions/recents.ts new file mode 100644 index 00000000..63095049 --- /dev/null +++ b/api/queries/functions/recents.ts @@ -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 { + 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([]); + } + }) + }) +} \ No newline at end of file diff --git a/api/queries/recently-played.ts b/api/queries/recently-played.ts index 766d90c0..0b59c7aa 100644 --- a/api/queries/recently-played.ts +++ b/api/queries/recently-played.ts @@ -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) }) \ No newline at end of file diff --git a/components/Home/helpers/recently-played.tsx b/components/Home/helpers/recently-played.tsx index 8d48fd2a..87b856da 100644 --- a/components/Home/helpers/recently-played.tsx +++ b/components/Home/helpers/recently-played.tsx @@ -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 (