feat: remove props destructuring for ProjectView
This commit is contained in:
parent
8c9623dd0e
commit
553a97f03d
@ -11,10 +11,7 @@ import ProjectKanban from '@/components/project/views/ProjectKanban.vue'
|
|||||||
import {useAuthStore} from '@/stores/auth'
|
import {useAuthStore} from '@/stores/auth'
|
||||||
import {DEFAULT_PROJECT_VIEW_SETTINGS} from '@/modelTypes/IProjectView'
|
import {DEFAULT_PROJECT_VIEW_SETTINGS} from '@/modelTypes/IProjectView'
|
||||||
|
|
||||||
const {
|
const props = defineProps<{
|
||||||
projectId,
|
|
||||||
viewId,
|
|
||||||
} = defineProps<{
|
|
||||||
projectId: number,
|
projectId: number,
|
||||||
viewId: number,
|
viewId: number,
|
||||||
}>()
|
}>()
|
||||||
@ -23,32 +20,32 @@ const router = useRouter()
|
|||||||
const projectStore = useProjectStore()
|
const projectStore = useProjectStore()
|
||||||
const authStore = useAuthStore()
|
const authStore = useAuthStore()
|
||||||
|
|
||||||
const currentProject = computed(() => projectStore.projects[projectId])
|
const currentProject = computed(() => projectStore.projects[props.projectId])
|
||||||
|
|
||||||
const currentView = computed(() => {
|
const currentView = computed(() => {
|
||||||
return currentProject.value?.views.find(v => v.id === viewId)
|
return currentProject.value?.views.find(v => v.id === props.viewId)
|
||||||
})
|
})
|
||||||
|
|
||||||
function redirectToDefaultViewIfNecessary() {
|
function redirectToDefaultViewIfNecessary() {
|
||||||
if (viewId === 0 || !projectStore.projects[projectId]?.views.find(v => v.id === viewId)) {
|
if (props.viewId === 0 || !projectStore.projects[props.projectId]?.views.find(v => v.id === props.viewId)) {
|
||||||
// Ideally, we would do that in the router redirect, but the projects (and therefore, the views)
|
// Ideally, we would do that in the router redirect, but the projects (and therefore, the views)
|
||||||
// are not always loaded then.
|
// are not always loaded then.
|
||||||
|
|
||||||
let view
|
let view
|
||||||
if (authStore.settings.frontendSettings.defaultView !== DEFAULT_PROJECT_VIEW_SETTINGS.FIRST) {
|
if (authStore.settings.frontendSettings.defaultView !== DEFAULT_PROJECT_VIEW_SETTINGS.FIRST) {
|
||||||
view = projectStore.projects[projectId]?.views.find(v => v.viewKind === authStore.settings.frontendSettings.defaultView)
|
view = projectStore.projects[props.projectId]?.views.find(v => v.viewKind === authStore.settings.frontendSettings.defaultView)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Use the first view as fallback if the default view is not available
|
// Use the first view as fallback if the default view is not available
|
||||||
if (view === undefined && projectStore.projects[projectId]?.views?.length > 0) {
|
if (view === undefined && projectStore.projects[props.projectId]?.views?.length > 0) {
|
||||||
view = projectStore.projects[projectId]?.views[0]
|
view = projectStore.projects[props.projectId]?.views[0]
|
||||||
}
|
}
|
||||||
|
|
||||||
if (view) {
|
if (view) {
|
||||||
router.replace({
|
router.replace({
|
||||||
name: 'project.view',
|
name: 'project.view',
|
||||||
params: {
|
params: {
|
||||||
projectId,
|
projectId: props.projectId,
|
||||||
viewId: view.id,
|
viewId: view.id,
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
@ -57,20 +54,20 @@ function redirectToDefaultViewIfNecessary() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
watch(
|
watch(
|
||||||
() => viewId,
|
() => props.viewId,
|
||||||
redirectToDefaultViewIfNecessary,
|
redirectToDefaultViewIfNecessary,
|
||||||
{immediate: true},
|
{immediate: true},
|
||||||
)
|
)
|
||||||
|
|
||||||
watch(
|
watch(
|
||||||
() => projectStore.projects[projectId],
|
() => projectStore.projects[props.projectId],
|
||||||
redirectToDefaultViewIfNecessary,
|
redirectToDefaultViewIfNecessary,
|
||||||
)
|
)
|
||||||
|
|
||||||
// using a watcher instead of beforeEnter because beforeEnter is not called when only the viewId changes
|
// using a watcher instead of beforeEnter because beforeEnter is not called when only the viewId changes
|
||||||
watch(
|
watch(
|
||||||
() => [projectId, viewId],
|
() => [props.projectId, props.viewId],
|
||||||
() => saveProjectView(projectId, viewId),
|
() => saveProjectView(props.projectId, props.viewId),
|
||||||
{immediate: true},
|
{immediate: true},
|
||||||
)
|
)
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user