feature/projects-all-the-way-down #3323

Merged
konrad merged 123 commits from feature/projects-all-the-way-down into main 2023-05-30 10:09:40 +00:00
Showing only changes of commit ebd9c4702e - Show all commits

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) {

See comment about having the data as sub projects from earlier.

See comment about having the data as sub projects from earlier.
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)
}
}

The three lines above should be called via a deep watcher on the current project. Not as a side effect.

The three lines above should be called via a deep watcher on the current project. Not as a side effect.

You mean setting the current project in the base store?

You mean setting the current project in the base store?

I mean:

  1. remove this sideeffect of the setProject function:
if (baseStore.currentProject?.id === project.id) {
	baseStore.setCurrentProject(project)
}
  1. Instead add a watcher on the project that has the id of the current project.
watchEffect(() => baseStore.setCurrentProject(projects.value[baseStore.currentProject.id])
)

It might be even better to make the currentProject a computed based on the store instead and only setting it via id (unsure here how to handle projects that are not saved yet)

I mean: 1) remove this sideeffect of the `setProject` function: ``` if (baseStore.currentProject?.id === project.id) { baseStore.setCurrentProject(project) } ``` 2) Instead add a watcher on the project that has the id of the current project. ```ts watchEffect(() => baseStore.setCurrentProject(projects.value[baseStore.currentProject.id]) ) ``` It might be even better to make the currentProject a computed based on the store instead and only setting it via id (unsure here how to handle projects that are not saved yet)

I've now changed it to use a watcher.

It might be even better to make the currentProject a computed based on the store instead and only setting it via id (unsure here how to handle projects that are not saved yet)

That sounds like a good idea, but let's push that to another PR.

I've now changed it to use a watcher. > It might be even better to make the currentProject a computed based on the store instead and only setting it via id (unsure here how to handle projects that are not saved yet) That sounds like a good idea, but let's push that to another PR.

I've now changed it to use a watcher.

It might be even better to make the currentProject a computed based on the store instead and only setting it via id (unsure here how to handle projects that are not saved yet)

That sounds like a good idea, but let's push that to another PR.

I've now changed it to use a watcher. > It might be even better to make the currentProject a computed based on the store instead and only setting it via id (unsure here how to handle projects that are not saved yet) That sounds like a good idea, but let's push that to another PR.

If I set an id for parentID in the passed project: will this update the parents childProjects?

If I set an id for `parentID` in the passed project: will this update the parents childProjects?

It did not. While checking this, I discovered how we're not using child ids anywhere any more (including in the api) so I've removed all traces of them.

It did not. While checking this, I discovered how we're not using child ids anywhere any more (including in the api) so I've removed all traces of them.
function setProjects(newProjects: IProject[]) {