feat: don't use child_projects property from api

This commit is contained in:
kolaente 2023-04-03 11:27:31 +02:00
parent 4ad9773022
commit ebd9c4702e
Signed by: konrad
GPG Key ID: F40E70337AB24C9B
1 changed files with 1 additions and 27 deletions

View File

@ -66,39 +66,13 @@ export const useProjectStore = defineStore('project', () => {
isLoading.value = newIsLoading
}
function setProject(project: IProject, updateChildren: boolean = true) {
function setProject(project: IProject) {
projects.value[project.id] = project
update(project)
if (baseStore.currentProject?.id === project.id) {
baseStore.setCurrentProject(project)
}
if (updateChildren) {
// When projects are loaded from the api, they will include child projects
// in the `childProjects` property. We flatten them out into the project store here.
project.childProjects?.forEach(p => setProject(new ProjectModel(p)))
delete project.childProjects
}
// if the project is a child project, we need to also set it in the parent
if (project.parentProjectId) {
const parent = projects.value[project.parentProjectId]
let foundProject = false
parent.childProjectIds = parent.childProjectIds?.forEach(p => {
if (p.id === project.id) {
foundProject = true
}
})
// If we hit this, the project now has a new parent project which it did not have before
if (!foundProject) {
if (!parent.childProjectIds) {
parent.childProjectIds = []
}
parent.childProjectIds.push(project.id)
}
setProject(parent, false)
}
}
function setProjects(newProjects: IProject[]) {