diff --git a/src/components/tasks/partials/singleTaskInProject.vue b/src/components/tasks/partials/singleTaskInProject.vue index 2e9fa5093..ff4948a8c 100644 --- a/src/components/tasks/partials/singleTaskInProject.vue +++ b/src/components/tasks/partials/singleTaskInProject.vue @@ -258,9 +258,7 @@ function undoDone(checked: boolean) { } async function toggleFavorite() { - task.value.isFavorite = !task.value.isFavorite - task.value = await taskService.update(task.value) - await projectStore.loadProjects() // reloading the projects list so that the Favorites project shows up or is hidden when there are (or are not) favorite tasks + task.value = taskStore.toggleFavorite(task.value) emit('task-updated', task.value) } diff --git a/src/stores/tasks.ts b/src/stores/tasks.ts index 9f26ad40b..0e4c2ee55 100644 --- a/src/stores/tasks.ts +++ b/src/stores/tasks.ts @@ -432,6 +432,17 @@ export const useTaskStore = defineStore('task', () => { coverImageAttachmentId: attachment ? attachment.id : 0, }) } + + async function toggleFavorite(task: ITask) { + const taskService = new TaskService() + task.isFavorite = !task.isFavorite + task = await taskService.update(task) + + // reloading the projects list so that the Favorites project shows up or is hidden when there are (or are not) favorite tasks + await projectStore.loadProjects() + + return task + } return { tasks, diff --git a/src/views/tasks/TaskDetailView.vue b/src/views/tasks/TaskDetailView.vue index 14a8bc078..0bae548f9 100644 --- a/src/views/tasks/TaskDetailView.vue +++ b/src/views/tasks/TaskDetailView.vue @@ -753,8 +753,7 @@ async function changeProject(project: IProject) { } async function toggleFavorite() { - task.isFavorite = !task.isFavorite - const newTask = await taskService.update(task) + const newTask = taskStore.toggleFavorite(task.value) Object.assign(task, newTask) }