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
2 changed files with 18 additions and 19 deletions
Showing only changes of commit ba452ab883 - Show all commits

View File

@ -211,22 +211,8 @@ export function useProject(projectId: MaybeRef<IProject['id']>) {
const projectStore = useProjectStore()
const parentProject = ref<IProject | null>(null)
watch(
() => project.parentProjectId,
projectId => {
if (project.parentProjectId) {
parentProject.value = projectStore.projects[project.parentProjectId]
}
},
{immediate: true},
)
async function save() {
const updatedProject = await projectStore.updateProject({
...project,
parentProjectId: parentProject.value.id ?? project.parentProjectId,
})
const updatedProject = await projectStore.updateProject(project)
Object.assign(project, updatedProject)
success({message: t('project.edit.success')})
}

If the parent should be editable the parent should use useProject itself. I our target here is to make the parentProjectId updateable: why do we need to export an extra object, since the parentProjectId is already part of the project? If not: could we use a computed getter / setter here instead?

If the parent should be editable the parent should use `useProject` itself. I our target here is to make the parentProjectId updateable: why do we need to export an extra object, since the parentProjectId is already part of the project? If not: could we use a computed getter / setter here instead?

I've moved it out of the composable. It's only used in one place anyway...

I've moved it out of the composable. It's only used in one place anyway...
@ -234,7 +220,6 @@ export function useProject(projectId: MaybeRef<IProject['id']>) {
return {
isLoading: readonly(isLoading),
project,
parentProject,
save,
}
}

View File

@ -72,11 +72,11 @@
</template>
<script lang="ts">
export default { name: 'project-setting-edit' }
export default {name: 'project-setting-edit'}
</script>
<script setup lang="ts">
import {type PropType} from 'vue'
import {watch, ref, type PropType} from 'vue'
import {useRouter} from 'vue-router'
import {useI18n} from 'vue-i18n'
@ -88,6 +88,7 @@ import ProjectSearch from '@/components/tasks/partials/projectSearch.vue'
import type {IProject} from '@/modelTypes/IProject'
import {useBaseStore} from '@/stores/base'
import {useProjectStore} from '@/stores/projects'
import {useProject} from '@/stores/projects'
import {useTitle} from '@/composables/useTitle'
@ -100,14 +101,27 @@ const props = defineProps({
})
const router = useRouter()
const projectStore = useProjectStore()
const {t} = useI18n({useScope: 'global'})
konrad marked this conversation as resolved Outdated

Use computed getter / setter to set parentProjectId of project instead.

Use computed getter / setter to set parentProjectId of project instead.

I've changed this since moving the parent project logic out of the composable.

I've changed this since moving the parent project logic out of the composable.
const {project, parentProject, save: saveProject, isLoading} = useProject(props.projectId)
const {project, save: saveProject, isLoading} = useProject(props.projectId)
const parentProject = ref<IProject | null>(null)
watch(
() => project.parentProjectId,
projectId => {
if (project.parentProjectId) {
parentProject.value = projectStore.projects[project.parentProjectId]
}
},
{immediate: true},
)
useTitle(() => project?.title ? t('project.edit.title', {project: project.title}) : '')
async function save() {
project.parentProjectId = parentProject.value.id ?? project.parentProjectId
await saveProject()
await useBaseStore().handleSetCurrentProject({project})
router.back()