From 8bb107c05dab2f63fc8fbabff807ebc3f56c3fdc Mon Sep 17 00:00:00 2001 From: Neil Murphy Date: Fri, 3 Jan 2025 15:36:34 +0000 Subject: [PATCH 1/8] working search feature --- src/components/CategoryList.tsx | 41 +++++--- src/{App.tsx => components/Container.tsx} | 12 ++- src/components/SearchInput.tsx | 122 +++++++++++++++++++++- src/components/SnippetList.tsx | 16 +-- src/components/SnippetModal.tsx | 2 +- src/contexts/AppContext.tsx | 16 +-- src/hooks/useCategories.ts | 2 +- src/hooks/useSnippets.ts | 35 ++++++- src/main.tsx | 6 +- src/router.tsx | 16 +++ src/styles/main.css | 27 +++++ src/types/index.ts | 2 + src/utils/consts.ts | 8 ++ src/utils/{ => helpers}/slugify.ts | 0 14 files changed, 255 insertions(+), 50 deletions(-) rename src/{App.tsx => components/Container.tsx} (75%) create mode 100644 src/router.tsx create mode 100644 src/utils/consts.ts rename src/utils/{ => helpers}/slugify.ts (100%) diff --git a/src/components/CategoryList.tsx b/src/components/CategoryList.tsx index 4f454a92..157c94c1 100644 --- a/src/components/CategoryList.tsx +++ b/src/components/CategoryList.tsx @@ -1,15 +1,32 @@ -import { useEffect } from "react"; +import { FC } from "react"; import { useAppContext } from "@contexts/AppContext"; import { useCategories } from "@hooks/useCategories"; +import { defaultCategory } from "@utils/consts"; -const CategoryList = () => { +interface CategoryListItemProps { + name: string; +} + +const CategoryListItem: FC = ({ name }) => { const { category, setCategory } = useAppContext(); - const { fetchedCategories, loading, error } = useCategories(); - useEffect(() => { - setCategory(fetchedCategories[0]); - }, [setCategory, fetchedCategories]); + return ( +
  • + +
  • + ); +}; + +const CategoryList = () => { + const { fetchedCategories, loading, error } = useCategories(); if (loading) return
    Loading...
    ; @@ -17,17 +34,9 @@ const CategoryList = () => { return ( ); diff --git a/src/App.tsx b/src/components/Container.tsx similarity index 75% rename from src/App.tsx rename to src/components/Container.tsx index d2ccddb6..dc657b26 100644 --- a/src/App.tsx +++ b/src/components/Container.tsx @@ -1,11 +1,15 @@ -import SnippetList from "@components/SnippetList"; +import { FC } from "react"; +import { Outlet } from "react-router-dom"; + import { useAppContext } from "@contexts/AppContext"; import Banner from "@layouts/Banner"; import Footer from "@layouts/Footer"; import Header from "@layouts/Header"; import Sidebar from "@layouts/Sidebar"; -const App = () => { +interface ContainerProps {} + +const Container: FC = () => { const { category } = useAppContext(); return ( @@ -18,7 +22,7 @@ const App = () => {

    {category ? category : "Select a category"}

    - +