View Saved Recipes

This commit is contained in:
jableader 2024-01-13 18:00:55 +11:00
parent bb52d9b121
commit 7a5e7ca938
3 changed files with 27 additions and 15 deletions

View file

@ -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,11 +80,14 @@ 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) => { data.parseRecipe(this.link).then((response) => {
if (!response) if (!response)
{ {
@ -95,6 +98,10 @@ export default {
this.parse_failed = false; this.parse_failed = false;
this.recipe = response; this.recipe = response;
}); });
}
else {
this.recipe = null;
}
}, },
updateProduct(ingredient, product_link) { updateProduct(ingredient, product_link) {
data.parseProduct(ingredient, product_link).then(product => { data.parseProduct(ingredient, product_link).then(product => {

View file

@ -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],

View file

@ -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