Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 | 4x 1x 1x 8x 3x 1x 2x 2x 6x 2x | import { useQuery } from "@tanstack/react-query";
import { proApi } from "../../lib/api";
import { queryKeys } from "../../lib/query-keys";
import type { BlogMediaPage } from "../../lib/api/blog-images";
export function useBlogImages(proId: string | null, blogId: string | null) {
return useQuery({
queryKey: queryKeys.blogImages.list(proId as string, blogId as string),
queryFn: async () => {
// Safe to assert as string here because enabled check ensures non-null
const response = await proApi.getBlogImages(
proId as string,
blogId as string,
);
return response.data || [];
},
enabled: !!proId && !!blogId,
});
}
export function usePexelsSearch(proId: string | null, query: string, page = 1) {
return useQuery({
queryKey: queryKeys.blogImages.pexelsSearch(query, page),
queryFn: async () => {
if (!query || query.trim().length === 0) {
return { photos: [], page: 1, per_page: 20, total_results: 0 };
}
// Safe to assert as string here because enabled check ensures non-null
const response = await proApi.searchPexels(proId as string, query, page);
return response.data;
},
enabled: !!proId && query.trim().length > 0,
staleTime: 5 * 60 * 1000, // Cache for 5 minutes (Pexels rate limit)
});
}
/**
* Search the pro's media library for images to insert into the blog.
* A blank search returns all available media (no short-circuit on empty query).
*/
export function useProBlogMediaSearch(
proId: string | null,
blogId: string | null,
search: string,
page = 1,
) {
return useQuery<BlogMediaPage>({
queryKey: queryKeys.blogImages.proMedia(
proId ?? "",
blogId ?? "",
search,
page,
),
queryFn: async () => {
return proApi.searchProMedia(proId as string, blogId as string, {
search,
page,
perPage: 20,
});
},
enabled: !!proId && !!blogId,
staleTime: 5 * 60 * 1000,
});
}
|