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 return null
} }
// When in pause, it can happen to const compareDate = new Date(
// have a tick where now is behind new Date(). record.value?.breakTime?.start ??
const mostRecentDate = new Date( // When in pause, it can happen to
Math.max(new Date(now.value).getTime(), new Date().getTime()) // have a tick where now is behind new Date().
Math.max(new Date(now.value).getTime(), new Date().getTime())
) )
return formatDiffInMinutes( return formatDiffInMinutes(
stepRecord.value.start, 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: { actions: {
syncTaskRecord(task: Task) { syncTaskRecord(task: Task) {
if (!(task.id in this.records)) { const isTaskRecorded = task.id in this.records
if (!isTaskRecorded) {
return return
} }
@@ -26,13 +28,11 @@ export const useTaskRecordStore = defineStore('task-record-store', {
const taskRecordStepIds = Object.keys(record.stepRecords) const taskRecordStepIds = Object.keys(record.stepRecords)
const taskStepIds = new Set(task.steps.map((step) => step.id)) const taskStepIds = new Set(task.steps.map((step) => step.id))
const hasSameSteps = const hasRecordedStepsStillInTask = taskRecordStepIds.every(
taskRecordStepIds.length === taskStepIds.size && (taskRecordStepId) => taskStepIds.has(taskRecordStepId)
taskRecordStepIds.every((taskRecordStepId) => )
taskStepIds.has(taskRecordStepId)
)
if (!hasSameSteps) { if (!hasRecordedStepsStillInTask) {
this.records[task.id] = new TaskRecord(task.id) this.records[task.id] = new TaskRecord(task.id)
} }
}, },