1
0

fix(quick add magic): make sure assignees which don't exist are not removed from task title

Resolves https://kolaente.dev/vikunja/frontend/issues/2927
This commit is contained in:
kolaente
2023-01-12 13:32:00 +01:00
parent 5999def569
commit 2af42f8fbe
6 changed files with 50 additions and 31 deletions

View File

@ -97,7 +97,7 @@ export const useBaseStore = defineStore('base', () => {
// The forceUpdate parameter is used only when updating a list background directly because in that case
// the current list stays the same, but we want to show the new background right away.
if (list.id !== currentList.value.id || forceUpdate) {
if (list.id !== currentList.value?.id || forceUpdate) {
if (list.backgroundInformation) {
try {
const blurHash = await getBlobFromBlurHash(list.backgroundBlurHash)

View File

@ -9,7 +9,7 @@ import UserService from '@/services/user'
import {playPop} from '@/helpers/playPop'
import {getQuickAddMagicMode} from '@/helpers/quickAddMagicMode'
import {parseTaskText} from '@/modules/parseTaskText'
import {cleanupItemText, parseTaskText, PREFIXES} from '@/modules/parseTaskText'
import TaskAssigneeModel from '@/models/taskAssignee'
import LabelTaskModel from '@/models/labelTask'
@ -63,7 +63,7 @@ async function addLabelToTask(task: ITask, label: ILabel) {
return response
}
async function findAssignees(parsedTaskAssignees: string[]) {
async function findAssignees(parsedTaskAssignees: string[]): Promise<IUser[]> {
if (parsedTaskAssignees.length <= 0) {
return []
}
@ -376,7 +376,8 @@ export const useTaskStore = defineStore('task', () => {
Partial<ITask>,
) {
const cancel = setModuleLoading(setIsLoading)
const parsedTask = parseTaskText(title, getQuickAddMagicMode())
const quickAddMagicMode = getQuickAddMagicMode()
const parsedTask = parseTaskText(title, quickAddMagicMode)
const foundListId = await findListId({
list: parsedTask.list,
@ -390,11 +391,20 @@ export const useTaskStore = defineStore('task', () => {
const assignees = await findAssignees(parsedTask.assignees)
// Only clean up those assignees from the task title which actually exist
let cleanedTitle = parsedTask.text
if (assignees.length > 0) {
const assigneePrefix = PREFIXES[quickAddMagicMode]?.assignee
if (assigneePrefix) {
cleanedTitle = cleanupItemText(cleanedTitle, assignees.map(a => a.username), assigneePrefix)
}
}
// I don't know why, but it all goes up in flames when I just pass in the date normally.
const dueDate = parsedTask.date !== null ? new Date(parsedTask.date).toISOString() : null
const task = new TaskModel({
title: parsedTask.text,
title: cleanedTitle,
listId: foundListId,
dueDate,
priority: parsedTask.priority,