Skip to content

Commit

Permalink
Made a bunch of crap and trying to fix it somehow
Browse files Browse the repository at this point in the history
  • Loading branch information
dostonnabotov committed Nov 29, 2024
1 parent 15a4112 commit fa19b37
Show file tree
Hide file tree
Showing 18 changed files with 276 additions and 335 deletions.
13 changes: 10 additions & 3 deletions public/data/index.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
{
"languages": ["JavaScript", "Sass"]
}
[
{
"language": "Sass",
"icon": "/icons/sass.svg"
},
{
"language": "CSS",
"icon": "/icons/css.svg"
}
]
8 changes: 8 additions & 0 deletions public/icons/css.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions public/icons/sass.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
109 changes: 85 additions & 24 deletions src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,39 +1,100 @@
import Footer from "./layouts/Footer";
import Header from "./layouts/Header";
import SnippetList from "./components/SnippetList";
import Sidebar from "./layouts/Sidebar";
import { Navigate, useLocation } from "react-router-dom";
import SnippetModal from "./components/SnippetModal";
import Banner from "./layouts/Banner";
import { useState } from "react";
import Button from "./components/Button";
import { CopyIcon, ExpandIcon } from "./components/Icons";
import slugify from "./utils/slugify";
import { useLanguages } from "./hooks/useLanguages";
import { useCategories } from "./hooks/useCategories";
import { useSnippets } from "./hooks/useSnippets";

type LanguageType = {
language: string;
icon: string;
};

type SnippetType = {
title: string;
description: string;
code: string;
tags: string[];
author: string;
};

const App = () => {
const location = useLocation();
const [language, setLanguage] = useState<LanguageType>({
language: "Sass",
icon: "/icons/sass.svg",
});
const [category, setCategory] = useState<string>("");
const [snippet, setSnippet] = useState<SnippetType>();

const { fetchedLanguages } = useLanguages();
const { fetchedCategories } = useCategories(language.language);
const { fetchedSnippets } = useSnippets(language.language, category);

if (location.pathname === "/") {
return <Navigate to="/javascript/dom-manipulation" replace />;
}
const handleLanguageChange = (
event: React.ChangeEvent<HTMLSelectElement>
) => {
const language = fetchedLanguages.find(
(lan) => slugify(lan.language) === slugify(event.target.value)
);
if (language) {
setLanguage(language);
}
};

return (
<>
{/* Had to put the modal in App.tsx as well for it to work despite
it's also being created in HTML with portal.
If you know why it's that way, please let me know. */}
<SnippetModal />
{/* <SnippetModal /> */}
<div className="container flow" data-flow-space="xl">
<Header />
<div className="heading">
<h1 className="main-title">
Made to save your <span className="text-highlight">time.</span>
</h1>
<p>
Find the necessary snippet in seconds, across multiple languages.
Just search and copy!
</p>
</div>
<Banner />
<main className="main">
<Sidebar />
<SnippetList />
<aside className="sidebar flow">
<select
id="languages"
className="language-switcher"
onChange={handleLanguageChange}
>
{fetchedLanguages.map(({ language }) => (
<option key={language} value={slugify(language)}>
{language}
</option>
))}
</select>
<ul role="list" className="categories">
{fetchedCategories.map((name) => (
<li className="category">
<button onClick={() => setCategory(name)}>{name}</button>
</li>
))}
</ul>
</aside>
<section className="flow">
<h2 className="section-title">{category}</h2>
<ul role="list" className="snippets">
{fetchedSnippets.map((snippet) => (
<li className="snippet">
<div className="snippet__preview">
<img src={language.icon} alt={language.language} />
<Button isIcon={true} className="snippet__copy">
<CopyIcon />
</Button>
</div>

<div className="snippet__content">
<h3 className="snippet__title">{snippet.title}</h3>
<Button isIcon={true}>
<ExpandIcon />
</Button>
</div>
</li>
))}
</ul>
</section>
</main>
<hr className="divider" />
<Footer />
</div>
</>
Expand Down
18 changes: 0 additions & 18 deletions src/components/Category.tsx

This file was deleted.

45 changes: 0 additions & 45 deletions src/components/CategoryList.tsx

This file was deleted.

56 changes: 0 additions & 56 deletions src/components/LanguageSwitch.tsx

This file was deleted.

4 changes: 2 additions & 2 deletions src/components/Logo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ import { LogoIcon } from "./Icons";

const Logo = () => {
return (
<Link to={"/"} className="logo">
<a href="/" className="logo">
<LogoIcon />
<span>QuickSnip</span>
</Link>
</a>
);
};

Expand Down
26 changes: 0 additions & 26 deletions src/components/SnippetCard.tsx

This file was deleted.

57 changes: 0 additions & 57 deletions src/components/SnippetList.tsx

This file was deleted.

Loading

0 comments on commit fa19b37

Please sign in to comment.