Skip to content

Commit

Permalink
fix: remove redundant component, fix typo (#957)
Browse files Browse the repository at this point in the history
  • Loading branch information
grzegorzpokorski authored Oct 16, 2023
1 parent b075be7 commit e9c6bda
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 30 deletions.
4 changes: 2 additions & 2 deletions src/app/(main)/categories/[slug]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { notFound } from "next/navigation";
import { type Metadata } from "next";
import { ProductListByCategoryDocument } from "@/gql/graphql";
import { executeGraphQL } from "@/lib/graphql";
import { ProductsList } from "@/ui/components/ProductsList";
import { ProductList } from "@/ui/components/ProductList";

export const generateMetadata = async ({ params }: { params: { slug: string } }): Promise<Metadata> => {
const { category } = await executeGraphQL(ProductListByCategoryDocument, {
Expand Down Expand Up @@ -31,7 +31,7 @@ export default async function Page({ params }: { params: { slug: string } }) {
return (
<div className="mx-auto max-w-7xl p-8 pb-16">
<h1 className="pb-8 text-xl font-semibold">{name}</h1>
<ProductsList products={products.edges.map((e) => e.node)} />
<ProductList products={products.edges.map((e) => e.node)} />
</div>
);
}
4 changes: 2 additions & 2 deletions src/app/(main)/page.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { ProductListDocument } from "@/gql/graphql";
import { executeGraphQL } from "@/lib/graphql";
import { ProductsList } from "@/ui/components/ProductsList";
import { ProductList } from "@/ui/components/ProductList";

export const metadata = {
title: "Saleor Storefront example",
Expand All @@ -18,7 +18,7 @@ export default async function Page() {
<div>
<section className="mx-auto max-w-7xl p-8 pb-16">
<h2 className="sr-only">Product list</h2>
<ProductsList products={products} />
<ProductList products={products} />
</section>
</div>
);
Expand Down
4 changes: 2 additions & 2 deletions src/app/(main)/products/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { notFound } from "next/navigation";
import { ProductListPaginatedDocument } from "@/gql/graphql";
import { ProductsPerPage, executeGraphQL } from "@/lib/graphql";
import { Pagination } from "@/ui/components/Pagination";
import { ProductsList } from "@/ui/components/ProductsList";
import { ProductList } from "@/ui/components/ProductList";

export const metadata = {
title: "Product List · Saleor Storefront example",
Expand Down Expand Up @@ -34,7 +34,7 @@ export default async function Page({ searchParams }: Props) {
<div>
<section className="mx-auto max-w-7xl p-8 pb-16">
<h2 className="sr-only">Product list</h2>
<ProductsList products={products.edges.map((e) => e.node)} />
<ProductList products={products.edges.map((e) => e.node)} />
<Pagination pageInfo={products.pageInfo} />
</section>
</div>
Expand Down
15 changes: 7 additions & 8 deletions src/ui/components/ProductList.tsx
Original file line number Diff line number Diff line change
@@ -1,20 +1,19 @@
import { ProductElement } from "./ProductElement";
import { type ProductListItemFragment } from "@/gql/graphql";

type Props = {
products: ProductListItemFragment[];
};

export const ProductList = ({ products }: Props) => {
export const ProductList = ({ products }: { products: readonly ProductListItemFragment[] }) => {
return (
<ul className="grid gap-8 sm:grid-cols-2 md:grid-cols-3 lg:grid-cols-4" role="list">
<ul
role="list"
data-testid="ProductList"
className="grid grid-cols-1 gap-8 sm:grid-cols-2 lg:grid-cols-3"
>
{products.map((product, index) => (
<ProductElement
key={product.id}
product={product}
//Prioritize first image in the list to speed up above the fold image loading on mobile
priority={index === 0}
loading={index < 4 ? "eager" : "lazy"}
loading={index < 3 ? "eager" : "lazy"}
/>
))}
</ul>
Expand Down
16 changes: 0 additions & 16 deletions src/ui/components/ProductsList.tsx

This file was deleted.

0 comments on commit e9c6bda

Please sign in to comment.