feat(frontend): add useLibrarySearch, useLibrarySyncStatus, useTriggerSync, useAdminSettings hooks
This commit is contained in:
34
k-tv-frontend/hooks/use-library-search.ts
Normal file
34
k-tv-frontend/hooks/use-library-search.ts
Normal file
@@ -0,0 +1,34 @@
|
||||
"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,
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user