fix(project): correctly set last project when navigating from a saved filter (#1642)
This commit is contained in:
parent
a110d0f577
commit
215605db77
|
|
@ -14,7 +14,7 @@
|
|||
<BaseButton
|
||||
v-if="!isModal || isMobile"
|
||||
class="back-button mbs-2"
|
||||
@click="router.options.history.state?.back?.includes('/projects/') ? router.back() : router.push(projectRoute)"
|
||||
@click="lastProject ? router.back() : router.push(projectRoute)"
|
||||
>
|
||||
<Icon icon="arrow-left" />
|
||||
{{ $t('task.detail.back') }}
|
||||
|
|
@ -691,6 +691,24 @@ function saveTaskViaHotkey(event) {
|
|||
saveTask()
|
||||
}
|
||||
|
||||
const lastProject = computed(() => {
|
||||
const backRoute = router.options.history.state?.back
|
||||
if (!backRoute || typeof backRoute !== 'string') {
|
||||
return null
|
||||
}
|
||||
|
||||
const projectMatch = backRoute.match(/\/projects\/(-?\d+)/)
|
||||
if (!projectMatch || !projectMatch[1]) {
|
||||
return null
|
||||
}
|
||||
|
||||
const id = parseInt(projectMatch[1])
|
||||
|
||||
return projectStore.projects[id] ?? null
|
||||
})
|
||||
|
||||
const lastProjectOrTaskProject = computed(() => lastProject.value ?? project.value)
|
||||
|
||||
onMounted(() => {
|
||||
document.addEventListener('keydown', saveTaskViaHotkey)
|
||||
})
|
||||
|
|
@ -704,14 +722,14 @@ onBeforeRouteLeave(async () => {
|
|||
return
|
||||
}
|
||||
|
||||
if (!project.value) {
|
||||
if (!lastProjectOrTaskProject.value) {
|
||||
await new Promise<void>((resolve) => {
|
||||
const timeout = setTimeout(() => {
|
||||
stop()
|
||||
resolve()
|
||||
}, 5000) // 5 second timeout
|
||||
|
||||
const stop = watch(project, (p) => {
|
||||
const stop = watch(lastProjectOrTaskProject, (p) => {
|
||||
if (p) {
|
||||
clearTimeout(timeout)
|
||||
stop()
|
||||
|
|
@ -721,8 +739,8 @@ onBeforeRouteLeave(async () => {
|
|||
})
|
||||
}
|
||||
|
||||
if (project.value) {
|
||||
await baseStore.handleSetCurrentProjectIfNotSet(project.value)
|
||||
if (lastProjectOrTaskProject.value) {
|
||||
await baseStore.handleSetCurrentProjectIfNotSet(lastProjectOrTaskProject.value)
|
||||
}
|
||||
})
|
||||
|
||||
|
|
@ -788,8 +806,8 @@ watch(
|
|||
taskColor.value = task.value.hexColor
|
||||
setActiveFields()
|
||||
|
||||
if (project.value) {
|
||||
await baseStore.handleSetCurrentProjectIfNotSet(project.value)
|
||||
if (lastProject.value) {
|
||||
await baseStore.handleSetCurrentProjectIfNotSet(lastProject.value)
|
||||
}
|
||||
} catch (e) {
|
||||
if (e?.response?.status === 404) {
|
||||
|
|
|
|||
Loading…
Reference in New Issue