File tree Expand file tree Collapse file tree 3 files changed +118
-8
lines changed Expand file tree Collapse file tree 3 files changed +118
-8
lines changed Original file line number Diff line number Diff line change
1
+ import Link from 'next/link' ;
1
2
import { v4 as uuidv4 } from 'uuid' ;
2
3
3
4
/**
@@ -10,15 +11,17 @@ const Categories = ({ categories }) => {
10
11
< >
11
12
< section className = "container mx-auto bg-white" >
12
13
< div className = "flex " >
13
- { categories . map ( ( { name } ) => (
14
- < div
15
- key = { uuidv4 ( ) }
16
- className = "flex flex-col justify-around p-6 cursor-pointer xs:w-1/2 md:w-1/3 xl:w-1/4"
17
- >
18
- < div className = "flex items-center justify-center w-full h-16 text-center border border-gray-300 rounded-lg shadow hover:shadow-outline" >
19
- < p className = "text-lg" > { name } </ p >
14
+ { categories . map ( ( { id, name, slug } ) => (
15
+ < Link as = { `/kategori/${ slug } ?id=${ id } ` } href = "/kategori/[id]" >
16
+ < div
17
+ key = { uuidv4 ( ) }
18
+ className = "flex flex-col justify-around p-6 cursor-pointer xs:w-1/2 md:w-1/3 xl:w-1/4"
19
+ >
20
+ < div className = "flex items-center justify-center w-full h-16 text-center border border-gray-300 rounded-lg shadow hover:shadow-outline" >
21
+ < p className = "text-lg" > { name } </ p >
22
+ </ div >
20
23
</ div >
21
- </ div >
24
+ </ Link >
22
25
) ) }
23
26
</ div >
24
27
</ section >
Original file line number Diff line number Diff line change
1
+ import { withRouter } from 'next/router' ;
2
+
3
+ import IndexProducts from 'components/Product/IndexProducts.component' ;
4
+ import PageTitle from 'components/Header/PageTitle.component' ;
5
+
6
+ import client from 'utils/apollo/ApolloClient' ;
7
+
8
+ import { GET_PRODUCTS_FROM_CATEGORY } from 'utils/const/GQL_QUERIES' ;
9
+
10
+ /**
11
+ * Display a single product with dynamic pretty urls
12
+ */
13
+ const Produkt = ( { categoryName, products } ) => {
14
+
15
+
16
+ const error = false ;
17
+
18
+ return (
19
+ < >
20
+ { products ? (
21
+ < >
22
+ < PageTitle title = { categoryName } marginleft = "50" />
23
+
24
+ < IndexProducts products = { products } />
25
+ </ >
26
+ ) : (
27
+ < div className = "mt-8 text-2xl text-center" > Laster produkt ...</ div >
28
+ ) }
29
+ { /* Display error message if error occured */ }
30
+ { error && (
31
+ < div className = "mt-8 text-2xl text-center" >
32
+ Feil under lasting av produkt ...
33
+ </ div >
34
+ ) }
35
+ </ >
36
+ ) ;
37
+ } ;
38
+
39
+ export default withRouter ( Produkt ) ;
40
+
41
+ export async function getServerSideProps ( context ) {
42
+ let {
43
+ query : { id } ,
44
+ } = context ;
45
+
46
+ const res = await client . query ( {
47
+ query : GET_PRODUCTS_FROM_CATEGORY ,
48
+ variables : { id } ,
49
+ } ) ;
50
+
51
+ return {
52
+ props : {
53
+ categoryName : res . data . productCategory . name ,
54
+ products : res . data . productCategory . products . nodes ,
55
+ } ,
56
+ } ;
57
+ }
Original file line number Diff line number Diff line change @@ -118,6 +118,56 @@ export const FETCH_ALL_CATEGORIES_QUERY = gql`
118
118
}
119
119
` ;
120
120
121
+ export const GET_PRODUCTS_FROM_CATEGORY = gql `
122
+ query ProductsFromCategory($id: ID!) {
123
+ productCategory(id: $id) {
124
+ id
125
+ name
126
+ products(first: 50) {
127
+ nodes {
128
+ id
129
+ productId
130
+ averageRating
131
+ slug
132
+ description
133
+ image {
134
+ id
135
+ uri
136
+ title
137
+ srcSet
138
+ sourceUrl
139
+ }
140
+ name
141
+ ... on SimpleProduct {
142
+ price
143
+ id
144
+ }
145
+ ... on VariableProduct {
146
+ price
147
+ id
148
+ }
149
+ ... on ExternalProduct {
150
+ price
151
+ id
152
+ externalUrl
153
+ }
154
+ ... on GroupProduct {
155
+ products {
156
+ nodes {
157
+ ... on SimpleProduct {
158
+ id
159
+ price
160
+ }
161
+ }
162
+ }
163
+ id
164
+ }
165
+ }
166
+ }
167
+ }
168
+ }
169
+ ` ;
170
+
121
171
export const GET_CART = gql `
122
172
query GET_CART {
123
173
cart {
You can’t perform that action at this time.
0 commit comments