|
1 | 1 | import Footer from "./layouts/Footer"; |
2 | 2 | import Header from "./layouts/Header"; |
3 | 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 | | -}; |
| 4 | +import LanguageSelector from "./components/LanguageSelector"; |
| 5 | +import CategoryList from "./components/CategoryList"; |
| 6 | +import { useAppContext } from "./contexts/AppContext"; |
| 7 | +import SnippetList from "./components/SnippetList"; |
24 | 8 |
|
25 | 9 | const App = () => { |
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); |
36 | | - |
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 | | - }; |
| 10 | + const { category } = useAppContext(); |
47 | 11 |
|
48 | 12 | return ( |
49 | 13 | <> |
50 | | - {/* <SnippetModal /> */} |
51 | 14 | <div className="container flow" data-flow-space="xl"> |
52 | 15 | <Header /> |
53 | 16 | <Banner /> |
54 | 17 | <main className="main"> |
55 | 18 | <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> |
| 19 | + <LanguageSelector /> |
| 20 | + <CategoryList /> |
74 | 21 | </aside> |
75 | 22 | <section className="flow"> |
76 | 23 | <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> |
| 24 | + <SnippetList /> |
96 | 25 | </section> |
97 | 26 | </main> |
98 | 27 | <Footer /> |
|
0 commit comments