From 78c4d836f77eaf135fc8303e9ad0b1d79e70c227 Mon Sep 17 00:00:00 2001 From: ACR1209 Date: Sat, 25 Jan 2025 17:47:18 -0500 Subject: [PATCH 1/2] Enhance SnippetList component to handle loading state and display message when no snippets are found --- src/components/SnippetList.tsx | 30 ++++++++++++++++++++---------- src/styles/main.css | 13 ++++++++++++- 2 files changed, 32 insertions(+), 11 deletions(-) diff --git a/src/components/SnippetList.tsx b/src/components/SnippetList.tsx index 0b9a2025..0b88852c 100644 --- a/src/components/SnippetList.tsx +++ b/src/components/SnippetList.tsx @@ -5,22 +5,16 @@ import { useAppContext } from "@contexts/AppContext"; import { useSnippets } from "@hooks/useSnippets"; import { SnippetType } from "@types"; -import { LeftAngleArrowIcon } from "./Icons"; import SnippetModal from "./SnippetModal"; const SnippetList = () => { const { language, snippet, setSnippet } = useAppContext(); - const { fetchedSnippets } = useSnippets(); + const { fetchedSnippets, loading } = useSnippets(); const [isModalOpen, setIsModalOpen] = useState(false); const shouldReduceMotion = useReducedMotion(); - if (!fetchedSnippets) - return ( -
- -
- ); + if (loading) return null; const handleOpenModal = (activeSnippet: SnippetType) => { setIsModalOpen(true); @@ -34,9 +28,25 @@ const SnippetList = () => { return ( <> - + - {fetchedSnippets.map((snippet, idx) => { + {fetchedSnippets && fetchedSnippets.length === 0 && ( +
+

No snippets found for this category. Why not add one? 🚀

+ + Add your own snippet + +
+ )} + {fetchedSnippets?.map((snippet, idx) => { const uniqueId = `${language.name}-${snippet.title}`; return ( Date: Mon, 3 Feb 2025 17:16:29 -0500 Subject: [PATCH 2/2] Fix linting --- src/components/SnippetList.tsx | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/components/SnippetList.tsx b/src/components/SnippetList.tsx index a93902b6..ab986886 100644 --- a/src/components/SnippetList.tsx +++ b/src/components/SnippetList.tsx @@ -18,9 +18,9 @@ const SnippetList = () => { const [searchParams, setSearchParams] = useSearchParams(); const { fetchedSnippets, loading } = useSnippets(); const { language, subLanguage, snippet, setSnippet } = useAppContext(); - + const [isModalOpen, setIsModalOpen] = useState(false); - + const shouldReduceMotion = useReducedMotion(); const handleOpenModal = (selected: SnippetType) => () => { @@ -54,7 +54,7 @@ const SnippetList = () => { } // eslint-disable-next-line react-hooks/exhaustive-deps }, [fetchedSnippets, searchParams]); - + if (loading) return null; return ( pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy