feat: improve loadTask logic #2715

Merged
konrad merged 1 commits from dpschen/frontend:feature/improve-task-loading-logic into main 2022-11-17 15:31:23 +00:00
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'