-
Notifications
You must be signed in to change notification settings - Fork 55
/
BlogPage.jsx
136 lines (131 loc) · 5.17 KB
/
BlogPage.jsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
import React from 'react'
import { useState } from 'react'
import SingleBlog from '../components/SingleBlog';
const BlogPage = () => {
const [activeTab, setActiveTab] = useState("latest")
const [blogs, setblogs] = useState([
{
id: 1,
title: "Lorem Ipsum Blog latest-blog",
content: "Lorem ipsum dolor sit amet, consectetur adipiscing elit...",
author: "John Doe",
publication_date: "2024-05-03",
tag:"latest"
},
{
id: 2,
title: "Lorem Ipsum Blog latest blog",
content: "Lorem ipsum dolor sit amet, consectetur adipiscing elit...",
author: "John Doe",
publication_date: "2024-05-03",
tag:"latest"
},
{
id: 3,
title: "Lorem Ipsum Blog latest blog",
content: "Lorem ipsum dolor sit amet, consectetur adipiscing elit...",
author: "John Doe",
publication_date: "2024-05-03",
tag:"latest"
},
{
id: 4,
title: "Lorem Ipsum Blog latest blog",
content: "Lorem ipsum dolor sit amet, consectetur adipiscing elit...",
author: "John Doe",
publication_date: "2024-05-03",
tag:"latest"
},
{
id: 5,
title: "Lorem Ipsum Blog trending blog",
content: "Lorem ipsum dolor sit amet, consectetur adipiscing elit...",
author: "John Doe",
publication_date: "2024-05-03",
tag:"trending"
},
{
id: 6,
title: "Lorem Ipsum Blog trending blog",
content: "Lorem ipsum dolor sit amet, consectetur adipiscing elit...",
author: "John Doe",
publication_date: "2024-05-03",
tag:"trending"
},
{
id: 7,
title: "Lorem Ipsum Blog trending blog",
content: "Lorem ipsum dolor sit amet, consectetur adipiscing elit...",
author: "John Doe",
publication_date: "2024-05-03",
tag:"trending"
},
{
id: 8,
title: "Lorem Ipsum Blog top blog",
content: "Lorem ipsum dolor sit amet, consectetur adipiscing elit...",
author: "John Doe",
publication_date: "2024-05-03",
tag:"top"
},
{
id: 9,
title: "Lorem Ipsum Blog top blog",
content: "Lorem ipsum dolor sit amet, consectetur adipiscing elit...",
author: "John Doe",
publication_date: "2024-05-03",
tag:"top"
},
{
id: 10,
title: "Lorem Ipsum Blog top blog",
content: "Lorem ipsum dolor sit amet, consectetur adipiscing elit...",
author: "John Doe",
publication_date: "2024-05-03",
tag:"top"
},
// Add more blog objects as needed
]);
const blogsGroupedByTags = Object.groupBy(blogs, ({tag})=> tag)
const handleTabClick = (e)=>{
console.log(e.target.id)
const previousActiveButton= document.querySelector(`#${activeTab + "Tab"}`)
const previousActiveContainer = document.querySelector(`#${activeTab + "TabContainer"}`)
const activeContainer = document.querySelector(`#${e.target.id + "Container"}`)
const buttonValue = e.target.textContent.toLowerCase();
if(activeTab!==buttonValue){
previousActiveButton.classList.add("text-gray-600")
previousActiveContainer.classList.remove("border-black")
activeContainer.classList.add("border-black")
e.target.classList.remove("text-gray-600")
setActiveTab(buttonValue)
}
}
return (
<>
<div className="grid grid-cols-3 lg:w-1/2 xl:w-1/4 md:w-2/3 w-5/6 mx-auto align-items-center justify-items-center">
<div id="topTabContainer" className="border-b-2 w-full text-center transition-border duration-300">
<button id="topTab" className="relative p-0 m-0 border-0 bg-transparent w-full h-full text-gray-600" onClick={(e)=>handleTabClick(e)}>
<h1 className="sticky top-0 left-0 z-[-1] text-2xl font-bold mb-4 mt-10 text-center transition-color duration-300">Top</h1>
</button>
</div>
<div id="trendingTabContainer" className="border-b-2 w-full text-center transition-border duration-300">
<button id="trendingTab" className="relative p-0 m-0 border-0 bg-transparent w-full h-full relative z-1 text-gray-600" onClick={(e)=>handleTabClick(e)}>
<h1 className="sticky top-0 left-0 z-[-1] text-2xl font-bold mb-4 mt-10 text-center transition-color duration-300">Trending</h1>
</button>
</div>
<div id="latestTabContainer" className="border-b-2 w-full border-black text-center transition-border duration-300">
<button id="latestTab" className="relative p-0 m-0 border-0 bg-transparent w-full h-full" onClick={(e)=>handleTabClick(e)}>
<h1 className="sticky top-0 left-0 w-full z-[-1] text-2xl font-bold mb-4 mt-10 text-center transition-color duration-300">Latest</h1>
</button>
</div>
</div>
<div class="container mx-auto px-4 py-8 w-full">
<div class="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-10 w-[80%] mx-auto">
{blogsGroupedByTags[activeTab].map((blog)=> <SingleBlog blog={blog}/>)}
</div>
</div>
</>
)
}
export default BlogPage