Category pages
parent
b59134dc5e
commit
5ccda75fff
@ -0,0 +1,52 @@
|
||||
import React, {useState} from 'react'
|
||||
import Head from 'next/head'
|
||||
import Link from 'next/link'
|
||||
|
||||
import Card from '~/components/card'
|
||||
import styles from './style.module.css'
|
||||
|
||||
Category.getInitialProps = async function({ctx: {axios, query: {slug}}}){
|
||||
console.log(slug)
|
||||
const {data: category} = await axios.get(`/api/categories/by-slug/${slug}`)
|
||||
|
||||
console.log(category)
|
||||
|
||||
if(!category) {
|
||||
const err = new Error("Not found")
|
||||
err.status = 404
|
||||
throw err;
|
||||
}
|
||||
|
||||
return {category}
|
||||
}
|
||||
|
||||
export default function Category({category: {items, children, parent, ...category}}){
|
||||
return (
|
||||
<>
|
||||
<Head><title>{category.name}</title></Head>
|
||||
<h2>{category.name}</h2>
|
||||
<div className={styles.pageContainer}>
|
||||
{parent && (
|
||||
<Link href={`/store/category/${parent.urlslug}`}><a className={styles.parentLink}>< Back to {parent.name}</a></Link>
|
||||
)}
|
||||
<p className={styles.description}>{category.description}</p>
|
||||
{children.length > 0 && <div className={styles.childCategories}>
|
||||
{children.map(childCategory => (
|
||||
<>
|
||||
<Link href={`/store/category/${childCategory.urlslug}`}><a>{childCategory.name}</a></Link>
|
||||
</>
|
||||
))}
|
||||
</div>}
|
||||
<div className={styles.items}>
|
||||
{items.length > 0 ? (
|
||||
<div className="cardContainer">
|
||||
{items.map(item=>
|
||||
<Card item={item}/>
|
||||
)}
|
||||
</div>
|
||||
) : <p>No items found</p> }
|
||||
</div>
|
||||
</div>
|
||||
</>
|
||||
)
|
||||
}
|
@ -0,0 +1,36 @@
|
||||
.pageContainer {
|
||||
max-width: 800px;
|
||||
margin: 0 auto;
|
||||
width: calc(100% - 100px);
|
||||
position: relative;
|
||||
}
|
||||
|
||||
.parentLink {
|
||||
position: absolute;
|
||||
top: -65px;
|
||||
color: rgb(121, 10, 141);
|
||||
}
|
||||
|
||||
.description {
|
||||
text-align: center;
|
||||
margin-top: -20px;
|
||||
}
|
||||
|
||||
.childCategories {
|
||||
width: 100%;
|
||||
display: flex;
|
||||
flex-direction: row;
|
||||
justify-content: center;
|
||||
flex-wrap: wrap;
|
||||
}
|
||||
|
||||
.childCategories > a {
|
||||
display: inline-block;
|
||||
border: solid 1px rgb(248, 48, 255);
|
||||
background: rgba(248, 48, 255, 0.4);
|
||||
padding: 4px 10px;
|
||||
border-radius: 15px;
|
||||
text-decoration: none;
|
||||
color: black;
|
||||
margin: 10px 20px;
|
||||
}
|
Loading…
Reference in New Issue