Skip to content

Commit 629878a

Browse files
committed
We can now display products from a single category
1 parent 4a1d7b0 commit 629878a

File tree

2 files changed

+25
-21
lines changed

2 files changed

+25
-21
lines changed

components/Category/Categories.component.jsx

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,19 +12,16 @@ const Categories = ({ categories }) => {
1212
<section className="container mx-auto bg-white">
1313
<div className="flex ">
1414
{categories.map(({ id, name, slug }) => (
15-
<div
16-
key={uuidv4()}
17-
className="flex flex-col justify-around p-6 cursor-pointer xs:w-1/2 md:w-1/3 xl:w-1/4"
18-
>
19-
<div className="flex items-center justify-center w-full h-16 text-center border border-gray-300 rounded-lg shadow hover:shadow-outline">
20-
<Link
21-
as={`/kategori/${slug}-${id}`}
22-
href={`/kategori?slug=${slug}-${id}`}
23-
>
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">
2421
<p className="text-lg">{name}</p>
25-
</Link>
22+
</div>
2623
</div>
27-
</div>
24+
</Link>
2825
))}
2926
</div>
3027
</section>

pages/kategori/[slug].js

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,28 @@
11
import { withRouter } from 'next/router';
22

3-
import SingleProduct from 'components/Product/SingleProduct.component';
3+
import IndexProducts from 'components/Product/IndexProducts.component';
4+
import PageTitle from 'components/Header/PageTitle.component';
5+
46
import client from 'utils/apollo/ApolloClient';
57

68
import { GET_PRODUCTS_FROM_CATEGORY } from 'utils/const/GQL_QUERIES';
79

810
/**
911
* Display a single product with dynamic pretty urls
1012
*/
11-
const Produkt = (props) => {
12-
const { product } = props;
13+
const Produkt = ({ categoryName, products }) => {
14+
1315

1416
const error = false;
1517

1618
return (
1719
<>
18-
{product ? (
19-
<SingleProduct product={product} />
20+
{products ? (
21+
<>
22+
<PageTitle title={categoryName} marginleft="50" />
23+
24+
<IndexProducts products={products} />
25+
</>
2026
) : (
2127
<div className="mt-8 text-2xl text-center">Laster produkt ...</div>
2228
)}
@@ -32,19 +38,20 @@ const Produkt = (props) => {
3238

3339
export default withRouter(Produkt);
3440

35-
export async function getStaticProps(context) {
41+
export async function getServerSideProps(context) {
3642
let {
37-
query: { slug, productId },
43+
query: { id },
3844
} = context;
3945

40-
const id = productId;
41-
4246
const res = await client.query({
4347
query: GET_PRODUCTS_FROM_CATEGORY,
4448
variables: { id },
4549
});
4650

4751
return {
48-
props: { product: res.data.product },
52+
props: {
53+
categoryName: res.data.productCategory.name,
54+
products: res.data.productCategory.products.nodes,
55+
},
4956
};
5057
}

0 commit comments

Comments
 (0)