From 9af8704bbc5413e059241533f18540c4e9e6ce9f Mon Sep 17 00:00:00 2001 From: Nich Galzin <74174344+nichgalzin@users.noreply.github.com> Date: Thu, 27 Jun 2024 17:17:56 +0100 Subject: [PATCH] feat: loading state and display Relates #256 --- app/(dashboard)/search/page.tsx | 7 +-- components/search/ItemDisplayContainer.tsx | 51 +++++++++++----------- 2 files changed, 29 insertions(+), 29 deletions(-) diff --git a/app/(dashboard)/search/page.tsx b/app/(dashboard)/search/page.tsx index 527ff659..27e2b89f 100644 --- a/app/(dashboard)/search/page.tsx +++ b/app/(dashboard)/search/page.tsx @@ -20,8 +20,10 @@ export default function SearchItemPage() { const [searchParams, setSearchParams] = useState(initialSearchParams); const [searchResults, setSearchResults] = useState([]); + const [isLoading, setIsLoading] = useState(false); const fetchSearchResults = async () => { + setIsLoading(true); let data: PartialItem[] = []; switch (true) { // case !!searchParams.query && @@ -58,6 +60,7 @@ export default function SearchItemPage() { break; } setSearchResults(data); + setIsLoading(false); }; useEffect(() => { @@ -72,10 +75,8 @@ export default function SearchItemPage() { /> ); diff --git a/components/search/ItemDisplayContainer.tsx b/components/search/ItemDisplayContainer.tsx index 19cf206a..3b7c926c 100644 --- a/components/search/ItemDisplayContainer.tsx +++ b/components/search/ItemDisplayContainer.tsx @@ -3,41 +3,40 @@ import { PartialItem } from '@/types/supabaseTypes'; import ItemCard from '../ItemCard'; type ItemDisplayContainerProps = { - query: string; - category: string; - subcategory: string; searchResults: PartialItem[] | []; + isLoading: boolean; }; const ItemDisplayContainer: React.FC = ({ - query, - category, - subcategory, searchResults, + isLoading, }) => { + if (isLoading) { + return ( +
+

Loading....

+
+ ); + } return (
-

- Search for:{' '} - - {query.length > 0 ? query : ''} - {category.length > 0 ? category : ''} - {subcategory.length > 0 ? subcategory : ''} - -

- {searchResults.map((result) => ( - - ))} + {searchResults.length > 0 ? ( + searchResults.map((result) => ( + + )) + ) : ( +

No results found.

+ )}
);