current step Id per record

This commit is contained in:
Julien Calixte
2023-05-14 13:32:12 +02:00
parent 14fbca6247
commit 0c1eb447d0
9 changed files with 28 additions and 22 deletions

View File

@@ -23,13 +23,13 @@ const getNextStepId = () => {
return null
}
if (!recordStore.currentStepId) {
if (!record.value.currentStepId) {
const [firstStep] = task.value.steps
return firstStep.id
}
const currentStepIndex = task.value.steps.findIndex(
(step) => step.id === recordStore.currentStepId
(step) => step.id === record.value.currentStepId
)
const canHaveNextIndex =
@@ -46,7 +46,9 @@ const hasStarted = computed(
() => Object.values(record.value?.stepRecords ?? {}).length > 0
)
const canStart = computed(() => !recordStore.currentStepId && !hasStarted.value)
const canStart = computed(
() => !record.value.currentStepId && !hasStarted.value
)
const startRecording = () => {
if (!canStart.value || !task.value) {
@@ -61,13 +63,13 @@ const startRecording = () => {
}
const nextStep = () => {
if (!task.value || !recordStore.currentStepId || !record.value) {
if (!task.value || !record.value.currentStepId || !record.value) {
return
}
recordStore.nextStepRecord({
taskId: record.value.taskId,
currentStepId: recordStore.currentStepId,
currentStepId: record.value.currentStepId,
nextStepId: getNextStepId(),
tick: toISODate(new Date())
})
@@ -108,7 +110,7 @@ onUnmounted(() => {
<template>
<div class="record-controls buttons has-addons">
<template v-if="record && recordStore.currentStepId">
<template v-if="record && record.currentStepId">
<button
class="button is-primary is-light"
v-if="record.breakTime"

View File

@@ -19,7 +19,9 @@ const step = computed(() => taskStore.getStep(props.taskId, props.stepId))
const stepRecord = computed(() =>
recordStore.getStepRecord(props.taskId, props.stepId)
)
const isCurrentStep = computed(() => recordStore.currentStepId === props.stepId)
const isCurrentStep = computed(
() => record.value?.currentStepId === props.stepId
)
const isInBreakTime = computed(() => !!record.value?.breakTime)
const now = ref(toISODate(new Date()))

View File

@@ -27,7 +27,6 @@ const mountTaskRecordPreview = (withRecord = false) => {
'task-store': { tasks: [task] },
'task-record-store': withRecord
? {
currentStepId: null,
records: {
[task.id]: record
}

View File

@@ -14,5 +14,6 @@ export const fixtureRecordable = (
start: toISODate(faker.datatype.datetime())
}
},
currentStepId: null,
end: partialRecordable?.end
})

View File

@@ -8,4 +8,5 @@ export interface Recordable {
stepRecords: Record<string, TimeRange>
notes: string
breakTime?: TimeRange
currentStepId: string | null
}

View File

@@ -2,12 +2,13 @@ import { toISODate } from '@/shared/types/date'
import { faker } from '@faker-js/faker'
import { describe, expect, it } from 'vitest'
import type { Recordable } from '../interfaces/recordable'
import { fixtureRecordable } from '../interfaces/recordable.fixture'
import { fixtureTimeRange } from '../interfaces/time-range.fixture'
import { TaskRecord } from './task-record'
describe('Task Record', () => {
it('creates a Record from a Recordable', () => {
const recordable: Recordable = {
const recordable: Recordable = fixtureRecordable({
taskId: faker.datatype.uuid(),
notes: faker.lorem.paragraphs(),
start: toISODate(faker.date.past(1)),
@@ -16,7 +17,7 @@ describe('Task Record', () => {
stepRecords: {
[faker.datatype.uuid()]: fixtureTimeRange()
}
}
})
expect(TaskRecord.fromRecordable(recordable)).toEqual(recordable)
})

View File

@@ -8,6 +8,7 @@ export class TaskRecord implements Recordable {
public stepRecords: Record<string, TimeRange> = {}
public notes = ''
public breakTime?: TimeRange
public currentStepId: string | null = null
public constructor(public readonly taskId: string) {}
@@ -19,6 +20,7 @@ export class TaskRecord implements Recordable {
const taskRecord = new TaskRecord(recordable.taskId)
taskRecord.stepRecords = recordable.stepRecords
taskRecord.currentStepId = recordable.currentStepId
taskRecord.start = recordable.start
taskRecord.end = recordable.end
taskRecord.breakTime = recordable.breakTime

View File

@@ -6,14 +6,12 @@ import { TaskRecord } from '../models/task-record'
import { addBreakTimeToStepRecords } from '../services/breaktime-service'
export interface TaskRecordStoreState {
currentStepId: string | null
records: { [recordId: string]: Recordable }
}
export const useTaskRecordStore = defineStore('task-record-store', {
persist: true,
state: (): TaskRecordStoreState => ({
currentStepId: null,
records: {}
}),
actions: {
@@ -57,10 +55,10 @@ export const useTaskRecordStore = defineStore('task-record-store', {
[params.stepId]: {
start: params.start
}
}
}
},
currentStepId: params.stepId
}
}
})
},
endStepRecord(params: { taskId: string; stepId: string; end: ISODate }) {
@@ -101,7 +99,7 @@ export const useTaskRecordStore = defineStore('task-record-store', {
}
this.records[taskId].end = toISODate(new Date())
this.currentStepId = null
this.records[taskId].currentStepId = null
},
updateRecordNotes(taskId: string, notes: string) {
const record = this.records[taskId]
@@ -119,12 +117,12 @@ export const useTaskRecordStore = defineStore('task-record-store', {
}
},
reset(taskId: string) {
this.currentStepId = null
if (!this.records[taskId]) {
return
}
this.records[taskId].stepRecords = {}
this.records[taskId].end = undefined
this.records[taskId].currentStepId = null
},
pause(taskId: string) {
if (this.records[taskId]?.breakTime) {

View File

@@ -1,3 +1,4 @@
import { fixtureRecordable } from '@/modules/record/interfaces/recordable.fixture'
import type { TaskRecordStoreState } from '@/modules/record/stores/useTaskRecordStore'
import { fixtureTask } from '@/modules/task/models/task.fixture'
import type { TaskStoreState } from '@/modules/task/stores/useTask.store'
@@ -18,20 +19,19 @@ const [firstTask, secondTask] = tasks
const initialState: InitialState = {
'task-store': { tasks },
'task-record-store': {
currentStepId: null,
records: {
[firstTask.id]: {
[firstTask.id]: fixtureRecordable({
taskId: firstTask.id,
stepRecords: {},
start: toISODate(new Date()),
notes: ''
},
[secondTask.id]: {
}),
[secondTask.id]: fixtureRecordable({
taskId: secondTask.id,
stepRecords: {},
start: toISODate(new Date()),
notes: ''
}
})
}
}
}