fix(quick actions): always allow creating a new project or task, regardless of context

Resolves https://community.vikunja.io/t/ui-hotkeys-shortcuts/1096/29
This commit is contained in:
kolaente 2025-03-31 18:13:58 +02:00
parent d6bac2578b
commit 3e7c2966ab
No known key found for this signature in database
GPG Key ID: F40E70337AB24C9B
2 changed files with 11 additions and 12 deletions

View File

@ -318,12 +318,11 @@ const hintText = computed(() => {
})
const availableCmds = computed(() => {
const cmds = []
if (currentProject.value !== null) {
cmds.push(commands.value.newTask, commands.value.newProject)
}
cmds.push(commands.value.newTeam)
return cmds
return [
commands.value.newTask,
commands.value.newProject,
commands.value.newTeam,
]
})
const parsedQuery = computed(() => parseTaskText(query.value, authStore.settings.frontendSettings.quickAddMagicMode))
@ -509,7 +508,7 @@ async function doCmd() {
async function newTask() {
let projectId = authStore.settings.defaultProjectId
if (currentProject.value.id) {
if (currentProject.value?.id && currentProject.value.id > 0) {
projectId = currentProject.value.id
}
const task = await taskStore.createNewTask({
@ -521,11 +520,10 @@ async function newTask() {
}
async function newProject() {
if (currentProject.value === null) {
return
}
const parentProjectId = currentProject.value?.id ?? 0
await projectStore.createProject(new ProjectModel({
title: query.value,
parentProjectId: Math.max(parentProjectId, 0),
}))
success({message: t('project.create.createdSuccess')})
}

View File

@ -401,8 +401,9 @@ export const useTaskStore = defineStore('task', () => {
}
// 3. Otherwise use the id from the route parameter
if (typeof router.currentRoute.value.params.projectId !== 'undefined') {
foundProjectId = Number(router.currentRoute.value.params.projectId)
const projectIdFromRoute = Number(router.currentRoute.value.params.projectId)
if (typeof router.currentRoute.value.params.projectId !== 'undefined' && projectIdFromRoute > 0) {
foundProjectId = projectIdFromRoute
}
// 4. If none of the above worked, reject the promise with an error.