cuizin/cuizin/js_src/components/Recipe.vue

95 lines
2.3 KiB
Vue
Raw Normal View History

2018-02-27 17:47:32 +01:00
<template>
2018-03-03 11:41:23 +01:00
<v-container grid-list-md class="panel">
<v-layout row>
<v-flex xs12 v-if="recipe">
2018-02-28 22:06:21 +01:00
<h1 class="text-xs-center mt-3 mb-3">
2018-03-03 11:41:23 +01:00
{{ recipe.title }}
2018-02-28 22:06:21 +01:00
</h1>
2018-03-03 11:41:23 +01:00
<p>
</p>
2018-02-28 22:06:21 +01:00
<p class="text-xs-center">
2018-03-03 11:41:23 +01:00
<img :src="recipe.picture" />
2018-02-28 22:06:21 +01:00
</p>
2018-03-03 11:41:23 +01:00
<v-layout row class="text-xs-center">
2018-02-28 22:06:21 +01:00
<v-flex xs6>
2018-03-03 11:41:23 +01:00
<p>{{ recipe.nb_person }}</p>
2018-02-28 22:06:21 +01:00
</v-flex>
<v-flex xs6>
2018-03-03 11:41:23 +01:00
<p><v-icon>timelapse</v-icon> Preparation: {{ recipe.preparation_time }}&nbsp;mins</p>
<p><v-icon>whatshot</v-icon> Cooking: {{ recipe.cooking_time }}&nbsp;mins</p>
2018-02-28 22:06:21 +01:00
</v-flex>
</v-layout>
2018-03-03 11:41:23 +01:00
<p>{{ recipe.short_description }}</p>
<h2>Ingredients</h2>
<ul class="ml-5">
<li v-for="ingredient in recipe.ingredients">
{{ ingredient }}
</li>
2018-02-28 23:11:22 +01:00
</ul>
2018-03-03 11:41:23 +01:00
<h2 class="mt-3">Instructions</h2>
2018-03-03 12:02:47 +01:00
<nl2br tag="p" :text="recipe.instructions"></nl2br>
2018-03-03 11:41:23 +01:00
<p v-if="recipe.url" class="text-xs-center">
<v-btn :href="recipe.url">
<v-icon class="fa-icon">fa-external-link</v-icon>
</v-btn>
<v-btn @click="handleDelete">
<v-icon>delete</v-icon>
</v-btn>
2018-02-28 22:06:21 +01:00
</p>
2018-02-27 17:47:32 +01:00
</v-flex>
</v-layout>
</v-container>
</template>
<script>
import * as constants from '@/constants';
export default {
data() {
return {
isLoading: false,
recipe: null,
};
},
created() {
this.fetchRecipe();
},
watch: {
// call again the method if the route changes
$route: 'fetchRecipe',
},
methods: {
fetchRecipe() {
this.isLoading = true;
fetch(`${constants.API_URL}api/v1/recipe/${this.$route.params.recipeId}`)
2018-02-27 17:47:32 +01:00
.then(response => response.json())
.then((response) => {
this.recipe = response.recipes[0];
this.isLoading = false;
});
},
2018-02-28 22:06:21 +01:00
handleDelete() {
fetch(`${constants.API_URL}api/v1/recipe/${this.$route.params.recipeId}`, {
2018-02-28 22:06:21 +01:00
method: 'DELETE',
})
.then(() => this.$router.replace('/'));
},
2018-02-27 17:47:32 +01:00
},
};
</script>
2018-02-28 22:06:21 +01:00
<style scoped>
img {
2018-03-03 11:41:23 +01:00
width: 100%;
}
.panel {
max-width: 600px;
}
.fa-icon {
font-size: 20px;
2018-02-28 22:06:21 +01:00
}
</style>