From 82a7fb1429d7704f6d66622ae9509f878ade9131 Mon Sep 17 00:00:00 2001 From: felixNyalenda Date: Thu, 11 Jan 2024 10:32:17 +0300 Subject: [PATCH 1/3] Add related blogs header --- src/APP/pages/blog/sections/RelatedBlogs.jsx | 35 +++++++++++--------- 1 file changed, 20 insertions(+), 15 deletions(-) diff --git a/src/APP/pages/blog/sections/RelatedBlogs.jsx b/src/APP/pages/blog/sections/RelatedBlogs.jsx index 04ea6083..4ffed94d 100644 --- a/src/APP/pages/blog/sections/RelatedBlogs.jsx +++ b/src/APP/pages/blog/sections/RelatedBlogs.jsx @@ -30,21 +30,26 @@ function RelatedBlogs({ blogId, categoryId }) { {isLoading &&

Loading blogs...

} {isSuccess && ( -
- {Array.isArray(filteredRelatedBlogs) && - filteredRelatedBlogs.length > 0 ? ( - filteredRelatedBlogs.filter(function(blog){ - if(blog.id === blogId ) { - return false; - } - return true; - }).map((blog) => ( - - )) - ) : ( -

No related blogs found!

- )} -
+ <> +

+ Related Blogs +

+
+ {Array.isArray(filteredRelatedBlogs) && + filteredRelatedBlogs.length > 0 ? ( + filteredRelatedBlogs + .filter(function (blog) { + if (blog.id === blogId) { + return false; + } + return true; + }) + .map((blog) => ) + ) : ( +

No related blogs found!

+ )} +
+ )} ); From 11596e7edf77522c39a0091e0ac8dbe2ab623e0c Mon Sep 17 00:00:00 2001 From: felixNyalenda Date: Thu, 11 Jan 2024 16:27:37 +0300 Subject: [PATCH 2/3] conditionally render related blogs --- src/APP/pages/blog/sections/RelatedBlogs.jsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/APP/pages/blog/sections/RelatedBlogs.jsx b/src/APP/pages/blog/sections/RelatedBlogs.jsx index 4ffed94d..b669aca9 100644 --- a/src/APP/pages/blog/sections/RelatedBlogs.jsx +++ b/src/APP/pages/blog/sections/RelatedBlogs.jsx @@ -29,7 +29,7 @@ function RelatedBlogs({ blogId, categoryId }) { {isError &&

Error loading blogs!

} {isLoading &&

Loading blogs...

} - {isSuccess && ( + {isSuccess && filteredRelatedBlogs.length > 0 && ( <>

Related Blogs From ae632239d619a197ae00e0e97c93318eca420302 Mon Sep 17 00:00:00 2001 From: felixNyalenda Date: Thu, 11 Jan 2024 16:30:44 +0300 Subject: [PATCH 3/3] conditionally render related blogs --- src/APP/pages/blogs/sections/BlogsWrapper.jsx | 13 +------------ 1 file changed, 1 insertion(+), 12 deletions(-) diff --git a/src/APP/pages/blogs/sections/BlogsWrapper.jsx b/src/APP/pages/blogs/sections/BlogsWrapper.jsx index 77ba83c4..2d1a199d 100644 --- a/src/APP/pages/blogs/sections/BlogsWrapper.jsx +++ b/src/APP/pages/blogs/sections/BlogsWrapper.jsx @@ -1,4 +1,3 @@ - /* eslint-disable operator-linebreak */ /* eslint-disable react/jsx-indent */ import React, { useState, useEffect, useContext } from "react"; @@ -16,14 +15,11 @@ import { import { filterBlogsByCat } from "../../../../utilities/FilterBlogs"; - function SearchResults({ searchText }) { return (

- Showing results for - "{searchText}" - + "{searchText}"

); } @@ -34,7 +30,6 @@ function BlogsWrapper() { const [selectedCat, setSelectedCat] = useState(""); const [page, setPage] = useState(1); - const { data: blogsData, refetch: refetchBlogsData, @@ -54,7 +49,6 @@ function BlogsWrapper() { setPage((prevState) => (prevState = index)); }; - const handleFilter = (categoryId) => { setSelectedCat(categoryId); }; @@ -66,12 +60,10 @@ function BlogsWrapper() { const allBlogs = filteredBlogs && Array.isArray(filteredBlogs) ? filteredBlogs.map((blog) => ) - : null; return (
- {isError && } {isLoading && (
@@ -82,7 +74,6 @@ function BlogsWrapper() { {isSuccess && ( <>
- {statusBlogCategories === "error" && (

Error loading blog categories!

)} @@ -102,7 +93,6 @@ function BlogsWrapper() { blogCategories && Array.isArray(blogCategories) ? blogCategories.map((blog) => ( - - )) : null}