Skip to content
Snippets Groups Projects
Commit 4f292785 authored by Katarzyna Szlejter's avatar Katarzyna Szlejter
Browse files

Recipe view. Needs tests.

parent 7b8db049
No related branches found
No related tags found
1 merge request!18Recipe view. Needs tests.
Pipeline #224915 passed
...@@ -6,6 +6,7 @@ import ProfileCreationView from '../views/ProfileCreationView.vue' ...@@ -6,6 +6,7 @@ import ProfileCreationView from '../views/ProfileCreationView.vue'
import RegisterAccountView from '../views/RegisterAccountView.vue' import RegisterAccountView from '../views/RegisterAccountView.vue'
import PinCodeView from "@/views/PinCodeView.vue"; import PinCodeView from "@/views/PinCodeView.vue";
import FridgeView from "@/views/FridgeView.vue"; import FridgeView from "@/views/FridgeView.vue";
import RecipeView from "@/views/RecipeView.vue";
const router = createRouter({ const router = createRouter({
...@@ -45,6 +46,11 @@ const router = createRouter({ ...@@ -45,6 +46,11 @@ const router = createRouter({
path: '/myFridge', path: '/myFridge',
name: 'myFridge', name: 'myFridge',
component: FridgeView component: FridgeView
},
{
path: '/recipe/:id',
name: 'recipe',
component: RecipeView
} }
] ]
}) })
......
...@@ -263,4 +263,20 @@ export const API = { ...@@ -263,4 +263,20 @@ export const API = {
throw new Error("Could not fetch fridge item"); throw new Error("Could not fetch fridge item");
}); });
}, },
/**
* Get recipe based on id
* @param id
* @returns {Promise<*>}
*/
getRecipe: async (id) => {
return axios.get(`${import.meta.env.VITE_BACKEND_URL}/recipe/${id}`)
.then((response) => {
console.log(response.data);
return response.data;
})
.catch((error) => {
throw new Error(error);
})
}
} }
\ No newline at end of file
<script>
import {API} from "@/util/API";
export default {
name: "RecipeView",
data() {
return {
recipe: {},
id: this.$route.params.id,
title: "",
description: "",
time: "",
ingredients: [],
instructions: "",
}
},
methods: {
async loadData() {
await API.getRecipe(this.id)
.then((recipe) => {
this.title = recipe.title;
this.description = recipe.description;
this.time = recipe.time;
this.ingredients = recipe.ingredient;
this.instructions = recipe.instructions;
})
},
addIngredientsShoppingList() {
//TODO add ingredients to shopping list
},
removeIngredientsFromFridge() {
//TODO remove used ingredients from fridge
}
},
async mounted() {
await this.loadData();
}
}
</script>
<template>
<main>
<h1>{{this.title}}</h1><br>
<p>{{this.description}}</p><br>
<div class="ingredients">
<h2>Ingredienser</h2>
<ul>
<li v-for="ingredient in this.ingredients">{{ ingredient.item.name }} {{ ingredient.amount.quantity }} {{ingredient.amount.unit}}</li>
</ul>
<button @click="addIngredientsShoppingList">Legg til ingrediensene i handlekurven</button>
</div>
<div class="instructions">
<h2>Instruksjoner</h2>
{{this.instructions}}
</div>
<button @click="removeIngredientsFromFridge">Fjern varene fra kjøleskapet</button>
</main>
</template>
<style scoped lang="scss">
@media(min-width: base.$desktop-min) {
main {
padding-top: 45px !important;
}
}
main {
padding: 20px 10px;
.ingredients {
margin-bottom: 20px;
}
button {
min-height: 40px;
border-radius: 0;
border: 1px solid;
cursor: pointer;
padding: 5px;
}
}
</style>
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment