From d4faa0607431b7c50ab808017af470a88e4b7540 Mon Sep 17 00:00:00 2001 From: kolaente Date: Wed, 12 Apr 2023 10:45:56 +0200 Subject: [PATCH] fix: move parent project child id mutation to store --- src/components/home/ProjectsNavigation.vue | 6 ------ src/stores/projects.ts | 9 +++++++++ 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/src/components/home/ProjectsNavigation.vue b/src/components/home/ProjectsNavigation.vue index 889e327d0..69ea625f6 100644 --- a/src/components/home/ProjectsNavigation.vue +++ b/src/components/home/ProjectsNavigation.vue @@ -92,12 +92,6 @@ async function saveProjectPosition(e: SortableEvent) { projectAfter !== null ? projectAfter.position : null, ) - if (project.parentProjectId !== parentProjectId && project.parentProjectId > 0) { - const parentProject = projectStore.getProjectById(project.parentProjectId) - const childProjectIndex = parentProject.childProjectIds.findIndex(pId => pId === project.id) - parentProject.childProjectIds.splice(childProjectIndex, 1) - } - try { // create a copy of the project in order to not violate pinia manipulation await projectStore.updateProject({ diff --git a/src/stores/projects.ts b/src/stores/projects.ts index 414532e59..26ee18ad2 100644 --- a/src/stores/projects.ts +++ b/src/stores/projects.ts @@ -112,6 +112,15 @@ export const useProjectStore = defineStore('project', () => { async function updateProject(project: IProject) { const cancel = setModuleLoading(setIsLoading) const projectService = new ProjectService() + + const oldProject = projects.value[project.id] + if (oldProject && oldProject.parentProjectId !== project.parentProjectId && oldProject.parentProjectId > 0) { + const parentProject = projects.value[oldProject.parentProjectId] + if (parentProject) { + const childProjectIndex = parentProject.childProjectIds.findIndex(pId => pId === project.id) + parentProject.childProjectIds.splice(childProjectIndex, 1) + } + } try { await projectService.update(project)