This repository was archived by the owner on Sep 26, 2024. It is now read-only.
File tree 7 files changed +111
-17
lines changed
7 files changed +111
-17
lines changed Original file line number Diff line number Diff line change
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 ;
Original file line number Diff line number Diff line change @@ -4,7 +4,7 @@ function LayoutToggle({ gridState, setGridState }) {
4
4
const position = ! ! gridState ? "left-0" : "right-0" ;
5
5
6
6
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" >
8
8
< div className = "container flex justify-center " >
9
9
< div className = "bg-saucyRed w-20 h-8 rounded-xl flex items-center cursor-pointer relative text-grey text-md " >
10
10
< div className = { "absolute bottom-0.1 w-10 h-10 rounded-xl bg-gray-100 " + position } > </ div >
Original file line number Diff line number Diff line change
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 ;
Original file line number Diff line number Diff line change 1
1
import React from "react" ;
2
- import cover1 from "./placeholders/cover1.jpg" ;
3
- import cover2 from "./placeholders/cover2.jpg" ;
4
2
import humanizeNumber from "../lib/humanizeNumber" ;
5
3
import getAvatar from "../lib/getAvatar" ;
6
4
7
5
function PostList ( { data } ) {
8
- const [ repoOwner , repoName ] = data . repo_name . split ( "/" ) ;
9
-
10
6
const repoLink = `https://github.com/${ data . repo_name } ` ;
11
7
const handleClick = ( option ) => {
12
8
option === "issues" ? window . open ( `${ repoLink } /issues` ) : window . open ( repoLink ) ;
Original file line number Diff line number Diff line change @@ -4,26 +4,25 @@ import PostGrid from "./PostGrid.jsx";
4
4
import PostList from "./PostList.jsx" ;
5
5
import postData from "../data/hot.json" ;
6
6
import Modal from "../components/Modal" ;
7
+ import SecondaryNav from "./SecondaryNav" ;
8
+ import GridDisplay from "./GridDisplay" ;
9
+ import ListDisplay from "./ListDisplay" ;
7
10
8
11
const PostsWrap = ( ) => {
9
12
const [ isGrid , setIsGrid ] = useState ( true ) ;
13
+ const [ activeLink , setActiveLink ] = useState ( "popular" ) ;
14
+ const fetchedData = [ ...postData ] ;
15
+
10
16
return (
11
17
< >
12
18
< Modal />
19
+ < SecondaryNav activeLink = { activeLink } setActiveLink = { setActiveLink } />
13
20
< LayoutToggle gridState = { isGrid } setGridState = { setIsGrid } />
14
21
< div className = "bg-darkestGrey py-6 w-full min-h-screen" >
15
22
{ 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 } />
21
24
) : (
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 } />
27
26
) }
28
27
</ div >
29
28
</ >
Original file line number Diff line number Diff line change
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 ;
Original file line number Diff line number Diff line change 2
2
// Component Imports
3
3
4
4
import PrimaryNav from ' ../components/PrimaryNav.astro' ;
5
- import SecondaryNav from ' ../components/SecondaryNav.astro' ;
6
5
import PostsWrap from ' ../components/PostsWrap.jsx' ;
7
6
8
7
@@ -49,7 +48,6 @@ let social_card = 'https://repository-images.githubusercontent.com/71359796/179e
49
48
<!-- page -->
50
49
<main >
51
50
<PrimaryNav />
52
- <SecondaryNav />
53
51
<PostsWrap client:load />
54
52
</main >
55
53
</body >
You can’t perform that action at this time.
0 commit comments