Добавил проекты на страницу лаборатории. Добавил хуки usePostById (для wpPostPage) и usePostProjects (для варианта Projects в CardListPages)

This commit is contained in:
ifraimka1 committed 2025-04-03 20:03:16 +03:00
1 parent 2dad45711f
commit c66b352d3d
4 files changed
+47 -37

No files matched your search

+6 -24
View File
@@ -1,30 +1,12 @@
// posts/api/useProjectById.ts
// posts/api/usePostById.ts
import { fetchPostById } from "@/modules/posts/api/get";
import { useQuery } from "@tanstack/react-query";
import { wp } from "@/shared/api/wp-client";
import { parseContent } from "@/shared/api/parseContent";
import { App, WPv2 } from "@/shared/types/app";
import { App } from "@/shared/types/app";
export const usePostById = (id: number) => {
return useQuery<App.ProjectPost>({
queryKey: ["project", id],
queryFn: async () => {
const [post, categories] = await Promise.all([
wp.posts().id(id).get() as Promise<WPv2.Post>,
wp.categories().param("post", id).get() as Promise<WPv2.Category[]>,
]);
const categoryNames = categories.map((c) => c.name);
return {
id: post.id,
title: post.title.rendered,
content: parseContent(post.content.rendered),
lab: categoryNames.find((c) => c !== "projects") || "",
preview: post.featured_media?.toString() || null,
categories: categoryNames,
tag: "",
};
},
return useQuery<App.WpPost>({
queryKey: [id],
queryFn: fetchPostById,
enabled: !!id,
});
};
@@ -0,0 +1,12 @@
// posts/api/useProjects.ts
import { fetchProjects } from "@/modules/posts/api/get";
import { useQuery } from "@tanstack/react-query";
import { App } from "@/shared/types/app";
export const useProjects = (tag: number) => {
return useQuery<App.WpPost[]>({
queryKey: [tag],
queryFn: fetchProjects,
enabled: !!tag,
});
};