From bcba94fc9f1f301a9affe50c24b19df90f54cd19 Mon Sep 17 00:00:00 2001 From: Julien Calixte Date: Tue, 29 Aug 2023 22:57:42 +0200 Subject: [PATCH] insert steps to existing task --- .../record/components/RecordControls.vue | 14 +++++++++++-- src/modules/task/components/NewStepsForm.vue | 16 +++++--------- src/modules/task/stores/useTask.store.ts | 21 +++++++++++++++++++ 3 files changed, 38 insertions(+), 13 deletions(-) diff --git a/src/modules/record/components/RecordControls.vue b/src/modules/record/components/RecordControls.vue index b00a41e..02381bd 100644 --- a/src/modules/record/components/RecordControls.vue +++ b/src/modules/record/components/RecordControls.vue @@ -83,8 +83,12 @@ const addStepsForm = () => { } const addSteps = (steps: Stepable[]) => { - console.log(steps) + if (!record.value.currentStepId) { + return + } + isAddingSteps.value = false + taskStore.addStepsToTask(props.taskId, steps, record.value.currentStepId) } const activeElement = useActiveElement() @@ -157,9 +161,14 @@ onUnmounted(() => { - + +

s: start record

n: next step

diff --git a/src/modules/task/components/NewStepsForm.vue b/src/modules/task/components/NewStepsForm.vue index 439fe3f..85f0896 100644 --- a/src/modules/task/components/NewStepsForm.vue +++ b/src/modules/task/components/NewStepsForm.vue @@ -12,16 +12,15 @@ const emits = defineEmits<{ }>() const steps = ref([]) -const submit = () => { +const save = () => { emits('submit', steps.value) - emits('close') steps.value = [] } - - diff --git a/src/modules/task/stores/useTask.store.ts b/src/modules/task/stores/useTask.store.ts index 6d438b1..e765f98 100644 --- a/src/modules/task/stores/useTask.store.ts +++ b/src/modules/task/stores/useTask.store.ts @@ -17,6 +17,27 @@ export const useTaskStore = defineStore('task-store', { this.remove(task.id) this.tasks.push(task) }, + addStepsToTask(taskId: string, steps: Stepable[], fromStepId: string) { + const task = this.tasks.find((t) => t.id === taskId) + + if (!task) { + return + } + + const fromStepIndex = task.steps.findIndex((s) => s.id === fromStepId) + + if (fromStepIndex < 0) { + return + } + + const newSteps = [ + ...task.steps.slice(0, fromStepIndex + 1), + ...steps, + ...task.steps.slice(fromStepIndex + 1) + ] + + task.steps = newSteps + }, reset() { this.tasks = [] },