fixed recipe share with sections

This commit is contained in:
vishnuraghavb 2021-06-29 17:07:04 +05:30
parent c65050d4e1
commit b82968acec

View file

@ -767,60 +767,76 @@ export default {
} }
}, },
shareRecipe() { shareRecipe() {
let overview = `${this.recipe.title}\n\n`; let r = this.recipe;
if (this.recipe.rating) let overview = `${r.title}\n\n`;
overview += `${localize("stars")}: ${this.recipe.rating}\n`; if (r.rating) overview += `${localize("stars")}: ${r.rating}\n`;
overview += `${localize("cui")}: ${localize( overview += `${localize("cui")}: ${localize(r.cuisine)}\n${localize(
this.recipe.cuisine "cat"
)}\n${localize("cat")}: ${localize(this.recipe.category)}\n`; )}: ${localize(r.category)}\n`;
if (this.recipe.tags.length) if (r.tags.length)
overview += `${localize("ts")}: ${this.recipe.tags.join(", ")}\n`; overview += `${localize("ts")}: ${r.tags.join(", ")}\n`;
if (this.recipe.prepTime != "00:00") if (r.prepTime != "00:00")
overview += `${localize("prepT")}: ${this.formattedTime( overview += `${localize("prepT")}: ${this.formattedTime(r.prepTime)}\n`;
this.recipe.prepTime if (r.cookTime != "00:00")
)}\n`; overview += `${localize("cookT")}: ${this.formattedTime(r.cookTime)}\n`;
if (this.recipe.cookTime != "00:00")
overview += `${localize("cookT")}: ${this.formattedTime(
this.recipe.cookTime
)}\n`;
overview += `${localize("yld")}: ${this.tempYieldQuantity} ${localize( overview += `${localize("yld")}: ${this.tempYieldQuantity} ${localize(
this.recipe.yieldUnit r.yieldUnit
)}\n${localize("Difficulty level")}: ${localize( )}\n${localize("Difficulty level")}: ${localize(r.difficulty)}\n`;
this.recipe.difficulty
)}\n`;
let shareContent = overview; let shareContent = overview;
if (this.recipe.ingredients.length) { if (r.ingredients.length) {
let ingredients = `\n\n${localize("ings")}:\n\n`; let ingredients = `\n\n${localize("ings")}:\n\n`;
this.recipe.ingredients.forEach((e) => { r.ingredients.forEach((e) => {
ingredients += `- ${ if (e.type) {
e.quantity ingredients += `- ${
? this.roundedQuantity(e.quantity) + e.quantity
" " + ? this.roundedQuantity(e.quantity) +
this.$options.filters.L(e.unit) + " " +
" " localize(e.unit) +
: "" " "
}${e.value}\n`; : ""
}${e.value}\n`;
} else {
ingredients += `\n${
e.quantity
? this.roundedQuantity(e.quantity) +
" " +
localize(e.unit) +
" "
: ""
}${e.value}\n\n`;
}
}); });
shareContent += ingredients; shareContent += ingredients;
} }
if (this.recipe.instructions.length) { let ins = r.instructions;
if (ins.length) {
let a = 1;
let b = 1;
let group = ins.reduce((acc, e) => {
if (!e.type) {
a = 1;
acc.push(b++);
} else acc.push(a++);
return acc;
}, []);
let instructions = `\n\n${localize("inss")}:\n\n`; let instructions = `\n\n${localize("inss")}:\n\n`;
this.recipe.instructions.forEach((e, i) => { ins.forEach(
instructions += `${i + 1}. ${e.value}\n\n`; (e, i) =>
}); (instructions += (e.type ? group[i] + ". " : "") + `${e.value}\n\n`)
);
shareContent += instructions; shareContent += instructions;
} }
if (this.recipe.combinations.length) { if (r.combinations.length) {
let combinations = `\n${localize("cmbs")}:\n\n`; let combinations = `\n${localize("cmbs")}:\n\n`;
this.recipe.combinations.forEach((e, i) => { r.combinations.forEach((e, i) => {
combinations += `${i + 1}. ${this.getCombinationTitle(e)}\n\n`; combinations += `${i + 1}. ${this.getCombinationTitle(e)}\n\n`;
}); });
shareContent += combinations; shareContent += combinations;
} }
if (this.recipe.notes.length) { if (r.notes.length) {
let notes = `\n${localize("nos")}:\n\n`; let notes = `\n${localize("nos")}:\n\n`;
this.recipe.notes.forEach((e, i) => { r.notes.forEach((e, i) => {
notes += `${i + 1}. ${e.value}\n\n`; notes += `${i + 1}. ${e.value}\n\n`;
}); });
shareContent += notes; shareContent += notes;