File tree Expand file tree Collapse file tree 1 file changed +8
-9
lines changed
src/app/(main)/collections Expand file tree Collapse file tree 1 file changed +8
-9
lines changed Original file line number Diff line number Diff line change @@ -5,7 +5,7 @@ export const runtime = "edge"
5
5
6
6
export async function GET ( request : NextRequest ) {
7
7
const searchParams = Object . fromEntries ( request . nextUrl . searchParams )
8
- const { handle, pageParam , limit, cart_id } = searchParams
8
+ const { handle, page , limit, cart_id } = searchParams
9
9
10
10
const collection = await fetchCollection ( handle )
11
11
. then ( ( res ) => res )
@@ -14,7 +14,7 @@ export async function GET(request: NextRequest) {
14
14
} )
15
15
16
16
const { products, count, nextPage } = await fetchCollectionProducts ( {
17
- pageParam ,
17
+ page ,
18
18
id : collection . id ,
19
19
limit,
20
20
cart_id,
@@ -41,12 +41,12 @@ async function fetchCollection(handle: string) {
41
41
}
42
42
43
43
async function fetchCollectionProducts ( {
44
- pageParam = "0" ,
44
+ page = "0" ,
45
45
id,
46
46
limit = "12" ,
47
47
cart_id,
48
48
} : {
49
- pageParam : string
49
+ page : string
50
50
id : string
51
51
limit : string
52
52
cart_id : string
@@ -56,17 +56,16 @@ async function fetchCollectionProducts({
56
56
collection_id : [ id ] ,
57
57
cart_id,
58
58
limit,
59
- offset : pageParam ,
59
+ offset : page ,
60
60
expand : "variants,variants.prices" ,
61
61
} ,
62
62
} ) . then ( ( res ) => res . body )
63
63
64
+ const nextPage = parseInt ( offset ) + parseInt ( limit )
65
+
64
66
return {
65
67
products,
66
68
count,
67
- nextPage :
68
- count > parseInt ( offset ) + parseInt ( limit )
69
- ? parseInt ( offset ) + parseInt ( limit )
70
- : null ,
69
+ nextPage : count > nextPage ? nextPage : null ,
71
70
}
72
71
}
You can’t perform that action at this time.
0 commit comments