From d620417e31110af51f64c0fd7789cdd93dc1f04a Mon Sep 17 00:00:00 2001 From: ifraimka1 Date: Thu, 17 Apr 2025 19:04:07 +0300 Subject: [PATCH] =?UTF-8?q?=D0=9F=D0=BE=D1=84=D0=B8=D0=BA=D1=81=D0=B8?= =?UTF-8?q?=D0=BB=20=D0=BE=D1=82=D0=BE=D0=B1=D1=80=D0=B0=D0=B6=D0=B5=D0=BD?= =?UTF-8?q?=D0=B8=D0=B5=20=D0=BF=D1=80=D0=BE=D0=B5=D0=BA=D1=82=D0=BE=D0=B2?= =?UTF-8?q?.=20=D0=A3=D0=B1=D1=80=D0=B0=D0=BB=20=D0=BB=D0=B8=D1=88=D0=BD?= =?UTF-8?q?=D0=B5=D0=B5=20=D0=BF=D0=BE=D0=BB=D0=B5=20categories=20=D0=B2?= =?UTF-8?q?=20=D1=82=D0=B8=D0=BF=D0=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../posts/api/get/fetchPostProjects.ts | 20 +++++++++++++------ src/modules/posts/api/get/fetchPosts.ts | 3 +-- src/shared/types/app.d.ts | 1 - 3 files changed, 15 insertions(+), 9 deletions(-) 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 {