35 lines
905 B
TypeScript
35 lines
905 B
TypeScript
"use client";
|
|
|
|
import { useQuery } from "@tanstack/react-query";
|
|
import { api } from "@/lib/api";
|
|
import { useAuthContext } from "@/context/auth-context";
|
|
|
|
export interface LibrarySearchParams {
|
|
q?: string;
|
|
type?: string;
|
|
series?: string[];
|
|
collection?: string;
|
|
provider?: string;
|
|
decade?: number;
|
|
min_duration?: number;
|
|
max_duration?: number;
|
|
genres?: string[];
|
|
offset?: number;
|
|
limit?: number;
|
|
}
|
|
|
|
/**
|
|
* Paginated library search — always enabled, DB-backed (fast).
|
|
* Separate from useLibraryItems in use-library.ts which is snapshot-based
|
|
* and used only for block editor filter preview.
|
|
*/
|
|
export function useLibrarySearch(params: LibrarySearchParams) {
|
|
const { token } = useAuthContext();
|
|
return useQuery({
|
|
queryKey: ["library", "search", params],
|
|
queryFn: () => api.library.itemsPage(token!, params),
|
|
enabled: !!token,
|
|
staleTime: 2 * 60 * 1000,
|
|
});
|
|
}
|