undo deletion with index
This commit is contained in:
parent
07dae68939
commit
a005016bd0
1 changed files with 39 additions and 12 deletions
|
@ -92,7 +92,7 @@
|
||||||
col="1"
|
col="1"
|
||||||
class="ico x"
|
class="ico x"
|
||||||
:text="icon.x"
|
:text="icon.x"
|
||||||
@tap="removeRecipe(recipeID, mealType)"
|
@tap="removeRecipe(mealType, recipeID)"
|
||||||
/>
|
/>
|
||||||
</GridLayout>
|
</GridLayout>
|
||||||
</StackLayout>
|
</StackLayout>
|
||||||
|
@ -177,6 +177,7 @@ export default {
|
||||||
showUndo: false,
|
showUndo: false,
|
||||||
undo: false,
|
undo: false,
|
||||||
MPSettings: MPSettings,
|
MPSettings: MPSettings,
|
||||||
|
temp: 0,
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
computed: {
|
computed: {
|
||||||
|
@ -339,13 +340,6 @@ export default {
|
||||||
setToday(date) {
|
setToday(date) {
|
||||||
if (date) this.date = date;
|
if (date) this.date = date;
|
||||||
},
|
},
|
||||||
newMealPlan(date, type, title) {
|
|
||||||
this.addMealPlanAction({
|
|
||||||
date: date ? date : this.todaysTime,
|
|
||||||
type,
|
|
||||||
title,
|
|
||||||
});
|
|
||||||
},
|
|
||||||
toggleEditMode() {
|
toggleEditMode() {
|
||||||
this.edit = !this.edit;
|
this.edit = !this.edit;
|
||||||
},
|
},
|
||||||
|
@ -366,6 +360,15 @@ export default {
|
||||||
},
|
},
|
||||||
|
|
||||||
// DATA HANDLERS
|
// DATA HANDLERS
|
||||||
|
newMealPlan({ date, type, title, index, inDB }) {
|
||||||
|
this.addMealPlanAction({
|
||||||
|
date: date ? date : this.todaysTime,
|
||||||
|
type,
|
||||||
|
title,
|
||||||
|
index,
|
||||||
|
inDB,
|
||||||
|
});
|
||||||
|
},
|
||||||
addRecipe(type) {
|
addRecipe(type) {
|
||||||
let filteredRecipes = this.recipes.filter((e) =>
|
let filteredRecipes = this.recipes.filter((e) =>
|
||||||
this.getRecipes[type] ? !this.getRecipes[type].includes(e.id) : true
|
this.getRecipes[type] ? !this.getRecipes[type].includes(e.id) : true
|
||||||
|
@ -375,20 +378,43 @@ export default {
|
||||||
title: "selRec",
|
title: "selRec",
|
||||||
recipes: filteredRecipes,
|
recipes: filteredRecipes,
|
||||||
},
|
},
|
||||||
}).then((title) => title && this.newMealPlan(null, type, title));
|
}).then(
|
||||||
|
(title) =>
|
||||||
|
title &&
|
||||||
|
this.newMealPlan({ date: 0, type, title, index: null, inDB: true })
|
||||||
|
);
|
||||||
},
|
},
|
||||||
removeRecipe(title, type) {
|
deleteTempFromDB() {
|
||||||
|
if (this.temp) {
|
||||||
|
this.temp.inDB = 1;
|
||||||
|
this.deleteMealPlanAction(this.temp);
|
||||||
|
this.temp = 0;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
removeRecipe(type, title) {
|
||||||
|
this.deleteTempFromDB();
|
||||||
let date = this.todaysTime;
|
let date = this.todaysTime;
|
||||||
|
let index = this.mealPlans.findIndex(
|
||||||
|
(e) => e.date == date && e.type == type && e.title == title
|
||||||
|
);
|
||||||
let mealPlan = {
|
let mealPlan = {
|
||||||
date,
|
date,
|
||||||
type,
|
type,
|
||||||
title,
|
title,
|
||||||
|
index,
|
||||||
};
|
};
|
||||||
|
let temp;
|
||||||
|
this.temp = temp = mealPlan;
|
||||||
this.deleteMealPlanAction(mealPlan);
|
this.deleteMealPlanAction(mealPlan);
|
||||||
this.showUndoBar("recRm").then(() => this.newMealPlan(date, type, title));
|
this.showUndoBar("recRm")
|
||||||
|
.then(() => this.newMealPlan({ date, type, title, index }))
|
||||||
|
.catch(() => {
|
||||||
|
temp.inDB = 1;
|
||||||
|
console.log("deleting inDB after catch: ", temp);
|
||||||
|
this.deleteMealPlanAction(temp);
|
||||||
|
});
|
||||||
},
|
},
|
||||||
showUndoBar(message) {
|
showUndoBar(message) {
|
||||||
clearInterval(barTimer);
|
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
this.animateBar(this.appbar, 0).then(() => {
|
this.animateBar(this.appbar, 0).then(() => {
|
||||||
this.showUndo = true;
|
this.showUndo = true;
|
||||||
|
@ -396,6 +422,7 @@ export default {
|
||||||
this.countdown = 5;
|
this.countdown = 5;
|
||||||
this.animateBar(this.snackbar, 1).then(() => {
|
this.animateBar(this.snackbar, 1).then(() => {
|
||||||
let a = 5;
|
let a = 5;
|
||||||
|
clearInterval(barTimer);
|
||||||
barTimer = setInterval(() => {
|
barTimer = setInterval(() => {
|
||||||
if (this.undo) {
|
if (this.undo) {
|
||||||
this.hideBar();
|
this.hideBar();
|
||||||
|
|
Loading…
Reference in a new issue