mirror of
https://git.rdcenter.ru/RDCenter/skb-kit.git
synced 2026-12-05 02:39:45 +00:00
Добавил проекты на страницу лаборатории. Добавил хуки usePostById (для wpPostPage) и usePostProjects (для варианта Projects в CardListPages)
This commit is contained in:
1 parent
2dad45711f
commit
c66b352d3d
4 files changed
+47
-37
No files matched your search
@@ -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,
|
||||
});
|
||||
};
|
||||
Reference in new issue
Block a user