Пофиксил отображение проектов. Убрал лишнее поле categories в типе

This commit is contained in:
ifraimka1 committed 2025-04-17 19:11:07 +03:00
1 parent 84bffc7235
commit e7ccd0263c
3 files changed
+15 -9

No files matched your search

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