diff --git a/src/components/EditRecipePage.vue b/src/components/EditRecipePage.vue
index ad8b39c..9ea98f6 100644
--- a/src/components/EditRecipePage.vue
+++ b/src/components/EditRecipePage.vue
@@ -4,21 +4,22 @@
-
+
-
@@ -63,33 +64,35 @@ export default {
},
data() {
return {
- link: "",
- parsed: null,
+ link: this.$route.query.url ?? "",
+ parse_failed: false,
recipe: null,
chefs: []
}
},
mounted() {
- if (this.$route.query.url) {
- this.link = this.$route.query.url
- data.parseRecipe(this.link).then((response) => {
- if (!response)
- {
- this.parsed = true;
- return;
- }
-
- this.recipe = response.recipe;
- this.parsed = response.raw;
- });
- }
+ this.refreshRecipe();
},
methods: {
parseLink() {
this.$router.push({ path: '/recipes/add', query: { url: this.link }})
+ this.refreshRecipe();
+ },
+ refreshRecipe() {
+ if (!this.link) {
+ this.recipe = null;
+ return
+ }
+
data.parseRecipe(this.link).then((response) => {
- this.recipe = response.recipe;
- this.parsed = response.raw;
+ if (!response)
+ {
+ this.parse_failed = true;
+ return;
+ }
+
+ this.parse_failed = false;
+ this.recipe = response;
});
},
updateProduct(ingredient, product_link) {
@@ -102,13 +105,19 @@ export default {
const newIngredient = newIngredients[0];
ingredient.line = line;
ingredient.name = newIngredient.name;
- ingredient.measure = newIngredient.measure;
+ ingredient.quantity = newIngredient.quantity;
+ ingredient.unit = newIngredient.unit;
ingredient.preparation = newIngredient.preparation;
if (newIngredient.product) {
ingredient.product = newIngredient.product;
}
});
},
+ saveRecipe() {
+ data.saveRecipe(this.recipe).then((response) => {
+ this.$router.push(`/recipes/${response.id}`)
+ });
+ }
},
}
\ No newline at end of file
diff --git a/src/components/IngredientLine.vue b/src/components/IngredientLine.vue
index 17a39bf..96549f4 100644
--- a/src/components/IngredientLine.vue
+++ b/src/components/IngredientLine.vue
@@ -17,8 +17,8 @@
Ingredient: {{ ingredient.name }}
-
Quantity: {{ ingredient.measure.qty }}
-
Unit: {{ ingredient.measure.unit }}
+
Quantity: {{ ingredient.quantity }}
+
Unit: {{ ingredient.unit }}
Preparation: {{ ingredient.preparation }}
diff --git a/src/data.js b/src/data.js
index 9aa6920..fb9b29b 100644
--- a/src/data.js
+++ b/src/data.js
@@ -19,7 +19,7 @@ export default {
const body = {
url, tags: [ingredient.name, ingredient.line],
}
-
+
return fetch(BASE_URL + "/products", {
method: "POST",
headers: {
@@ -32,5 +32,14 @@ export default {
const params = lines.map(line => "ingredients=" + encodeURIComponent(line)).join("&");
return fetch(BASE_URL + "/recipes/ingredients/parse?" + params)
.then(response => response.json())
+ },
+ saveRecipe(recipe) {
+ return fetch(BASE_URL + "/recipes", {
+ method: "POST",
+ headers: {
+ "Content-Type": "application/json"
+ },
+ body: JSON.stringify(recipe),
+ }).then(response => response.json())
}
}
\ No newline at end of file