Skip to content

Commit d4d7632

Browse files
committed
add recipe cards and details
1 parent dd2c230 commit d4d7632

File tree

3 files changed

+136
-5
lines changed

3 files changed

+136
-5
lines changed

marmite/components/RecipeCard.js

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,17 @@
11
import Link from "next/link";
2+
import Image from "next/image";
23

34
function RecipeCard({ recipe }) {
45
const { title, slug, cookingTime, thumbnail } = recipe.fields;
56
return (
67
<div className="card">
7-
<div className="featured"></div>
8+
<div className="featured">
9+
<Image
10+
src={`https:${thumbnail.fields.file.url}`}
11+
width={thumbnail.fields.file.details.image.width}
12+
height={thumbnail.fields.file.details.image.height}
13+
/>
14+
</div>
815
<div className="content">
916
<div className="info">
1017
<h4>{title}</h4>
@@ -16,6 +23,41 @@ function RecipeCard({ recipe }) {
1623
</Link>
1724
</div>
1825
</div>
26+
<style jsx>{`
27+
.card {
28+
transform: rotateZ(-1deg);
29+
}
30+
.content {
31+
background: #fff;
32+
box-shadow: 1px 3px 5px rgba(0, 0, 0, 0.1);
33+
margin: 0;
34+
position: relative;
35+
top: -40px;
36+
left: -10px;
37+
}
38+
.info {
39+
padding: 16px;
40+
}
41+
.info h4 {
42+
margin: 4px 0;
43+
text-transform: uppercase;
44+
}
45+
.info p {
46+
margin: 0;
47+
color: #777;
48+
}
49+
.actions {
50+
margin-top: 20px;
51+
display: flex;
52+
justify-content: flex-end;
53+
}
54+
.actions a {
55+
color: #fff;
56+
background: #f01b29;
57+
padding: 16px 24px;
58+
text-decoration: none;
59+
}
60+
`}</style>
1961
</div>
2062
);
2163
}

marmite/pages/index.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,13 @@ export default function Recipes({ recipes }) {
2121
{recipes.map((recipe) => (
2222
<RecipeCard key={recipe.sys.id} recipe={recipe} />
2323
))}
24+
<style jsx>{`
25+
.recipe-list {
26+
display: grid;
27+
grid-template-columns: 1fr 1fr;
28+
gap: 20px 60px;
29+
}
30+
`}</style>
2431
</div>
2532
);
2633
}

marmite/pages/recipes/[slug].js

Lines changed: 86 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,89 @@
1-
export default function RecipeDetails() {
1+
import { createClient } from "contentful";
2+
import { documentToReactComponents } from "@contentful/rich-text-react-renderer";
3+
import Image from "next/image";
4+
5+
const client = createClient({
6+
space: process.env.CONTENTFUL_SPACE_ID,
7+
accessToken: process.env.CONTENTFUL_DELIVERY_API,
8+
});
9+
10+
export const getStaticPaths = async () => {
11+
const res = await client.getEntries({ content_type: "recipe" });
12+
const paths = res.items.map((item) => {
13+
return {
14+
params: { slug: item.fields.slug },
15+
};
16+
});
17+
return { paths, fallback: false };
18+
};
19+
20+
export async function getStaticProps({ params }) {
21+
const { items } = await client.getEntries({
22+
content_type: "recipe",
23+
"fields.slug": params.slug,
24+
});
25+
return {
26+
props: {
27+
recipe: items[0],
28+
},
29+
};
30+
}
31+
32+
export default function RecipeDetails({ recipe }) {
33+
const {
34+
featuredImage,
35+
title,
36+
cookingTime,
37+
ingredients,
38+
method,
39+
} = recipe.fields;
240
return (
341
<div>
4-
Recipe Details
42+
<div className="banner">
43+
<Image
44+
src={`https:${featuredImage.fields.file.url}`}
45+
width={featuredImage.fields.file.details.image.width}
46+
height={featuredImage.fields.file.details.image.height}
47+
/>
48+
<h2>{title}</h2>
49+
</div>
50+
<div className="info">
51+
<p>Takes approx {cookingTime} mins to make</p>
52+
<h3>Ingredients:</h3>
53+
{ingredients.map((ingredient) => (
54+
<span key={ingredient}>{ingredient}</span>
55+
))}
56+
</div>
57+
<div className="method">
58+
<h3>Method:</h3>
59+
<div>{documentToReactComponents(method)}</div>
60+
</div>
61+
<style jsx>{`
62+
h2,
63+
h3 {
64+
text-transform: uppercase;
65+
}
66+
.banner h2 {
67+
margin: 0;
68+
background: #fff;
69+
display: inline-block;
70+
padding: 20px;
71+
position: relative;
72+
top: -60px;
73+
left: -10px;
74+
transform: rotateZ(-1deg);
75+
box-shadow: 1px 3px 5px rgba(0, 0, 0, 0.1);
76+
}
77+
.info p {
78+
margin: 0;
79+
}
80+
.info span::after {
81+
content: ", ";
82+
}
83+
.info span:last-child::after {
84+
content: ".";
85+
}
86+
`}</style>
587
</div>
6-
)
7-
}
88+
);
89+
}

0 commit comments

Comments
 (0)