improved mark recipes as done

This commit is contained in:
vishnuraghavb 2021-06-29 20:31:03 +05:30
parent bc46115e63
commit 2f1c5d42c4
3 changed files with 65 additions and 54 deletions

View file

@ -608,6 +608,7 @@ export default {
}, },
pgUnload() { pgUnload() {
if (this.shake) stopAccelerometerUpdates(); if (this.shake) stopAccelerometerUpdates();
this.releaseBackEvent();
}, },
abLoad({ object }) { abLoad({ object }) {
this.appbar = object; this.appbar = object;

View file

@ -66,7 +66,7 @@
:class="{ r: RTL }" :class="{ r: RTL }"
> >
<RLabel class="sub" :text="'ts' | L" /> <RLabel class="sub" :text="'ts' | L" />
<RLabel class="v" :text="getTags(recipe.tags)" /> <RLabel class="v" :text="getTags" />
</StackLayout> </StackLayout>
<RGridLayout :rtl="RTL" rows="auto" columns="*, *"> <RGridLayout :rtl="RTL" rows="auto" columns="*, *">
<StackLayout class="attrT" :hidden="!hasTime(recipe.prepTime)"> <StackLayout class="attrT" :hidden="!hasTime(recipe.prepTime)">
@ -120,7 +120,7 @@
<RLabel <RLabel
class="v tw" class="v tw"
:class="{ 'tb t t3': !item.type }" :class="{ 'tb t t3': !item.type }"
:text="getIngredientItem(item)" :text="getIng(item)"
/> />
</RStackLayout> </RStackLayout>
</StackLayout> </StackLayout>
@ -234,7 +234,7 @@
col="2" col="2"
v-else v-else
class="ico" class="ico"
:text="icon.done" :text="recipeTried ? icon.try : icon.done"
@tap="toggle('tried', 1)" @tap="toggle('tried', 1)"
/> />
<Button <Button
@ -318,7 +318,6 @@ import * as utils from "~/shared/utils";
const Intl = require("nativescript-intl"); const Intl = require("nativescript-intl");
let barTimer; let barTimer;
declare const android: any; declare const android: any;
export default { export default {
components: { Toast }, components: { Toast },
props: ["filterTrylater", "recipeID", "yieldQuantity"], props: ["filterTrylater", "recipeID", "yieldQuantity"],
@ -348,6 +347,8 @@ export default {
view: null, view: null,
wv: null, wv: null,
showTools: 0, showTools: 0,
snackMsg: null,
recipeTried: 0,
}; };
}, },
computed: { computed: {
@ -378,6 +379,9 @@ export default {
hasPrinterSupport() { hasPrinterSupport() {
return utils.Printer.isSupported(); return utils.Printer.isSupported();
}, },
getTags() {
return this.recipe.tags.join(" · ");
},
}, },
methods: { methods: {
...mapActions(["toggleState", "setR"]), ...mapActions(["toggleState", "setR"]),
@ -392,6 +396,7 @@ export default {
}, },
onPageUnload() { onPageUnload() {
utils.keepScreenOn(0); utils.keepScreenOn(0);
if (this.recipeTried) this.markTried();
}, },
sbload({ object }) { sbload({ object }) {
this.sidebar = object; this.sidebar = object;
@ -401,7 +406,7 @@ export default {
}, },
tbLoad({ object }) { tbLoad({ object }) {
this.toastbar = object; this.toastbar = object;
this.recipe.tried && this.recipe.lastTried && this.showLastTried(); this.recipe.lastTried && this.showLastTried();
}, },
wvLoad({ object }) { wvLoad({ object }) {
this.wv = object; this.wv = object;
@ -527,7 +532,7 @@ export default {
let text = s && !unsel ? ` (${s}/${c})` : ` (${c})`; let text = s && !unsel ? ` (${s}/${c})` : ` (${c})`;
return localize(title) + text; return localize(title) + text;
}, },
getIngredientItem(o) { getIng(o) {
return `${ return `${
this.roundedQuantity(o.quantity) this.roundedQuantity(o.quantity)
? this.roundedQuantity(o.quantity) + " " ? this.roundedQuantity(o.quantity) + " "
@ -614,10 +619,6 @@ export default {
minute: "numeric", minute: "numeric",
}).format(new Date(date)); }).format(new Date(date));
}, },
isValidURL(string) {
let pattern = new RegExp("^https?|^www", "ig");
return pattern.test(string);
},
getCombinationTitle(id) { getCombinationTitle(id) {
return this.recipes.filter((e) => e.id === id)[0].title; return this.recipes.filter((e) => e.id === id)[0].title;
}, },
@ -692,6 +693,22 @@ export default {
}, },
// NavigationHandlers // NavigationHandlers
hijackBackEvent() {
Application.android.on(
AndroidApplication.activityBackPressedEvent,
this.backEvent
);
},
releaseBackEvent() {
Application.android.off(
AndroidApplication.activityBackPressedEvent,
this.backEvent
);
},
backEvent(args) {
args.cancel = true;
this.closePhoto();
},
editRecipe() { editRecipe() {
this.busyEdit = 1; this.busyEdit = 1;
this.$navigateTo(EditRecipe, { this.$navigateTo(EditRecipe, {
@ -714,7 +731,7 @@ export default {
this.syncCombinations(); this.syncCombinations();
this.createNotes(); this.createNotes();
this.yieldMultiplier = this.recipe.yieldQuantity; this.yieldMultiplier = this.recipe.yieldQuantity;
this.recipe.tried && this.recipe.lastTried && this.showLastTried(); this.recipe.lastTried && this.showLastTried();
}, },
// Tools // Tools
@ -847,19 +864,25 @@ export default {
}, },
// DataHandlers // DataHandlers
toggle(key: string, setDate: boolean) { toggle(key: string, setDate: number) {
console.log(setDate);
if (setDate) {
this.recipeTried = !this.recipeTried;
} else
this.toggleState({ this.toggleState({
id: this.currentRecipeID, id: this.currentRecipeID,
key, key,
setDate, setDate,
}); });
if (setDate) this.$navigateBack();
}, },
touchRate({ object, action }, r) { markTried() {
this.touchFade(object, action); this.toggleState({
if (action == "up") this.setRating(r); id: this.currentRecipeID,
key: "tried",
setDate: 1,
});
}, },
setRating(r) { rate(r) {
if (r !== this.recipe.rating || r === 1) { if (r !== this.recipe.rating || r === 1) {
if (this.recipe.rating == 1 && r == 1) r = 0; if (this.recipe.rating == 1 && r == 1) r = 0;
this.setR({ this.setR({
@ -869,8 +892,6 @@ export default {
} }
}, },
// ShoppingList
// Notes // Notes
createNote(note) { createNote(note) {
let regex = /(https?:\/\/[^\s]+)/g; let regex = /(https?:\/\/[^\s]+)/g;
@ -903,27 +924,12 @@ export default {
stack.addChild(this.createNote(note.value)) stack.addChild(this.createNote(note.value))
); );
}, },
getTags(tags) { isValidURL(s) {
return tags.join(" · "); let pattern = new RegExp("^https?|^www", "ig");
}, return pattern.test(s);
hijackBackEvent() {
Application.android.on(
AndroidApplication.activityBackPressedEvent,
this.backEvent
);
},
releaseBackEvent() {
Application.android.off(
AndroidApplication.activityBackPressedEvent,
this.backEvent
);
},
backEvent(args) {
if (this.photoOpen) {
args.cancel = true;
this.closePhoto();
} else this.$navigateBack();
}, },
// PhotoViewer
viewPhoto() { viewPhoto() {
this.hideBars(); this.hideBars();
this.photoOpen = 1; this.photoOpen = 1;
@ -994,7 +1000,7 @@ export default {
}); });
}, },
//DuplicateRecipe // Duplicate
duplicateRecipe() { duplicateRecipe() {
this.busyDup = 1; this.busyDup = 1;
let dupRecipe = Object.assign({}, this.recipe); let dupRecipe = Object.assign({}, this.recipe);
@ -1027,9 +1033,9 @@ export default {
i < ings.length - 1 ? "<ul>" : "" i < ings.length - 1 ? "<ul>" : ""
}`; }`;
else else
return `${i < 1 ? "<ul>" : ""}<li>${this.getIngredientItem( return `${i < 1 ? "<ul>" : ""}<li>${this.getIng(e)}</li>${
e i == ings.length - 1 ? "</ul>" : ""
)}</li>${i == ings.length - 1 ? "</ul>" : ""}`; }`;
}) })
.join(""); .join("");
}; };
@ -1085,7 +1091,7 @@ export default {
r.tags.length r.tags.length
? `<div class=attr><div style="grid-column:span 2"><p>${localize( ? `<div class=attr><div style="grid-column:span 2"><p>${localize(
"ts" "ts"
)}<p>${this.getTags(r.tags)}</div></div>` )}<p>${this.getTags}</div></div>`
: "" : ""
} ${ } ${
this.hasTime(r.prepTime) || this.hasTime(r.cookTime) this.hasTime(r.prepTime) || this.hasTime(r.cookTime)
@ -1139,6 +1145,10 @@ export default {
}, },
// Helpers // Helpers
touchRate({ object, action }, r) {
this.touchFade(object, action);
if (action == "up") this.rate(r);
},
touchYield({ object, action }) { touchYield({ object, action }) {
this.touchFade(object, action); this.touchFade(object, action);

View file

@ -1173,16 +1173,16 @@ export default new Vuex.Store({
} }
}, },
toggleState(state, { id, key, setDate }) { toggleState(state, { id, key, setDate }) {
let i = state.recipes.findIndex((e) => e.id == id) let res = state.recipes
state.recipes[i][key] = state.recipes[i][key] ? 0 : 1 let i = res.findIndex((e) => e.id == id)
state.recipes[i][key] = +!res[i][key]
db.execute( db.execute(
`UPDATE recipes SET ${key} = ${state.recipes[i][key]} WHERE id = '${id}'` `UPDATE recipes SET ${key} = ${res[i][key]} WHERE id = '${id}'`
) )
if (setDate) { if (setDate) {
state.recipes[i].lastTried = new Date().getTime() let time = new Date().getTime()
db.execute( state.recipes[i].lastTried = time
`UPDATE recipes SET lastTried = ${state.recipes[i].lastTried} WHERE id = '${id}'` db.execute(`UPDATE recipes SET lastTried = ${time} WHERE id = '${id}'`)
)
} }
}, },
// UnLinkCombinations // UnLinkCombinations