Skip to content
This repository was archived by the owner on Oct 21, 2020. It is now read-only.

Commit 9acab5e

Browse files
committed
Adding extra elements on recipe card
- Render ingredients and recipes on click - Display recipe image on recipe card
1 parent ff29367 commit 9acab5e

File tree

3 files changed

+57
-36
lines changed

3 files changed

+57
-36
lines changed

src/components/Home.vue

+19-13
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<template>
2-
<v-app >
2+
<v-app class="app">
33
<v-container id="home">
44
<v-row dense justify="center" alignment="center">
55
<v-col cols="12">
@@ -8,8 +8,8 @@
88

99
<v-card id="ingredientForm" class="elevation-12">
1010
<v-card-text>
11-
<v-form class="form-group" v-for="(item, index) in ingredients" :key="index">
12-
<v-text-field label="Ingredient" v-model="ingredients[index]" />
11+
<v-form ref="form" class="form-group" lazy-validation v-for="(item, index) in ingredients" :key="index">
12+
<v-text-field label="Ingredient" :rules="formRules" v-model="ingredients[index]" />
1313
</v-form>
1414
</v-card-text>
1515

@@ -56,7 +56,10 @@ export default {
5656
api_key: process.env.VUE_APP_API_KEY,
5757
url_base: "https://api.spoonacular.com/recipes",
5858
ingredients: ["", "", ""],
59-
dishes: []
59+
dishes: [],
60+
formRules:[
61+
v => !!v || 'Ingredient is required'
62+
]
6063
};
6164
},
6265
methods: {
@@ -89,18 +92,14 @@ export default {
8992
<style>
9093
@import url("https://fonts.googleapis.com/css2?family=Anton&family=League+Script&display=swap");
9194
92-
.btn-group {
93-
justify-content: center;
94-
align-items: center;
95-
display: flex;
96-
flex-direction: column;
97-
}
9895
#home {
9996
display: flex;
10097
flex-direction: column;
10198
color: rgb(46, 44, 44);
102-
font-family: roboto;
103-
max-width: 512px;}
99+
font-family: roboto;
100+
max-width: 512px;
101+
min-height: 100%;
102+
}
104103
#showRecipe {
105104
background-color: salmon;
106105
margin-top: 10px;
@@ -126,5 +125,12 @@ export default {
126125
#ingredientForm {
127126
flex-basis: 30%;
128127
flex-grow: 0;
129-
}
128+
}
129+
130+
.btn-group {
131+
justify-content: center;
132+
align-items: center;
133+
display: flex;
134+
flex-direction: column;
135+
}
130136
</style>

src/components/RecipeCard.vue

+38-22
Original file line numberDiff line numberDiff line change
@@ -14,34 +14,38 @@
1414
</v-card>
1515
</v-col>
1616

17-
<v-dialog class="popup" v-model="dialog">
17+
<v-dialog id="popup" v-model="dialog">
1818
<v-card>
19-
<v-card-title >
19+
<v-card-title id="dishTitle">
2020
<span class="headline">{{selectedDish.title}}</span>
2121
</v-card-title>
2222

23-
<v-card-text>
23+
<v-avatar size="200" >
24+
<v-img :src="recipeURL" />
25+
</v-avatar>
26+
27+
<v-card-text>
2428
<span class="headline">Time Cook: {{timeCook}} minutes</span>
2529
</v-card-text>
2630

27-
<v-btn class="btn mb-4" raised color="purple lighten-4">Ingredients</v-btn>
28-
<v-spacer></v-spacer>
29-
<v-btn raised color="purple lighten-4">Direction</v-btn>
30-
31-
<v-card-text>
31+
<v-btn class="btn mb-4" raised color="purple lighten-4" @click="showIngredient=!showIngredient">Ingredients</v-btn>
32+
<v-card-text v-if="showIngredient">
3233
<ul>
3334
<li v-for="item in ingredients" :key="item.index">{{item}}</li>
3435
</ul>
3536
</v-card-text>
3637

37-
<v-card-text v-if="instructions.length">
38-
<p>Steps: </p>
38+
<v-spacer></v-spacer>
39+
<v-btn raised color="purple lighten-4" @click="showInstruction=!showInstruction">Direction</v-btn>
40+
41+
42+
<v-card-text v-if="showInstruction">
3943
<ol>
4044
<li v-for="steps in instructions" :key="steps.number">{{steps.step}}</li>
4145
</ol>
4246
</v-card-text>
4347

44-
<v-card-text v-if="instructionURL">
48+
<v-card-text v-if="showInstruction && instructionURL">
4549
<a :href="instructionURL" target="_blank">Recipe URL</a>
4650
<p></p>
4751
</v-card-text>
@@ -54,6 +58,7 @@
5458
</v-card-actions>
5559
</v-card>
5660
</v-dialog>
61+
5762
</v-row>
5863
</template>
5964

@@ -72,16 +77,15 @@ export default {
7277
selectedDish: {},
7378
ingredients: [],
7479
instructionURL: "",
75-
timeCook: ""
80+
timeCook: "",
81+
recipeURL: "",
82+
showIngredient: false,
83+
showInstruction: false
7684
};
7785
},
7886
methods: {
7987
getRecipeIngredients: function(id) {
80-
this.ingredients.length = 0;
81-
this.instructions.length = 0;
82-
this.instructionURL = "";
83-
this.timeCook = "";
84-
88+
this.resetState();
8589
const url = `${this.url_base}/${id}/information?&apiKey=${this.api_key}`;
8690
fetch(url)
8791
.then(res => res.json())
@@ -90,15 +94,25 @@ export default {
9094
this.ingredients.push(element.name);
9195
});
9296
this.timeCook = result.readyInMinutes;
97+
this.recipeURL = result.image;
9398
if (result.analyzedInstructions.length === 0) {
9499
this.instructionURL = result.sourceUrl;
95100
} else {
96101
this.instructions = result.analyzedInstructions[0].steps;
97102
}
98103
});
99104
},
105+
resetState: function(){
106+
this.ingredients.length = 0;
107+
this.instructions.length = 0;
108+
this.instructionURL = "";
109+
this.timeCook = "";
110+
this.showIngredient = false;
111+
this.showInstruction = false
112+
},
113+
100114
scrollToTop() {
101-
document.getElementById("popup").scrollIntoView({
115+
document.getElementById("dishTitle").scrollIntoView({
102116
behavior: "smooth"
103117
});
104118
}
@@ -113,9 +127,11 @@ html {
113127
.title {
114128
align-self: start;
115129
text-align: center;
116-
}
130+
};
131+
.dishTitle{
132+
align-self: start;
133+
text-align: center;
134+
font-size: small;
135+
}
117136
118-
.popup {
119-
120-
}
121137
</style>

src/main.js

-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import Vue from 'vue'
2-
// import app from './App.vue'
32
import home from './components/Home.vue'
43
import vuetify from './plugins/vuetify';
54
import router from './router'

0 commit comments

Comments
 (0)