diff --git a/packages/template-retail-rsc-app/src/app/components/productGrid/index.tsx b/packages/template-retail-rsc-app/src/app/components/productGrid/index.tsx index fde3e3485e..55a7436b3d 100644 --- a/packages/template-retail-rsc-app/src/app/components/productGrid/index.tsx +++ b/packages/template-retail-rsc-app/src/app/components/productGrid/index.tsx @@ -3,10 +3,26 @@ import type {ShopperSearchTypes} from 'commerce-sdk-isomorphic' import ProductCard from '@/app/components/productCard' export default function ProductGrid({ - products + products, + isLoading = false }: { products: ShopperSearchTypes.ProductSearchHit[] + isLoading?: boolean }): ReactElement { + if (isLoading) { + return ( +
+ {Array.from({length: 8}).map((_, i) => ( +
+
+
+
+
+ ))} +
+ ) + } + return ( <>
@@ -18,7 +34,13 @@ export default function ProductGrid({ {/* Show a message when no products are found */} {products.length === 0 && (
+
+ + + +

No products found.

+

Try adjusting your search criteria or browse our categories.

)} diff --git a/packages/template-retail-rsc-app/src/app/components/searchResultsSummary/index.tsx b/packages/template-retail-rsc-app/src/app/components/searchResultsSummary/index.tsx new file mode 100644 index 0000000000..3f26ef1b3a --- /dev/null +++ b/packages/template-retail-rsc-app/src/app/components/searchResultsSummary/index.tsx @@ -0,0 +1,47 @@ +import type {ReactElement} from 'react' +import type {ShopperSearchTypes} from 'commerce-sdk-isomorphic' + +export default function SearchResultsSummary({ + searchTerm, + result, + className = '' +}: { + searchTerm: string + result: ShopperSearchTypes.ProductSearchResult + className?: string +}): ReactElement { + const totalResults = result.total || 0 + const currentPage = Math.floor((result.offset || 0) / (result.limit || 24)) + 1 + const totalPages = Math.ceil(totalResults / (result.limit || 24)) + + return ( +
+
+
+ {totalResults.toLocaleString()} results for "{searchTerm}" + {totalPages > 1 && ( + + (Page {currentPage} of {totalPages}) + + )} +
+ + {result.suggestedSearchTerms && result.suggestedSearchTerms.length > 0 && ( +
+ Did you mean: + {result.suggestedSearchTerms.slice(0, 3).map((term: string, index: number) => ( + + {term} + {index < Math.min(2, result.suggestedSearchTerms!.length - 1) && ', '} + + ))} +
+ )} +
+
+ ) +} diff --git a/packages/template-retail-rsc-app/src/app/routes/search/index.tsx b/packages/template-retail-rsc-app/src/app/routes/search/index.tsx index 46b5ec79a6..e654a7180b 100644 --- a/packages/template-retail-rsc-app/src/app/routes/search/index.tsx +++ b/packages/template-retail-rsc-app/src/app/routes/search/index.tsx @@ -6,6 +6,7 @@ import ProductGrid from '@/app/components/productGrid' import CategoryRefinements from '@/app/components/categoryRefinements' import CategorySorting from '@/app/components/categorySorting' import CategoryPagination from '@/app/components/categoryPagination' +import SearchResultsSummary from '@/app/components/searchResultsSummary' const limit = 24 @@ -31,37 +32,102 @@ export default function Search({ searchResult: ShopperSearchTypes.ProductSearchResult } }) { + const hasResults = searchResult.hits && searchResult.hits.length > 0 + const totalResults = searchResult.total || 0 + return (
-
-
-

Search Results for

-

- {searchTerm} ({searchResult.total}) -

-
+ {/* Search Header */} +
+ {searchTerm && ( +
+
+

Search Results for

+

+ "{searchTerm}" ({totalResults.toLocaleString()} {totalResults === 1 ? 'result' : 'results'}) +

+
-
- -
+ {hasResults && ( +
+ +
+ )} +
+ )}
-
-
- -
+ {/* Search Results */} + {searchTerm ? ( + hasResults ? ( +
+ {/* Filters Sidebar */} +
+ +
-
- + {/* Results Grid */} +
+ + - {searchResult.total > 1 && ( -
- + {/* Pagination */} + {totalResults > limit && ( +
+ +
+ )} +
+
+ ) : ( +
+
+
+ + + +
+

No results found

+

+ We couldn't find any products matching "{searchTerm}". Try adjusting your search terms or browse our categories. +

+
+

Try searching for:

+
+ {['shoes', 'electronics', 'clothing', 'accessories'].map((term) => ( + + {term} + + ))} +
+
- )} +
+ ) + ) : ( +
+
+
+ + + +
+

Search for products

+

+ Use the search bar in the header to find products, brands, or categories. +

+
-
+ )}
)