parsley/app/javascript/components/TheRecipe.vue

80 lines
2.0 KiB
Vue
Raw Normal View History

2018-04-01 21:43:23 -05:00
<template>
<div>
<div v-if="recipe === null">
Loading...
</div>
<div v-else>
2018-04-14 15:04:08 -05:00
<h1 class="title">{{ recipe.name }}</h1>
<div class="subtitle tags">
<span v-for="tag in recipe.tags" :key="tag" class="tag is-medium">{{tag}}</span>
</div>
2018-04-17 09:59:38 -05:00
<div class="tags">
<span v-if="isScaled" class="tag is-large">{{recipe.converted_scale}} X</span>
<span v-if="recipe.converted_system !== null" class="tag is-large">{{recipe.converted_system}}</span>
<span v-if="recipe.converted_unit !== null" class="tag is-large">{{recipe.converted_unit}}</span>
</div>
2018-04-14 15:04:08 -05:00
<hr>
2018-04-01 21:43:23 -05:00
<recipe-show :recipe="recipe"></recipe-show>
</div>
2018-04-03 18:31:20 -05:00
<router-link v-if="isLoggedIn" class="button" :to="{name: 'edit_recipe', params: { id: recipeId }}">Edit</router-link>
2018-04-01 22:32:13 -05:00
<router-link class="button" to="/">Back</router-link>
2018-04-01 21:43:23 -05:00
</div>
</template>
<script>
import RecipeShow from "./RecipeShow";
import { mapState } from "vuex";
import api from "../lib/Api";
export default {
data: function () {
return {
recipe: null,
showNutrition: false
}
},
computed: {
...mapState({
recipeId: state => state.route.params.id,
2018-04-17 09:59:38 -05:00
routeQuery: state => state.route.query,
2018-04-16 11:28:58 -05:00
scale: state => state.route.query.scale || null,
system: state => state.route.query.system || null,
unit: state => state.route.query.unit || null
2018-04-17 09:59:38 -05:00
}),
isScaled() {
return this.recipe.converted_scale !== null && this.recipe.converted_scale.length > 0 && this.recipe.converted_scale !== "1";
}
},
watch: {
routeQuery() {
this.refreshData();
}
},
methods: {
refreshData() {
this.loadResource(
api.getRecipe(this.recipeId, this.scale, this.system, this.unit)
.then(data => { this.recipe = data; return data; })
);
}
2018-04-01 21:43:23 -05:00
},
created() {
2018-04-17 09:59:38 -05:00
this.refreshData();
2018-04-01 21:43:23 -05:00
},
components: {
RecipeShow
}
}
</script>
<style lang="scss" scoped>
</style>