1
0

fix(views): move to new project view when moving tasks

This commit is contained in:
kolaente 2024-03-16 13:08:50 +01:00
parent 2dfb3a6379
commit bc34a33922
No known key found for this signature in database
GPG Key ID: F40E70337AB24C9B

View File

@ -1,12 +1,14 @@
import {computed, shallowRef, watchEffect, h, type VNode} from 'vue' import {computed, h, shallowRef, type VNode, watchEffect} from 'vue'
import {useRoute, useRouter} from 'vue-router' import {useRoute, useRouter} from 'vue-router'
import {useBaseStore} from '@/stores/base' import {useBaseStore} from '@/stores/base'
import {useProjectStore} from '@/stores/projects'
export function useRouteWithModal() { export function useRouteWithModal() {
const router = useRouter() const router = useRouter()
const route = useRoute() const route = useRoute()
const backdropView = computed(() => route.fullPath && window.history.state.backdropView) const backdropView = computed(() => route.fullPath && window.history.state.backdropView)
const baseStore = useBaseStore() const baseStore = useBaseStore()
const projectStore = useProjectStore()
const routeWithModal = computed(() => { const routeWithModal = computed(() => {
return backdropView.value return backdropView.value
@ -29,7 +31,7 @@ export function useRouteWithModal() {
if (routePropsOption === true) { if (routePropsOption === true) {
routeProps = route.params routeProps = route.params
} else { } else {
if(typeof routePropsOption === 'function') { if (typeof routePropsOption === 'function') {
routeProps = routePropsOption(route) routeProps = routePropsOption(route)
} else { } else {
routeProps = routePropsOption routeProps = routePropsOption
@ -60,12 +62,23 @@ export function useRouteWithModal() {
// If the current project was changed because the user moved the currently opened task while coming from kanban, // 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. // 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 // 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 routeMatch = new RegExp('\\/projects\\/\\d+\\/(\\d+)', 'g')
const kanbanRouter = {name: 'project.kanban', params: {projectId: baseStore.currentProject?.id}} const match = routeMatch.exec(historyState.value.back)
if (kanbanRouteMatch.test(historyState.value.back) if (match !== null && baseStore.currentProject) {
&& baseStore.currentProject let viewId: string | number = match[1]
&& historyState.value.back !== router.resolve(kanbanRouter).fullPath) {
router.push(kanbanRouter) if (!viewId) {
viewId = projectStore.projects[baseStore.currentProject?.id].views[0]?.id
}
const newRoute = {
name: 'project.view',
params: {
projectId: baseStore.currentProject?.id,
viewId,
},
}
router.push(newRoute)
return return
} }