feat: improve loadTask logic
continuous-integration/drone/pr Build is passing Details

This commit is contained in:
Dominik Pschenitschni 2022-11-11 22:20:15 +01:00
parent 244c436202
commit b11d3de8da
Signed by: dpschen
GPG Key ID: B257AC0149F43A77
1 changed files with 6 additions and 7 deletions

View File

@ -445,7 +445,7 @@
</template> </template>
<script lang="ts" setup> <script lang="ts" setup>
import {ref, reactive, toRef, shallowReactive, computed, watch, watchEffect, nextTick, type PropType} from 'vue' import {ref, reactive, toRef, shallowReactive, computed, watch, nextTick, type PropType} from 'vue'
import {useRouter, type RouteLocation} from 'vue-router' import {useRouter, type RouteLocation} from 'vue-router'
import {useI18n} from 'vue-i18n' import {useI18n} from 'vue-i18n'
import {unrefElement} from '@vueuse/core' import {unrefElement} from '@vueuse/core'
@ -590,13 +590,14 @@ async function scrollToHeading() {
const taskService = shallowReactive(new TaskService()) const taskService = shallowReactive(new TaskService())
async function loadTask(taskId: ITask['id']) { // load task
if (taskId === undefined) { watch(taskId, async (id) => {
if (id === undefined) {
return return
} }
try { try {
Object.assign(task, await taskService.get({id: taskId})) Object.assign(task, await taskService.get({id}))
attachmentStore.set(task.attachments) attachmentStore.set(task.attachments)
taskColor.value = task.hexColor taskColor.value = task.hexColor
setActiveFields() setActiveFields()
@ -605,9 +606,7 @@ async function loadTask(taskId: ITask['id']) {
scrollToHeading() scrollToHeading()
visible.value = true visible.value = true
} }
} }, {immediate: true})
watchEffect(() => taskId.value !== undefined && loadTask(taskId.value))
type FieldType = type FieldType =
| 'assignees' | 'assignees'