Skip to content

Commit 8936bb6

Browse files
committed
refactor: page and provider layouts
1 parent 78377c2 commit 8936bb6

File tree

15 files changed

+62
-43
lines changed

15 files changed

+62
-43
lines changed

src/app/cart/layout.tsx

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import PageLayout from "app/page-layout"
2+
3+
export default function CartLayout({
4+
children,
5+
}: {
6+
children: React.ReactNode
7+
}) {
8+
return <PageLayout>{children}</PageLayout>
9+
}

src/app/checkout/layout.tsx

Lines changed: 0 additions & 9 deletions
This file was deleted.

src/app/collections/[handle]/collection.tsx

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,11 @@ const fetchCollectionProducts = async ({
2828
handle: string
2929
cartId?: string
3030
}) => {
31-
const { products, count, nextPage } = await fetch(
31+
const { response, nextPage } = await fetch(
3232
`${BASEURL}/collections?handle=${handle}&cart_id=${cartId}&page=${pageParam}`
3333
).then((res) => res.json())
3434
return {
35-
response: { products, count },
35+
response,
3636
nextPage,
3737
}
3838
}
@@ -46,7 +46,6 @@ const Collection: React.FC<CollectionTemplateProps> = ({ collection }) => {
4646
hasNextPage,
4747
fetchNextPage,
4848
isFetchingNextPage,
49-
isLoading,
5049
refetch,
5150
} = useInfiniteQuery(
5251
[`get_collection_products`, collection.handle, cart?.id],
@@ -90,13 +89,6 @@ const Collection: React.FC<CollectionTemplateProps> = ({ collection }) => {
9089
<ProductPreview {...p} />
9190
</li>
9291
))}
93-
{isLoading &&
94-
!previews.length &&
95-
repeat(8).map((index) => (
96-
<li key={index}>
97-
<SkeletonProductPreview />
98-
</li>
99-
))}
10092
{isFetchingNextPage &&
10193
repeat(getNumberOfSkeletons(infiniteData?.pages)).map((index) => (
10294
<li key={index}>

src/app/collections/[handle]/page.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import PageLayout from "app/page-layout"
12
import Collection from "./collection"
23

34
import { Metadata } from "next"
@@ -26,8 +27,8 @@ export default async function CollectionPage({ params }: Props) {
2627
).then((res) => res.json())
2728

2829
return (
29-
<>
30+
<PageLayout>
3031
<Collection collection={collection} />
31-
</>
32+
</PageLayout>
3233
)
3334
}

src/app/collections/route.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,17 @@ export async function GET(request: NextRequest) {
1212
throw new Error(JSON.stringify(error.error))
1313
})
1414

15-
const { response, nextPage } = await fetchCollectionProducts({
15+
const { products, count, nextPage } = await fetchCollectionProducts({
1616
pageParam,
1717
id: collection.id,
1818
}).then((res) => res)
1919

2020
return NextResponse.json({
2121
collection,
22-
products: response.products,
23-
count: response.count,
22+
response: {
23+
products,
24+
count,
25+
},
2426
nextPage,
2527
})
2628
}
@@ -52,7 +54,8 @@ async function fetchCollectionProducts({
5254
).then((res) => res.body)
5355

5456
return {
55-
response: { products, count },
57+
products: [...products, ...products, ...products, ...products],
58+
count: 15,
5659
nextPage: count > offset + 12 ? offset + 12 : null,
5760
}
5861
}

src/app/layout.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
import Footer from "@modules/layout/templates/footer"
2+
import Nav from "@modules/layout/templates/nav"
3+
import Providers from "@modules/providers"
14
import "styles/globals.css"
25

36
export default function RootLayout({
@@ -8,7 +11,9 @@ export default function RootLayout({
811
return (
912
<html lang="en">
1013
<body>
11-
<main className="relative">{children}</main>
14+
<Providers>
15+
<main className="relative">{children}</main>
16+
</Providers>
1217
</body>
1318
</html>
1419
)

src/app/not-found.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { Metadata } from "next"
22
import Link from "next/link"
3+
import PageLayout from "./page-layout"
34

45
export const metadata: Metadata = {
56
title: "404",
@@ -8,7 +9,7 @@ export const metadata: Metadata = {
89

910
export default function NotFound() {
1011
return (
11-
<>
12+
<PageLayout>
1213
<div className="flex flex-col items-center justify-center min-h-[calc(100vh-64px)]">
1314
<h1 className="text-2xl-semi text-gry-900">Page not found</h1>
1415
<p className="text-small-regular text-gray-700">
@@ -21,6 +22,6 @@ export default function NotFound() {
2122
Go to frontpage
2223
</Link>
2324
</div>
24-
</>
25+
</PageLayout>
2526
)
2627
}

src/app/page-layout.tsx

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import Footer from "@modules/layout/templates/footer"
2+
import Nav from "@modules/layout/templates/nav"
3+
4+
export default function PageLayout({
5+
children,
6+
}: {
7+
children: React.ReactNode
8+
}) {
9+
return (
10+
<>
11+
<Nav />
12+
{children}
13+
<Footer />
14+
</>
15+
)
16+
}

src/app/page.tsx

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
1+
import PageLayout from "./page-layout"
12
import FeaturedProducts from "@modules/home/components/featured-products"
23
import Hero from "@modules/home/components/hero"
3-
import Footer from "@modules/layout/templates/footer"
4-
import Nav from "@modules/layout/templates/nav"
5-
import Providers from "@modules/providers"
64
import { Metadata } from "next"
75

86
export const metadata: Metadata = {
@@ -13,12 +11,10 @@ export const metadata: Metadata = {
1311

1412
const Home = () => {
1513
return (
16-
<Providers>
17-
<Nav />
14+
<PageLayout>
1815
<Hero />
1916
<FeaturedProducts />
20-
<Footer />
21-
</Providers>
17+
</PageLayout>
2218
)
2319
}
2420

src/app/store/page.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,16 @@
11
import { Metadata } from "next"
22
import Store from "./store"
3+
import PageLayout from "app/page-layout"
34

45
export const metadata: Metadata = {
56
title: "Store",
67
description: "Explore all of our products.",
78
}
89

910
export default function StorePage() {
10-
return <Store />
11+
return (
12+
<PageLayout>
13+
<Store />
14+
</PageLayout>
15+
)
1116
}

0 commit comments

Comments
 (0)