From 03eb483486ebe7d137190c6bb948e3bbbff1d3b2 Mon Sep 17 00:00:00 2001 From: hamed <15238-genius.ha@users.noreply.drupalcode.org> Date: Sun, 21 Jun 2026 17:34:12 +0330 Subject: [PATCH] fix(tags): update tag fetching logic and improve tag handling in Title component --- components/blogs/title/index.js | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/components/blogs/title/index.js b/components/blogs/title/index.js index a212943..a70c325 100644 --- a/components/blogs/title/index.js +++ b/components/blogs/title/index.js @@ -10,12 +10,14 @@ function Title({ onTagChange }) { useEffect(() => { const fetchTags = async () => { try { - const params = { - page: 1, - limit: 100, - }; - const response = await request.getBlogTags(params); - setTags(response?.data?.data || []); + // Blog tags are stored as names on each blog; build the chip list from + // the tag names actually present in published blogs. + const response = await request.getBlogs({ page: 1, limit: 50 }); + const names = (response?.data || []).flatMap((b) => + Array.isArray(b.tags) ? b.tags : [] + ); + const uniqueNames = [...new Set(names)]; + setTags(uniqueNames.map((name) => ({ name }))); } catch (error) { console.error("Error fetching tags:", error); setTags([]); @@ -25,10 +27,10 @@ function Title({ onTagChange }) { fetchTags(); }, []); - const handleTagClick = (idx, tagId) => { + const handleTagClick = (idx, tagName) => { setActiveBtn(idx); if (onTagChange) { - onTagChange(tagId); + onTagChange(tagName); } }; @@ -43,11 +45,11 @@ function Title({ onTagChange }) { /> {tags.map((tag, idx) => ( handleTagClick(idx + 1, tag.id)} + setActiveBtn={() => handleTagClick(idx + 1, tag.name)} activeBtn={activeBtn} name={tag.name} idx={idx + 1} - key={tag.uuid} + key={tag.name} /> ))}