diff --git a/src/modules/posts/api/get/fetchPostProjects.ts b/src/modules/posts/api/get/fetchPostProjects.ts index 69dc48e..e8f224e 100644 --- a/src/modules/posts/api/get/fetchPostProjects.ts +++ b/src/modules/posts/api/get/fetchPostProjects.ts @@ -6,10 +6,16 @@ import { App, WPv2 } from "@/shared/types/app"; export const fetchPostProjects = async (tag: number): Promise => { const categories = await wp.categories().get() as WPv2.Category[]; const catId = categories.find(item => item.name === "projects")?.id || -1; + const isLabPage = tag !== -1; // Если передали тег, значит, это страница лаборатории + // Одновременно отфильтровать и по тегу, по категории WP не дает + // Если тега нет, проще взять категорию projects + // Если тег есть, надо искать по нему const postsRequest = wp.posts(); - if (tag !== -1) { + if (isLabPage) { postsRequest.tags(tag); + } else { + postsRequest.categories(catId); } const [posts, mediaLibrary] = await Promise.all([ @@ -17,10 +23,13 @@ export const fetchPostProjects = async (tag: number): Promise => { fetchMedia(), ]); - const labIndex = posts.findIndex((post) => { - return !post.categories.includes(catId); - }); - posts.splice(labIndex, 1); + // При выборке по тегу подтянется еще и лаборатория, ее нужно убрать из массива + if (isLabPage) { + const labIndex = posts.findIndex((post) => { + return !post.categories.includes(catId); + }); + posts.splice(labIndex, 1); + } const result: App.Card[] = []; @@ -30,7 +39,6 @@ export const fetchPostProjects = async (tag: number): Promise => { const newPost: App.Card = { id: post.id, title: post.title.rendered, - //tag: post.tags[0] || -1, preview: image?.src || null, }; diff --git a/src/modules/posts/api/get/fetchPosts.ts b/src/modules/posts/api/get/fetchPosts.ts index 2d59034..c429ca1 100644 --- a/src/modules/posts/api/get/fetchPosts.ts +++ b/src/modules/posts/api/get/fetchPosts.ts @@ -31,7 +31,6 @@ export const fetchPosts = async (): Promise => { const newPost: App.WpPost = { id: post.id, title: post.title.rendered, - categories: postCategories, }; if (postCategories.includes("projects")) { @@ -58,6 +57,6 @@ export const fetchPosts = async (): Promise => { result.other.push(newWpPostPage); } } - + console.log('fetchPosts result', result); return result; }; diff --git a/src/shared/types/app.d.ts b/src/shared/types/app.d.ts index 9025138..a40e86f 100644 --- a/src/shared/types/app.d.ts +++ b/src/shared/types/app.d.ts @@ -276,7 +276,6 @@ declare namespace App { export interface WpPost { id: number; title: string; - categories: string[]; } export interface WpPostPage extends WpPost {