Skip to content
This repository was archived by the owner on Sep 26, 2024. It is now read-only.

Commit dd860fe

Browse files
feat: Implemented the filter logic on the nav links (#57)
1 parent 48f8c23 commit dd860fe

7 files changed

+111
-17
lines changed

src/components/GridDisplay.jsx

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import React from "react";
2+
import PostGrid from "./PostGrid";
3+
4+
const GridDisplay = ({ fetchedData, activeLink }) => {
5+
return (
6+
<div>
7+
<div className=" container grid xs:grid-cols-1 sm:grid-cols-2 md:grid-cols-3 gap-4 ">
8+
{activeLink == "popular"
9+
? fetchedData.map((item, i) => <PostGrid data={item} key={i} />)
10+
: activeLink == "upvoted"
11+
? fetchedData.map((item, i) => <PostGrid data={item} key={i} />)
12+
: activeLink == "discussed"
13+
? fetchedData.sort((a, b) => b.issues - a.issues).map((item, i) => <PostGrid data={item} key={i} />)
14+
: fetchedData
15+
.sort((a, b) => a.avg_recency_score - b.avg_recency_score)
16+
.map((item, i) => <PostGrid data={item} key={i} />)}
17+
</div>
18+
</div>
19+
);
20+
};
21+
22+
export default GridDisplay;

src/components/LayoutToggle.jsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ function LayoutToggle({ gridState, setGridState }) {
44
const position = !!gridState ? "left-0" : "right-0";
55

66
return (
7-
<div className=" bg-darkestGrey md:pt-8 pb-5 md:pb-14">
7+
<div className=" bg-darkestGrey pt-4 md:pt-4 pb-5">
88
<div className="container flex justify-center ">
99
<div className="bg-saucyRed w-20 h-8 rounded-xl flex items-center cursor-pointer relative text-grey text-md ">
1010
<div className={"absolute bottom-0.1 w-10 h-10 rounded-xl bg-gray-100 " + position}></div>

src/components/ListDisplay.jsx

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import React from "react";
2+
import PostList from "./PostList";
3+
4+
const ListDisplay = ({ fetchedData, activeLink }) => {
5+
return (
6+
<div>
7+
<div className=" container space-y-3 ">
8+
{activeLink == "popular"
9+
? fetchedData.map((item, i) => <PostList data={item} key={i} />)
10+
: activeLink == "upvoted"
11+
? fetchedData.map((item, i) => <PostList data={item} key={i} />)
12+
: activeLink == "discussed"
13+
? fetchedData.sort((a, b) => b.issues - a.issues).map((item, i) => <PostList data={item} key={i} />)
14+
: fetchedData
15+
.sort((a, b) => a.avg_recency_score - b.avg_recency_score)
16+
.map((item, i) => <PostList data={item} key={i} />)}
17+
</div>
18+
</div>
19+
);
20+
};
21+
22+
export default ListDisplay;

src/components/PostList.jsx

-4
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,8 @@
11
import React from "react";
2-
import cover1 from "./placeholders/cover1.jpg";
3-
import cover2 from "./placeholders/cover2.jpg";
42
import humanizeNumber from "../lib/humanizeNumber";
53
import getAvatar from "../lib/getAvatar";
64

75
function PostList({ data }) {
8-
const [repoOwner, repoName] = data.repo_name.split("/");
9-
106
const repoLink = `https://github.com/${data.repo_name}`;
117
const handleClick = (option) => {
128
option === "issues" ? window.open(`${repoLink}/issues`) : window.open(repoLink);

src/components/PostsWrap.jsx

+9-10
Original file line numberDiff line numberDiff line change
@@ -4,26 +4,25 @@ import PostGrid from "./PostGrid.jsx";
44
import PostList from "./PostList.jsx";
55
import postData from "../data/hot.json";
66
import Modal from "../components/Modal";
7+
import SecondaryNav from "./SecondaryNav";
8+
import GridDisplay from "./GridDisplay";
9+
import ListDisplay from "./ListDisplay";
710

811
const PostsWrap = () => {
912
const [isGrid, setIsGrid] = useState(true);
13+
const [activeLink, setActiveLink] = useState("popular");
14+
const fetchedData = [...postData];
15+
1016
return (
1117
<>
1218
<Modal />
19+
<SecondaryNav activeLink={activeLink} setActiveLink={setActiveLink} />
1320
<LayoutToggle gridState={isGrid} setGridState={setIsGrid} />
1421
<div className="bg-darkestGrey py-6 w-full min-h-screen">
1522
{isGrid ? (
16-
<div className=" container grid xs:grid-cols-1 sm:grid-cols-2 md:grid-cols-3 gap-4 ">
17-
{postData.map((item, i) => (
18-
<PostGrid data={item} key={i} />
19-
))}
20-
</div>
23+
<GridDisplay fetchedData={fetchedData} activeLink={activeLink} />
2124
) : (
22-
<div className=" container space-y-3 ">
23-
{postData.map((item, i) => (
24-
<PostList data={item} key={i} />
25-
))}
26-
</div>
25+
<ListDisplay fetchedData={fetchedData} activeLink={activeLink} />
2726
)}
2827
</div>
2928
</>

src/components/SecondaryNav.jsx

+57
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
import React, { useState } from "react";
2+
3+
const SecondaryNav = ({ activeLink, setActiveLink }) => {
4+
const handleChange = (e) => {
5+
e.preventDefault();
6+
const linkName = e.target.getAttribute("data-name");
7+
setActiveLink(linkName);
8+
};
9+
return (
10+
<div>
11+
<div className="bg-darkestGrey py-14 md:py-16">
12+
<nav className="container">
13+
<ul className="flex flex-col space-y-2 sm:flex-row text-xl font-righteous text-accent font-bold justify-center items-center cursor-pointer">
14+
<li
15+
data-name="popular"
16+
onClick={(e) => handleChange(e)}
17+
className={`${
18+
activeLink === "popular" ? "bg-cheesyYellow rounded-xl text-grey " : " "
19+
} hover:text-saucyRed transition-all duration-300 mr-3 p-2 sm:mr-11`}
20+
>
21+
Popular
22+
</li>
23+
<li
24+
data-name="upvoted"
25+
onClick={(e) => handleChange(e)}
26+
className={`${
27+
activeLink === "upvoted" ? "bg-cheesyYellow rounded-xl text-grey " : " "
28+
} hover:text-saucyRed transition-all duration-300 mr-3 p-2 sm:mr-11`}
29+
>
30+
Upvoted
31+
</li>
32+
<li
33+
data-name="discussed"
34+
onClick={(e) => handleChange(e)}
35+
className={`${
36+
activeLink === "discussed" ? "bg-cheesyYellow rounded-xl text-grey " : " "
37+
} hover:text-saucyRed transition-all duration-300 mr-3 p-2 sm:mr-11`}
38+
>
39+
Discussed
40+
</li>
41+
<li
42+
data-name="recent"
43+
onClick={(e) => handleChange(e)}
44+
className={`${
45+
activeLink === "recent" ? "bg-cheesyYellow rounded-xl text-grey " : " "
46+
} hover:text-saucyRed transition-all duration-300 mr-3 p-2 sm:mr-11`}
47+
>
48+
Recent
49+
</li>
50+
</ul>
51+
</nav>
52+
</div>
53+
</div>
54+
);
55+
};
56+
57+
export default SecondaryNav;

src/pages/index.astro

-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
// Component Imports
33
44
import PrimaryNav from '../components/PrimaryNav.astro';
5-
import SecondaryNav from '../components/SecondaryNav.astro';
65
import PostsWrap from '../components/PostsWrap.jsx';
76
87
@@ -49,7 +48,6 @@ let social_card = 'https://repository-images.githubusercontent.com/71359796/179e
4948
<!-- page -->
5049
<main>
5150
<PrimaryNav />
52-
<SecondaryNav />
5351
<PostsWrap client:load />
5452
</main>
5553
</body>

0 commit comments

Comments
 (0)