From 8101734c63e19f8da9d8a4893a5f390f3e0002f7 Mon Sep 17 00:00:00 2001 From: Gabriel Kaszewski Date: Fri, 20 Mar 2026 01:29:55 +0100 Subject: [PATCH] feat(frontend): add useLibraryShows and useLibrarySeasons hooks --- k-tv-frontend/hooks/use-library-seasons.ts | 14 ++++++++++++++ k-tv-frontend/hooks/use-library-shows.ts | 20 ++++++++++++++++++++ 2 files changed, 34 insertions(+) create mode 100644 k-tv-frontend/hooks/use-library-seasons.ts create mode 100644 k-tv-frontend/hooks/use-library-shows.ts diff --git a/k-tv-frontend/hooks/use-library-seasons.ts b/k-tv-frontend/hooks/use-library-seasons.ts new file mode 100644 index 0000000..e1f686e --- /dev/null +++ b/k-tv-frontend/hooks/use-library-seasons.ts @@ -0,0 +1,14 @@ +import { useQuery } from "@tanstack/react-query"; +import { api } from "@/lib/api"; +import { useAuthContext } from "@/context/auth-context"; +import type { SeasonSummary } from "@/lib/types"; + +export function useLibrarySeasons(seriesName: string | null, provider?: string) { + const { token } = useAuthContext(); + return useQuery({ + queryKey: ["library", "seasons", seriesName, provider], + queryFn: () => api.library.seasons(token!, seriesName!, provider), + enabled: !!token && !!seriesName, + staleTime: 30_000, + }); +} diff --git a/k-tv-frontend/hooks/use-library-shows.ts b/k-tv-frontend/hooks/use-library-shows.ts new file mode 100644 index 0000000..672c36c --- /dev/null +++ b/k-tv-frontend/hooks/use-library-shows.ts @@ -0,0 +1,20 @@ +import { useQuery } from "@tanstack/react-query"; +import { api } from "@/lib/api"; +import { useAuthContext } from "@/context/auth-context"; +import type { ShowSummary } from "@/lib/types"; + +export interface ShowsFilter { + q?: string; + provider?: string; + genres?: string[]; +} + +export function useLibraryShows(filter: ShowsFilter = {}) { + const { token } = useAuthContext(); + return useQuery({ + queryKey: ["library", "shows", filter], + queryFn: () => api.library.shows(token!, filter), + enabled: !!token, + staleTime: 30_000, + }); +}