fix sync task record that reset every times

This commit is contained in:
Julien Calixte
2023-08-29 22:07:30 +02:00
parent 8abe0e8caa
commit 3485a8cd8d
2 changed files with 13 additions and 12 deletions

View File

@@ -39,15 +39,16 @@ const duration = computed(() => {
return null
}
// When in pause, it can happen to
// have a tick where now is behind new Date().
const mostRecentDate = new Date(
Math.max(new Date(now.value).getTime(), new Date().getTime())
const compareDate = new Date(
record.value?.breakTime?.start ??
// When in pause, it can happen to
// have a tick where now is behind new Date().
Math.max(new Date(now.value).getTime(), new Date().getTime())
)
return formatDiffInMinutes(
stepRecord.value.start,
stepRecord.value?.end ?? toISODate(new Date(mostRecentDate))
stepRecord.value?.end ?? toISODate(new Date(compareDate))
)
})

View File

@@ -17,7 +17,9 @@ export const useTaskRecordStore = defineStore('task-record-store', {
}),
actions: {
syncTaskRecord(task: Task) {
if (!(task.id in this.records)) {
const isTaskRecorded = task.id in this.records
if (!isTaskRecorded) {
return
}
@@ -26,13 +28,11 @@ export const useTaskRecordStore = defineStore('task-record-store', {
const taskRecordStepIds = Object.keys(record.stepRecords)
const taskStepIds = new Set(task.steps.map((step) => step.id))
const hasSameSteps =
taskRecordStepIds.length === taskStepIds.size &&
taskRecordStepIds.every((taskRecordStepId) =>
taskStepIds.has(taskRecordStepId)
)
const hasRecordedStepsStillInTask = taskRecordStepIds.every(
(taskRecordStepId) => taskStepIds.has(taskRecordStepId)
)
if (!hasSameSteps) {
if (!hasRecordedStepsStillInTask) {
this.records[task.id] = new TaskRecord(task.id)
}
},