make sure task record are always sync with task
This commit is contained in:
@@ -19,10 +19,13 @@ const taskStore = useTaskStore()
|
|||||||
const recordStore = useTaskRecordStore()
|
const recordStore = useTaskRecordStore()
|
||||||
const router = useRouter()
|
const router = useRouter()
|
||||||
|
|
||||||
recordStore.addRecord(props.taskId)
|
|
||||||
|
|
||||||
const task = computed(() => taskStore.getTask(props.taskId))
|
const task = computed(() => taskStore.getTask(props.taskId))
|
||||||
|
|
||||||
|
if (task.value) {
|
||||||
|
recordStore.syncTaskRecord(task.value)
|
||||||
|
}
|
||||||
|
recordStore.addRecord(props.taskId)
|
||||||
|
|
||||||
useLoopyTitle(task.value?.title ?? '')
|
useLoopyTitle(task.value?.title ?? '')
|
||||||
|
|
||||||
const record = computed(() => recordStore.getTaskRecord(props.taskId))
|
const record = computed(() => recordStore.getTaskRecord(props.taskId))
|
||||||
|
|||||||
@@ -1,3 +1,5 @@
|
|||||||
|
import TaskList from '@/modules/task/components/TaskList.vue'
|
||||||
|
import type { Task } from '@/modules/task/models/task'
|
||||||
import { toISODate, type ISODate } from '@/shared/types/date'
|
import { toISODate, type ISODate } from '@/shared/types/date'
|
||||||
import { defineStore } from 'pinia'
|
import { defineStore } from 'pinia'
|
||||||
import type { Recordable } from '../interfaces/recordable'
|
import type { Recordable } from '../interfaces/recordable'
|
||||||
@@ -15,6 +17,26 @@ export const useTaskRecordStore = defineStore('task-record-store', {
|
|||||||
records: {}
|
records: {}
|
||||||
}),
|
}),
|
||||||
actions: {
|
actions: {
|
||||||
|
syncTaskRecord(task: Task) {
|
||||||
|
if (!(task.id in this.records)) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
const record = this.records[task.id]
|
||||||
|
|
||||||
|
const taskRecordStepIds = Object.keys(record)
|
||||||
|
const taskStepIds = new Set(task.steps.map((step) => step.id))
|
||||||
|
|
||||||
|
const hasSameSteps =
|
||||||
|
taskRecordStepIds.length === taskStepIds.size &&
|
||||||
|
taskRecordStepIds.every((taskRecordStepId) =>
|
||||||
|
taskStepIds.has(taskRecordStepId)
|
||||||
|
)
|
||||||
|
|
||||||
|
if (!hasSameSteps) {
|
||||||
|
this.records[task.id] = new TaskRecord(task.id)
|
||||||
|
}
|
||||||
|
},
|
||||||
addRecord(taskId: string) {
|
addRecord(taskId: string) {
|
||||||
if (taskId in this.records) {
|
if (taskId in this.records) {
|
||||||
return
|
return
|
||||||
@@ -104,17 +126,19 @@ export const useTaskRecordStore = defineStore('task-record-store', {
|
|||||||
updateRecordNotes(taskId: string, notes: string) {
|
updateRecordNotes(taskId: string, notes: string) {
|
||||||
const record = this.records[taskId]
|
const record = this.records[taskId]
|
||||||
|
|
||||||
if (record) {
|
if (!record) {
|
||||||
this.$patch({
|
return
|
||||||
records: {
|
|
||||||
...this.records,
|
|
||||||
[taskId]: {
|
|
||||||
...record,
|
|
||||||
notes
|
|
||||||
}
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this.$patch({
|
||||||
|
records: {
|
||||||
|
...this.records,
|
||||||
|
[taskId]: {
|
||||||
|
...record,
|
||||||
|
notes
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
},
|
},
|
||||||
reset(taskId: string) {
|
reset(taskId: string) {
|
||||||
if (!this.records[taskId]) {
|
if (!this.records[taskId]) {
|
||||||
|
|||||||
Reference in New Issue
Block a user