View Saved Recipes
This commit is contained in:
parent
bb52d9b121
commit
7a5e7ca938
3 changed files with 27 additions and 15 deletions
|
|
@ -1,6 +1,6 @@
|
||||||
<template>
|
<template>
|
||||||
<div>
|
<div>
|
||||||
<div>
|
<div v-if="!id">
|
||||||
<input class="recipe-link" type="text" v-model="link" placeholder="Link to Recipe" />
|
<input class="recipe-link" type="text" v-model="link" placeholder="Link to Recipe" />
|
||||||
<button @click="parseLink">Parse</button>
|
<button @click="parseLink">Parse</button>
|
||||||
</div>
|
</div>
|
||||||
|
|
@ -80,21 +80,28 @@ export default {
|
||||||
this.refreshRecipe();
|
this.refreshRecipe();
|
||||||
},
|
},
|
||||||
refreshRecipe() {
|
refreshRecipe() {
|
||||||
if (!this.link) {
|
if (this.id) {
|
||||||
this.recipe = null;
|
data.getRecipe(this.id).then((response) => {
|
||||||
return
|
this.recipe = response;
|
||||||
|
this.link = response.link;
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
else if (this.link) {
|
||||||
|
data.parseRecipe(this.link).then((response) => {
|
||||||
|
if (!response)
|
||||||
|
{
|
||||||
|
this.parse_failed = true;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
this.parse_failed = false;
|
||||||
|
this.recipe = response;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
this.recipe = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
data.parseRecipe(this.link).then((response) => {
|
|
||||||
if (!response)
|
|
||||||
{
|
|
||||||
this.parse_failed = true;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
this.parse_failed = false;
|
|
||||||
this.recipe = response;
|
|
||||||
});
|
|
||||||
},
|
},
|
||||||
updateProduct(ingredient, product_link) {
|
updateProduct(ingredient, product_link) {
|
||||||
data.parseProduct(ingredient, product_link).then(product => {
|
data.parseProduct(ingredient, product_link).then(product => {
|
||||||
|
|
|
||||||
|
|
@ -15,6 +15,10 @@ export default {
|
||||||
return fetch(BASE_URL + `/recipes/parse?url=${encodeURIComponent(url)}`)
|
return fetch(BASE_URL + `/recipes/parse?url=${encodeURIComponent(url)}`)
|
||||||
.then(response => response.json())
|
.then(response => response.json())
|
||||||
},
|
},
|
||||||
|
getRecipe(id) {
|
||||||
|
return fetch(BASE_URL + `/recipes/${encodeURIComponent(id)}`)
|
||||||
|
.then(response => response.json())
|
||||||
|
},
|
||||||
parseProduct(ingredient, url) {
|
parseProduct(ingredient, url) {
|
||||||
const body = {
|
const body = {
|
||||||
url, tags: [ingredient.name, ingredient.line],
|
url, tags: [ingredient.name, ingredient.line],
|
||||||
|
|
|
||||||
|
|
@ -20,6 +20,7 @@ const routes = [
|
||||||
{ path: '/meal/:id/edit', component: EditMealPage },
|
{ path: '/meal/:id/edit', component: EditMealPage },
|
||||||
{ path: '/meal/:id/swap', component: SwapMealPage },
|
{ path: '/meal/:id/swap', component: SwapMealPage },
|
||||||
{ path: '/recipes/add', component: EditRecipePage },
|
{ path: '/recipes/add', component: EditRecipePage },
|
||||||
|
{ path: '/recipes/:id', component: EditRecipePage, props: true },
|
||||||
]
|
]
|
||||||
|
|
||||||
// 3. Create the router instance and pass the `routes` option
|
// 3. Create the router instance and pass the `routes` option
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue