-
Notifications
You must be signed in to change notification settings - Fork 121
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #168 from w3bdesign/development
Finish category page
- Loading branch information
Showing
3 changed files
with
118 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
import { withRouter } from 'next/router'; | ||
|
||
import IndexProducts from 'components/Product/IndexProducts.component'; | ||
import PageTitle from 'components/Header/PageTitle.component'; | ||
|
||
import client from 'utils/apollo/ApolloClient'; | ||
|
||
import { GET_PRODUCTS_FROM_CATEGORY } from 'utils/const/GQL_QUERIES'; | ||
|
||
/** | ||
* Display a single product with dynamic pretty urls | ||
*/ | ||
const Produkt = ({ categoryName, products }) => { | ||
|
||
|
||
const error = false; | ||
|
||
return ( | ||
<> | ||
{products ? ( | ||
<> | ||
<PageTitle title={categoryName} marginleft="50" /> | ||
|
||
<IndexProducts products={products} /> | ||
</> | ||
) : ( | ||
<div className="mt-8 text-2xl text-center">Laster produkt ...</div> | ||
)} | ||
{/* Display error message if error occured */} | ||
{error && ( | ||
<div className="mt-8 text-2xl text-center"> | ||
Feil under lasting av produkt ... | ||
</div> | ||
)} | ||
</> | ||
); | ||
}; | ||
|
||
export default withRouter(Produkt); | ||
|
||
export async function getServerSideProps(context) { | ||
let { | ||
query: { id }, | ||
} = context; | ||
|
||
const res = await client.query({ | ||
query: GET_PRODUCTS_FROM_CATEGORY, | ||
variables: { id }, | ||
}); | ||
|
||
return { | ||
props: { | ||
categoryName: res.data.productCategory.name, | ||
products: res.data.productCategory.products.nodes, | ||
}, | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters