-
Notifications
You must be signed in to change notification settings - Fork 2
[RFC] Resources page proof of concept #52
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
e0a4de7
make all pages full height
aedwardg 91f595e
remove unused file
aedwardg 8405a54
update footer
aedwardg 4a76db6
update header
aedwardg 10687e7
render categories on resource page and read from json file
aedwardg 14d476d
render resource page with cards for each json entry
aedwardg 2765927
add more tags for testing
aedwardg 8ec5ed6
adjust ResourceCard and ResourcePage css for responsiveness
aedwardg 4106cbf
sort resource entries
aedwardg bdac6c6
add initial resources for html and js
aedwardg 9a048a4
add basic filter-by-tag functionality
aedwardg File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| { | ||
| "pageName": "CSS Resources", | ||
| "entries": [ | ||
| { | ||
| "title": "CSS Official Docs", | ||
| "url": "https://developer.mozilla.org/en-US/docs/Web/CSS", | ||
| "tags": ["css", "official docs"] | ||
| }, | ||
| { | ||
| "title": "Tailwind Official Docs", | ||
| "url": "https://tailwindcss.com", | ||
| "tags": [ | ||
| "css", | ||
| "official docs", | ||
| "tailwind", | ||
| "test1", | ||
| "test2", | ||
| "test3", | ||
| "test4", | ||
| "test5", | ||
| "test6" | ||
| ] | ||
| }, | ||
| { | ||
| "title": "CSS Flexbox Layout Guide", | ||
| "url": "https://css-tricks.com/snippets/css/a-guide-to-flexbox/", | ||
| "tags": ["css", "cheatsheet"] | ||
| } | ||
| ] | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| { | ||
| "pageName": "HTML Resources", | ||
| "entries": [ | ||
| { | ||
| "title": "HTML Official Docs", | ||
| "url": "https://developer.mozilla.org/en-US/docs/Web/HTML", | ||
| "tags": ["html", "official docs"] | ||
| } | ||
| ] | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| { | ||
| "pageName": "JavaScript Resources", | ||
| "entries": [ | ||
| { | ||
| "title": "JavaScript Official Docs", | ||
| "url": "https://developer.mozilla.org/en-US/docs/Web/JavaScript", | ||
| "tags": ["javascript", "official docs"] | ||
| }, | ||
| { | ||
| "title": "javacript.info", | ||
| "url": "https://javascript.info", | ||
| "tags": ["javascript", "crash course"] | ||
| } | ||
| ] | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| import { Link } from "react-router"; | ||
|
|
||
| interface Props { | ||
| name: string; | ||
| slug: string; | ||
| } | ||
|
|
||
| const CategoryCard = ({ name, slug }: Props) => { | ||
| return ( | ||
| <> | ||
| <Link | ||
| to={slug} | ||
| 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" | ||
| > | ||
| {name} | ||
| </Link> | ||
| </> | ||
| ); | ||
| }; | ||
|
|
||
| export default CategoryCard; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| import { Entry } from "./types"; | ||
|
|
||
| const ResourceCard = ({ entry }: { entry: Entry }) => { | ||
| return ( | ||
| <div className="min-h-24 w-96 rounded-md bg-slate-400 text-center shadow-lg shadow-gray-600 hover:shadow-2xl hover:shadow-gray-600"> | ||
| <a | ||
| href={entry.url} | ||
| target="_blank" | ||
| rel="noreferrer" | ||
| className="flex h-full w-full flex-col justify-around px-6 py-4" | ||
| > | ||
| <p className="pb-4 text-xl text-primary">{entry.title}</p> | ||
| <div className="flex flex-wrap justify-center gap-2"> | ||
| {entry.tags.map((t) => ( | ||
| <div | ||
| key={t} | ||
| className="rounded-xl border-transparent bg-slate-300 px-2 pb-1" | ||
| > | ||
| {t} | ||
| </div> | ||
| ))} | ||
| </div> | ||
| </a> | ||
| </div> | ||
| ); | ||
| }; | ||
| export default ResourceCard; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,92 @@ | ||
| import { useEffect, useState } from "react"; | ||
| import { useParams } from "react-router"; | ||
| import { JsonData, Entry } from "./types"; | ||
| import ResourceCard from "./ResourceCard"; | ||
| import { extractTags, sortEntries } from "./utils"; | ||
|
|
||
| const ResourcePage = () => { | ||
| const { category } = useParams(); | ||
| const [data, setData] = useState<JsonData | null>(null); | ||
| const [entries, setEntries] = useState<Entry[]>([]); | ||
| const [tags, setTags] = useState<string[]>([]); | ||
| const [filters, setFilters] = useState<string[]>([]); | ||
|
|
||
| useEffect(() => { | ||
| const fetchData = async () => { | ||
| if (category) { | ||
| const dataObject = (await import( | ||
| `../../data/resources/${category}.json` | ||
| )) as { default: JsonData }; | ||
| return dataObject.default; | ||
| } else { | ||
| return { pageName: "", entries: [] }; | ||
| } | ||
| }; | ||
|
|
||
| fetchData() | ||
| .then((json) => { | ||
| if (json.entries.length > 0) { | ||
| setData(json); | ||
| setEntries(sortEntries(json.entries)); | ||
| setTags(extractTags(json.entries)); | ||
| } | ||
| }) | ||
| .catch(console.error); | ||
| }, [category]); | ||
|
|
||
| const filterColor = (tag: string) => | ||
| filters.includes(tag) ? "bg-slate-400" : "bg-slate-300"; | ||
|
|
||
| if (data) { | ||
| return ( | ||
| <> | ||
| <section className="w-full bg-background"> | ||
| <h3 className="my-12 text-center text-4xl text-primary"> | ||
| {data.pageName} | ||
| </h3> | ||
| <div className="mb-6 flex w-full flex-col items-center justify-center text-center"> | ||
| <h4 className="text-xl font-bold text-primary">Categories</h4> | ||
| <div className="mt-4 flex w-96 flex-wrap justify-center gap-2 xl:w-[600px]"> | ||
| {tags.map((t) => ( | ||
| <div | ||
| key={t} | ||
| onClick={() => { | ||
| setFilters([...filters, t]); | ||
| setEntries(entries.filter((e) => e.tags.includes(t))); | ||
| }} | ||
| > | ||
| <button | ||
| className={`rounded-xl border-transparent bg-slate-300 px-2 pb-1 ${filterColor(t)}`} | ||
| > | ||
| {t} | ||
| </button> | ||
| </div> | ||
| ))} | ||
| {filters.length > 0 && ( | ||
| <button | ||
| className="rounded-xl bg-accent px-2 pb-1 text-primary" | ||
| onClick={() => { | ||
| setFilters([]); | ||
| setEntries(sortEntries(data.entries)); | ||
| }} | ||
| > | ||
| Clear filters × | ||
| </button> | ||
| )} | ||
| </div> | ||
| </div> | ||
| <div className="flex w-full justify-center pb-12"> | ||
| <div className="mx-4 flex flex-wrap justify-center gap-6 sm:w-5/6 xl:w-3/4"> | ||
| {entries.map((e) => ( | ||
| <ResourceCard entry={e} key={e.title} /> | ||
| ))} | ||
| </div> | ||
| </div> | ||
| </section> | ||
| </> | ||
| ); | ||
| } | ||
|
|
||
| return <></>; | ||
| }; | ||
| export default ResourcePage; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| import CategoryCard from "./CategoryCard"; | ||
|
|
||
| const Resources = () => ( | ||
| <main className="flex h-full w-full flex-col"> | ||
| <section className="flex h-full flex-col justify-center"> | ||
| <h3 className="my-12 text-center text-3xl text-secondary">Resources</h3> | ||
| <div className="flex w-full justify-center bg-background"> | ||
| <div className="grid grid-cols-3 place-items-center gap-y-6 sm:w-5/6 xl:w-3/4"> | ||
| <CategoryCard name="HTML" slug="html" /> | ||
| <CategoryCard name="CSS" slug="css" /> | ||
| <CategoryCard name="JavaScript" slug="javascript" /> | ||
| <CategoryCard name="Python" slug="python" /> | ||
| <CategoryCard name="Java" slug="java" /> | ||
| <CategoryCard name="C++" slug="c-plus-plus" /> | ||
| </div> | ||
| </div> | ||
| </section> | ||
| </main> | ||
| ); | ||
|
|
||
| export default Resources; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| export interface JsonData { | ||
| pageName: string; | ||
| entries: Entry[]; | ||
| } | ||
|
|
||
| export interface Entry { | ||
| title: string; | ||
| url: string; | ||
| tags: string[]; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| import { Entry } from "./types"; | ||
|
|
||
| export const sortEntries = (entries: Entry[]) => | ||
| entries.sort((a, b) => (sanitize(a.title) < sanitize(b.title) ? -1 : 1)); | ||
|
|
||
| const sanitize = (title: string) => | ||
| title.toLowerCase().replace("the", "").trim(); | ||
|
|
||
| export const extractTags = (entries: Entry[]) => [ | ||
| ...new Set( | ||
| entries.reduce<string[]>((acc, cur) => { | ||
| acc.push(...cur.tags); | ||
| return acc; | ||
| }, []), | ||
| ), | ||
| ]; |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Probably the only suggestion I would add is for an extra button on the resource page to return to all the categories
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cool, I'll open up a ticket for that so we don't make this PR any bigger 👍