insert steps to existing task

This commit is contained in:
Julien Calixte
2023-08-29 22:57:42 +02:00
parent 0cf32b4868
commit bcba94fc9f
3 changed files with 38 additions and 13 deletions

View File

@@ -83,8 +83,12 @@ const addStepsForm = () => {
} }
const addSteps = (steps: Stepable[]) => { const addSteps = (steps: Stepable[]) => {
console.log(steps) if (!record.value.currentStepId) {
return
}
isAddingSteps.value = false isAddingSteps.value = false
taskStore.addStepsToTask(props.taskId, steps, record.value.currentStepId)
} }
const activeElement = useActiveElement() const activeElement = useActiveElement()
@@ -157,9 +161,14 @@ onUnmounted(() => {
</button> </button>
</template> </template>
<button class="button is-primary is-light" @click="addStepsForm"> <button
v-if="!record.end && record.currentStepId"
class="button is-primary is-light"
@click="addStepsForm"
>
<img src="/icons/plus.svg" alt="plus" /> <img src="/icons/plus.svg" alt="plus" />
</button> </button>
<button <button
v-if="hasStarted" v-if="hasStarted"
class="button is-warning" class="button is-warning"
@@ -168,6 +177,7 @@ onUnmounted(() => {
<img src="/icons/recycle.svg" alt="reset" /> <img src="/icons/recycle.svg" alt="reset" />
</button> </button>
</div> </div>
<div class="column message"> <div class="column message">
<p><kbd>s</kbd>: start record</p> <p><kbd>s</kbd>: start record</p>
<p><kbd>n</kbd>: next step</p> <p><kbd>n</kbd>: next step</p>

View File

@@ -12,16 +12,15 @@ const emits = defineEmits<{
}>() }>()
const steps = ref<Stepable[]>([]) const steps = ref<Stepable[]>([])
const submit = () => { const save = () => {
emits('submit', steps.value) emits('submit', steps.value)
emits('close')
steps.value = [] steps.value = []
} }
</script> </script>
<template> <template>
<div class="modal" :class="{ 'is-active': isActive }"> <div class="modal" :class="{ 'is-active': isActive }">
<div class="modal-background"></div> <div class="modal-background" @click="$emit('close')"></div>
<div class="new-step-form modal-card"> <div class="new-step-form modal-card">
<header class="modal-card-head"> <header class="modal-card-head">
<p class="modal-card-title">New steps</p> <p class="modal-card-title">New steps</p>
@@ -32,17 +31,12 @@ const submit = () => {
></button> ></button>
</header> </header>
<section class="modal-card-body"> <section class="modal-card-body">
<step-input v-model="steps" size="small" /> <step-input v-if="isActive" v-model="steps" size="small" />
</section> </section>
<footer class="modal-card-foot"> <footer class="modal-card-foot">
<button class="button is-primary" @click="submit">Save changes</button> <button class="button is-primary" @click="save">add</button>
<button class="button" @click="$emit('close')">Cancel</button> <button class="button" @click="$emit('close')">cancel</button>
</footer> </footer>
</div> </div>
</div> </div>
</template> </template>
<style scoped lang="scss">
.new-step-form {
}
</style>

View File

@@ -17,6 +17,27 @@ export const useTaskStore = defineStore('task-store', {
this.remove(task.id) this.remove(task.id)
this.tasks.push(task) 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() { reset() {
this.tasks = [] this.tasks = []
}, },