From 570cbb61b8bae7866aaca9270e4403417032b20b Mon Sep 17 00:00:00 2001 From: * Date: Mon, 1 Jan 2024 15:01:04 +0700 Subject: [PATCH] Widget Component refactory --- src/components/widget/Category.js | 11 +++++------ src/components/widget/Search.js | 13 ++++++++++-- src/components/widget/Tag.js | 33 ++++++++++++++++++++----------- 3 files changed, 38 insertions(+), 19 deletions(-) diff --git a/src/components/widget/Category.js b/src/components/widget/Category.js index 340952bc..b30f5ca2 100644 --- a/src/components/widget/Category.js +++ b/src/components/widget/Category.js @@ -1,17 +1,16 @@ import { Link } from 'react-router-dom'; +import posts from './../../data/posts'; export default function Category() { + const categories = [...new Set(posts.map(post => post.category.title))]; return ( <>

Categories

diff --git a/src/components/widget/Search.js b/src/components/widget/Search.js index 9fb25f15..3ee56162 100644 --- a/src/components/widget/Search.js +++ b/src/components/widget/Search.js @@ -1,10 +1,19 @@ +import { useSearchParams } from 'react-router-dom'; + export default function Search() { + let [searchParams, setSearchParams] = useSearchParams(); + const handleSubmit = (e) => { + e.preventDefault(); + // let params = serializeFormQuery(event.target); + // setSearchParams(params); + } + return ( <>

Search

-
- + +
diff --git a/src/components/widget/Tag.js b/src/components/widget/Tag.js index 28e45af1..1bb1bcdf 100644 --- a/src/components/widget/Tag.js +++ b/src/components/widget/Tag.js @@ -1,22 +1,33 @@ import { Link } from 'react-router-dom'; +import posts from './../../data/posts'; export default function Tag() { + let newArr; + let arr = [...new Set(posts.map(post => post.tag))]; + + arr.map(val => newArr = val.split(',')) + + let removeDuplicate = (data) => { + let duplicates = data.reduce((acc, el, i, arr) => { + if(arr.indexOf(el) !== i && acc.indexOf(el) < 0) { + acc.push(el); + } + return acc; + },[]); + return duplicates; + } + + removeDuplicate(newArr); + let tags = newArr; + return ( <>

Tags