Skip to content

Commit 14d476d

Browse files
committed
render resource page with cards for each json entry
1 parent 10687e7 commit 14d476d

5 files changed

Lines changed: 60 additions & 22 deletions

File tree

src/data/resources/css.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
{
1010
"title": "Tailwind Official Docs",
1111
"url": "https://tailwindcss.com",
12-
"tags": ["css", "official docs", "tailwind"]
12+
"tags": ["css", "official docs", "tailwind", "test1", "test2", "test3"]
1313
},
1414
{
1515
"title": "CSS Flexbox Layout Guide",
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import { Entry } from "./types";
2+
3+
const ResourceCard = ({ entry }: { entry: Entry }) => {
4+
return (
5+
<div className="min-h-24 min-w-56 rounded-md bg-slate-400 text-center shadow-lg shadow-gray-600 hover:shadow-2xl hover:shadow-gray-600">
6+
<a
7+
href={entry.url}
8+
target="_blank"
9+
rel="noreferrer"
10+
className="flex h-full w-full flex-col justify-around px-6 py-4"
11+
>
12+
<p className="pb-4 text-xl text-primary">{entry.title}</p>
13+
<div className="flex flex-wrap justify-center gap-2">
14+
{entry.tags.map((t) => (
15+
<div
16+
key={t}
17+
className="rounded-xl border-transparent bg-slate-300 px-2 pb-1"
18+
>
19+
{t}
20+
</div>
21+
))}
22+
</div>
23+
</a>
24+
</div>
25+
);
26+
};
27+
export default ResourceCard;

src/routes/Resources/ResourcePage.tsx

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,7 @@
11
import { useEffect, useState } from "react";
22
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-
}
3+
import { JsonData } from "./types";
4+
import ResourceCard from "./ResourceCard";
145

156
const ResourcePage = () => {
167
const { category } = useParams();
@@ -41,9 +32,17 @@ const ResourcePage = () => {
4132
if (data) {
4233
return (
4334
<>
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)}
35+
<section className="h-2/3 w-full bg-background">
36+
<h3 className="my-12 text-center text-4xl text-primary">
37+
{data.pageName}
38+
</h3>
39+
<div className="flex w-full justify-center">
40+
<div className="mx-4 grid grid-cols-3 gap-x-4 sm:w-5/6 xl:w-3/4">
41+
{data.entries.map((e) => (
42+
<ResourceCard entry={e} key={e.title} />
43+
))}
44+
</div>
45+
</div>
4746
</section>
4847
</>
4948
);

src/routes/Resources/index.tsx

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,15 @@ const Resources = () => (
44
<main className="flex h-full w-full flex-col">
55
<section className="flex h-full flex-col justify-center">
66
<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" />
7+
<div className="flex w-full justify-center bg-background">
8+
<div className="grid grid-cols-3 place-items-center gap-y-6 sm:w-5/6 xl:w-3/4">
9+
<CategoryCard name="HTML" slug="html" />
10+
<CategoryCard name="CSS" slug="css" />
11+
<CategoryCard name="JavaScript" slug="javascript" />
12+
<CategoryCard name="Python" slug="python" />
13+
<CategoryCard name="Java" slug="java" />
14+
<CategoryCard name="C++" slug="c-plus-plus" />
15+
</div>
1416
</div>
1517
</section>
1618
</main>

src/routes/Resources/types.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
export interface JsonData {
2+
pageName: string;
3+
entries: Entry[];
4+
}
5+
6+
export interface Entry {
7+
title: string;
8+
url: string;
9+
tags: string[];
10+
}

0 commit comments

Comments
 (0)