Tasks: presave active task, able to edit on button action

This commit is contained in:
2023-12-31 18:10:00 +01:00
parent dabd5ea0f0
commit cb529e47d9
3 changed files with 63 additions and 11 deletions

View File

@ -30,15 +30,16 @@ export default {
timer: undefined,
timerState: 'Start',
task: {
startTime: 0,
stopTime: 0,
timeStart: 0,
timeEnd: 0,
title: ''
}
},
restore: false
}
},
computed: {
formattedElapsedTime() {
const date = new Date(this.timeNow - this.task.startTime)
const date = new Date(this.timeNow - this.task.timeStart)
const utc = date.toUTCString()
return utc.substr(utc.indexOf(':') - 2, 8)
}
@ -47,33 +48,60 @@ export default {
async startStopTimer() {
if (this.timerState == 'Start') {
this.timerState = 'Stop'
this.task.startTime = Date.now()
console.log('TADY', this.restore)
if (this.restore == false) {
console.log('TADY')
this.task.timeStart = Date.now()
}
this.timeNow = Date.now()
console.log('timer started')
this.timer = setInterval(() => {
this.timeNow = Date.now()
}, 1000)
if (!this.task._id) {
AppStore.data.newTask = {
title: this.task.title,
timeStart: this.task.timeStart
}
await AppStore.sendAdd(AppStore.data.newTask, '/task/add')
}
} else {
this.task.stopTime = Date.now()
this.task.timeEnd = Date.now()
this.timerState = 'Start'
clearInterval(this.timer)
this.timer = undefined
this.timeNow = 0
AppStore.data.newTask = {
title: this.task.title,
timeStart: this.task.startTime,
timeEnd: this.task.stopTime
timeStart: this.task.timeStart,
timeEnd: this.task.timeEnd
}
if (this.task._id) {
AppStore.data.newTask._id = this.task._id
await AppStore.sendAdd(AppStore.data.newTask, '/task/edit')
} else {
await AppStore.sendAdd(AppStore.data.newTask, '/task/add')
}
await AppStore.sendAdd(AppStore.data.newTask, '/task/add')
this.task = {
startTime: 0,
stopTime: 0,
timeStart: 0,
timeEnd: 0,
title: ''
}
this.restore = false
this.$emit('get-tasks')
}
}
},
async mounted() {
await AppStore.fetchData()
const task = AppStore.data.fetchedTasks.filter((task) => task.timeEnd === null)
if (task.length > 0) {
this.task = task[0]
this.restore = true
this.startStopTimer()
}
}
}
</script>