Skip to content

Commit fa19b37

Browse files
committed
Made a bunch of crap and trying to fix it somehow
1 parent 15a4112 commit fa19b37

18 files changed

+276
-335
lines changed

public/data/index.json

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1-
{
2-
"languages": ["JavaScript", "Sass"]
3-
}
1+
[
2+
{
3+
"language": "Sass",
4+
"icon": "/icons/sass.svg"
5+
},
6+
{
7+
"language": "CSS",
8+
"icon": "/icons/css.svg"
9+
}
10+
]

public/icons/css.svg

Lines changed: 8 additions & 0 deletions
Loading

public/icons/sass.svg

Lines changed: 3 additions & 0 deletions
Loading

src/App.tsx

Lines changed: 85 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,100 @@
11
import Footer from "./layouts/Footer";
22
import Header from "./layouts/Header";
3-
import SnippetList from "./components/SnippetList";
4-
import Sidebar from "./layouts/Sidebar";
5-
import { Navigate, useLocation } from "react-router-dom";
6-
import SnippetModal from "./components/SnippetModal";
3+
import Banner from "./layouts/Banner";
4+
import { useState } from "react";
5+
import Button from "./components/Button";
6+
import { CopyIcon, ExpandIcon } from "./components/Icons";
7+
import slugify from "./utils/slugify";
8+
import { useLanguages } from "./hooks/useLanguages";
9+
import { useCategories } from "./hooks/useCategories";
10+
import { useSnippets } from "./hooks/useSnippets";
11+
12+
type LanguageType = {
13+
language: string;
14+
icon: string;
15+
};
16+
17+
type SnippetType = {
18+
title: string;
19+
description: string;
20+
code: string;
21+
tags: string[];
22+
author: string;
23+
};
724

825
const App = () => {
9-
const location = useLocation();
26+
const [language, setLanguage] = useState<LanguageType>({
27+
language: "Sass",
28+
icon: "/icons/sass.svg",
29+
});
30+
const [category, setCategory] = useState<string>("");
31+
const [snippet, setSnippet] = useState<SnippetType>();
32+
33+
const { fetchedLanguages } = useLanguages();
34+
const { fetchedCategories } = useCategories(language.language);
35+
const { fetchedSnippets } = useSnippets(language.language, category);
1036

11-
if (location.pathname === "/") {
12-
return <Navigate to="/javascript/dom-manipulation" replace />;
13-
}
37+
const handleLanguageChange = (
38+
event: React.ChangeEvent<HTMLSelectElement>
39+
) => {
40+
const language = fetchedLanguages.find(
41+
(lan) => slugify(lan.language) === slugify(event.target.value)
42+
);
43+
if (language) {
44+
setLanguage(language);
45+
}
46+
};
1447

1548
return (
1649
<>
17-
{/* Had to put the modal in App.tsx as well for it to work despite
18-
it's also being created in HTML with portal.
19-
If you know why it's that way, please let me know. */}
20-
<SnippetModal />
50+
{/* <SnippetModal /> */}
2151
<div className="container flow" data-flow-space="xl">
2252
<Header />
23-
<div className="heading">
24-
<h1 className="main-title">
25-
Made to save your <span className="text-highlight">time.</span>
26-
</h1>
27-
<p>
28-
Find the necessary snippet in seconds, across multiple languages.
29-
Just search and copy!
30-
</p>
31-
</div>
53+
<Banner />
3254
<main className="main">
33-
<Sidebar />
34-
<SnippetList />
55+
<aside className="sidebar flow">
56+
<select
57+
id="languages"
58+
className="language-switcher"
59+
onChange={handleLanguageChange}
60+
>
61+
{fetchedLanguages.map(({ language }) => (
62+
<option key={language} value={slugify(language)}>
63+
{language}
64+
</option>
65+
))}
66+
</select>
67+
<ul role="list" className="categories">
68+
{fetchedCategories.map((name) => (
69+
<li className="category">
70+
<button onClick={() => setCategory(name)}>{name}</button>
71+
</li>
72+
))}
73+
</ul>
74+
</aside>
75+
<section className="flow">
76+
<h2 className="section-title">{category}</h2>
77+
<ul role="list" className="snippets">
78+
{fetchedSnippets.map((snippet) => (
79+
<li className="snippet">
80+
<div className="snippet__preview">
81+
<img src={language.icon} alt={language.language} />
82+
<Button isIcon={true} className="snippet__copy">
83+
<CopyIcon />
84+
</Button>
85+
</div>
86+
87+
<div className="snippet__content">
88+
<h3 className="snippet__title">{snippet.title}</h3>
89+
<Button isIcon={true}>
90+
<ExpandIcon />
91+
</Button>
92+
</div>
93+
</li>
94+
))}
95+
</ul>
96+
</section>
3597
</main>
36-
<hr className="divider" />
3798
<Footer />
3899
</div>
39100
</>

src/components/Category.tsx

Lines changed: 0 additions & 18 deletions
This file was deleted.

src/components/CategoryList.tsx

Lines changed: 0 additions & 45 deletions
This file was deleted.

src/components/LanguageSwitch.tsx

Lines changed: 0 additions & 56 deletions
This file was deleted.

src/components/Logo.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@ import { LogoIcon } from "./Icons";
33

44
const Logo = () => {
55
return (
6-
<Link to={"/"} className="logo">
6+
<a href="/" className="logo">
77
<LogoIcon />
88
<span>QuickSnip</span>
9-
</Link>
9+
</a>
1010
);
1111
};
1212

src/components/SnippetCard.tsx

Lines changed: 0 additions & 26 deletions
This file was deleted.

src/components/SnippetList.tsx

Lines changed: 0 additions & 57 deletions
This file was deleted.

0 commit comments

Comments
 (0)