FIX: saving w/ navigation

This commit is contained in:
Geoff Doty 2020-10-04 17:26:05 -04:00
parent b234b6ac7b
commit d96faaa5b1
1 changed files with 22 additions and 18 deletions

View File

@ -60,8 +60,8 @@ Litedom({
// delete entry
db.entries.delete(this.data.history[idx].id).then(() => {
// update entries list
this.entries();
// update entries
this.setDate(0);
});
},
modify(e) {
@ -89,7 +89,7 @@ Litedom({
modified: Date.now(),
}).then(() => {
// refresh entries
this.entries();
this.setDate(0);
// clear choices
this.data.choices = [];
@ -122,12 +122,15 @@ Litedom({
target: 'calorie',
type: source(calories),
value: Number(calories.value),
day: this.data.today,
day: this.data.current.day,
created: Date.now(),
modified: Date.now(),
}).then(async () => {
// update todays history
this.entries();
// update
this.setDate(0);
// clear choices
this.data.choices = [];
}).catch((err) => {
console.error(err);
});
@ -138,9 +141,16 @@ Litedom({
// set focus
document.getElementById('calories').focus();
},
async setDate(date, change) {
// currently selected data
let current = new Date(Date.parse(date));
async setDate(change = 0) {
let current;
// currently selected date
if (this.data.current.day) {
current = new Date(Date.parse(this.data.current.day));
} else {
current = new Date();
}
// date back one day
let alter = new Date(current.setDate(current.getDate() + Number(change)));
@ -164,19 +174,13 @@ Litedom({
}
},
async back() {
// currently selected data
let current = new Date(Date.parse(this.data.current.day));
await this.setDate(current, -1);
await this.setDate(-1);
},
async today() {
await this.setDate(new Date(), 0);
await this.setDate(0);
},
async forward() {
// currently selected data
let current = new Date(Date.parse(this.data.current.day));
await this.setDate(current, +1);
await this.setDate(+1);
},
addWeight() {
console.log('add weight');