From 8902c15f7e9590da075e860f3d35939169ee246a Mon Sep 17 00:00:00 2001 From: kolaente Date: Mon, 10 Jul 2023 18:10:14 +0200 Subject: [PATCH] fix: correctly resolve kanban board in the background when moving a task Resolves F-951 --- src/composables/useRouteWithModal.ts | 18 ++++++++++++++++-- src/views/project/ProjectKanban.vue | 26 ++++++++++---------------- 2 files changed, 26 insertions(+), 18 deletions(-) diff --git a/src/composables/useRouteWithModal.ts b/src/composables/useRouteWithModal.ts index d4e17c5c7..a384e0a8e 100644 --- a/src/composables/useRouteWithModal.ts +++ b/src/composables/useRouteWithModal.ts @@ -1,10 +1,12 @@ -import { computed, shallowRef, watchEffect, h, type VNode } from 'vue' -import { useRoute, useRouter } from 'vue-router' +import {computed, shallowRef, watchEffect, h, type VNode} from 'vue' +import {useRoute, useRouter} from 'vue-router' +import {useBaseStore} from '@/stores/base' export function useRouteWithModal() { const router = useRouter() const route = useRoute() const backdropView = computed(() => route.fullPath && window.history.state.backdropView) + const baseStore = useBaseStore() const routeWithModal = computed(() => { return backdropView.value @@ -44,6 +46,18 @@ export function useRouteWithModal() { function closeModal() { const historyState = computed(() => route.fullPath && window.history.state) + // If the current project was changed because the user moved the currently opened task while coming from kanban, + // we need to reflect that change in the route when they close the task modal. + // The last route is only available as resolved string, therefore we need to use a regex for matching here + const kanbanRouteMatch = new RegExp('\\/projects\\/\\d+\\/kanban', 'g') + const kanbanRouter = {name: 'project.kanban', params: {projectId: baseStore.currentProject?.id}} + if (kanbanRouteMatch.test(historyState.value.back) + && baseStore.currentProject + && historyState.value.back !== router.resolve(kanbanRouter).fullPath) { + router.push(kanbanRouter) + return + } + if (historyState.value) { router.back() } else { diff --git a/src/views/project/ProjectKanban.vue b/src/views/project/ProjectKanban.vue index 5551f795d..2adf969a5 100644 --- a/src/views/project/ProjectKanban.vue +++ b/src/views/project/ProjectKanban.vue @@ -1,7 +1,7 @@