File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ {
2+ "pageName" : " CSS Resources" ,
3+ "entries" : [
4+ {
5+ "title" : " CSS Official Docs" ,
6+ "url" : " https://developer.mozilla.org/en-US/docs/Web/CSS" ,
7+ "tags" : [" css" , " official docs" ]
8+ },
9+ {
10+ "title" : " Tailwind Official Docs" ,
11+ "url" : " https://tailwindcss.com" ,
12+ "tags" : [" css" , " official docs" , " tailwind" ]
13+ },
14+ {
15+ "title" : " CSS Flexbox Layout Guide" ,
16+ "url" : " https://css-tricks.com/snippets/css/a-guide-to-flexbox/" ,
17+ "tags" : [" css" , " cheatsheet" ]
18+ }
19+ ]
20+ }
Original file line number Diff line number Diff line change @@ -5,6 +5,8 @@ import "./index.css";
55import Layout from "./components/Layout" ;
66import Home from "./routes/Home" ;
77import About from "./routes/About" ;
8+ import Resources from "./routes/Resources" ;
9+ import ResourcePage from "./routes/Resources/ResourcePage" ;
810
911const root = document . getElementById ( "root" ) ;
1012
@@ -16,6 +18,8 @@ if (root) {
1618 < Route element = { < Layout /> } >
1719 < Route index element = { < Home /> } />
1820 < Route path = "/about" element = { < About /> } />
21+ < Route path = "/resources" element = { < Resources /> } />
22+ < Route path = "/resources/:category" element = { < ResourcePage /> } />
1923 </ Route >
2024 </ Routes >
2125 </ BrowserRouter >
Original file line number Diff line number Diff line change 1+ import { Link } from "react-router" ;
2+
3+ interface Props {
4+ name : string ;
5+ slug : string ;
6+ }
7+
8+ const CategoryCard = ( { name, slug } : Props ) => {
9+ return (
10+ < >
11+ < Link
12+ to = { slug }
13+ className = "my-4 min-w-[50%] rounded-lg border-2 border-primary px-6 py-12 text-center text-2xl shadow-lg shadow-primary hover:bg-primary hover:text-accent hover:shadow-2xl hover:shadow-primary"
14+ >
15+ { name }
16+ </ Link >
17+ </ >
18+ ) ;
19+ } ;
20+
21+ export default CategoryCard ;
Original file line number Diff line number Diff line change 1+ import { useEffect , useState } from "react" ;
2+ import { useParams } from "react-router" ;
3+
4+ interface JsonData {
5+ pageName : string ;
6+ entries : Entry [ ] ;
7+ }
8+
9+ interface Entry {
10+ title : string ;
11+ url : string ;
12+ tags : string [ ] ;
13+ }
14+
15+ const ResourcePage = ( ) => {
16+ const { category } = useParams ( ) ;
17+ const [ data , setData ] = useState < JsonData | null > ( null ) ;
18+
19+ useEffect ( ( ) => {
20+ const fetchData = async ( ) => {
21+ if ( category ) {
22+ const dataObject = ( await import (
23+ `../../data/resources/${ category } .json`
24+ ) ) as { default : JsonData } ;
25+ return dataObject . default ;
26+ } else {
27+ return { pageName : "" , entries : [ ] } ;
28+ }
29+ } ;
30+
31+ fetchData ( ) . then (
32+ ( json ) => {
33+ setData ( json ) ;
34+ } ,
35+ ( ) => {
36+ setData ( { pageName : "" , entries : [ ] } ) ;
37+ } ,
38+ ) ;
39+ } , [ category ] ) ;
40+
41+ if ( data ) {
42+ return (
43+ < >
44+ < section className = "h-2/3 bg-background" >
45+ < h3 className = "text-xl text-accent" > { data . pageName } </ h3 >
46+ { data . entries . map ( ( e ) => e . title ) }
47+ </ section >
48+ </ >
49+ ) ;
50+ }
51+ } ;
52+ export default ResourcePage ;
Original file line number Diff line number Diff line change 1+ import CategoryCard from "./CategoryCard" ;
2+
3+ const Resources = ( ) => (
4+ < main className = "flex h-full w-full flex-col" >
5+ < section className = "flex h-full flex-col justify-center" >
6+ < h3 className = "my-12 text-center text-3xl text-secondary" > Resources</ h3 >
7+ < div className = "grid w-full grid-cols-3 place-items-center gap-y-6 bg-background" >
8+ < CategoryCard name = "HTML" slug = "html" />
9+ < CategoryCard name = "CSS" slug = "css" />
10+ < CategoryCard name = "JavaScript" slug = "javascript" />
11+ < CategoryCard name = "Python" slug = "python" />
12+ < CategoryCard name = "Java" slug = "java" />
13+ < CategoryCard name = "C++" slug = "c-plus-plus" />
14+ </ div >
15+ </ section >
16+ </ main >
17+ ) ;
18+
19+ export default Resources ;
You can’t perform that action at this time.
0 commit comments