chore: move more logic to ProjectsNavigationItem.vue
This commit is contained in:
parent
65522a57f1
commit
b567146d69
@ -19,23 +19,10 @@
|
|||||||
}"
|
}"
|
||||||
>
|
>
|
||||||
<template #item="{element: project}">
|
<template #item="{element: project}">
|
||||||
<li
|
|
||||||
class="list-menu loader-container is-loading-small"
|
|
||||||
:class="{'is-loading': projectUpdating[project.id]}"
|
|
||||||
:data-project-id="project.id"
|
|
||||||
>
|
|
||||||
<ProjectsNavigationItem
|
<ProjectsNavigationItem
|
||||||
:project="project"
|
:project="project"
|
||||||
:can-collapse="childProjects[project.id]?.length > 0"
|
:is-loading="projectUpdating[project.id]"
|
||||||
:is-collapsed="collapsedProjects[project.id] || false"
|
|
||||||
@collapse="collapsedProjects[project.id] = !collapsedProjects[project.id]"
|
|
||||||
/>
|
/>
|
||||||
<ProjectsNavigation
|
|
||||||
v-if="!collapsedProjects[project.id]"
|
|
||||||
v-model="childProjects[project.id]"
|
|
||||||
:can-edit-order="true"
|
|
||||||
/>
|
|
||||||
</li>
|
|
||||||
</template>
|
</template>
|
||||||
</draggable>
|
</draggable>
|
||||||
</template>
|
</template>
|
||||||
@ -68,18 +55,11 @@ const projectStore = useProjectStore()
|
|||||||
|
|
||||||
// Vue draggable will modify the projects list as it changes their position which will not work on a prop.
|
// Vue draggable will modify the projects list as it changes their position which will not work on a prop.
|
||||||
// Hence, we'll clone the prop and work on the clone.
|
// Hence, we'll clone the prop and work on the clone.
|
||||||
const collapsedProjects = ref<{ [id: IProject['id']]: boolean }>({})
|
|
||||||
const availableProjects = ref<IProject[]>([])
|
const availableProjects = ref<IProject[]>([])
|
||||||
const childProjects = ref<{ [id: IProject['id']]: boolean }>({})
|
|
||||||
watch(
|
watch(
|
||||||
() => props.modelValue,
|
() => props.modelValue,
|
||||||
projects => {
|
projects => {
|
||||||
availableProjects.value = projects || []
|
availableProjects.value = projects || []
|
||||||
projects?.forEach(p => {
|
|
||||||
collapsedProjects.value[p.id] = false
|
|
||||||
childProjects.value[p.id] = projectStore.getChildProjects(p.id)
|
|
||||||
.sort((a, b) => a.position - b.position)
|
|
||||||
})
|
|
||||||
},
|
},
|
||||||
{immediate: true},
|
{immediate: true},
|
||||||
)
|
)
|
||||||
|
@ -1,11 +1,16 @@
|
|||||||
<template>
|
<template>
|
||||||
|
<li
|
||||||
|
class="list-menu loader-container is-loading-small"
|
||||||
|
:class="{'is-loading': isLoading}"
|
||||||
|
:data-project-id="project.id"
|
||||||
|
>
|
||||||
<section>
|
<section>
|
||||||
<BaseButton
|
<BaseButton
|
||||||
v-if="canCollapse"
|
v-if="childProjects?.length > 0"
|
||||||
@click="emit('collapse')"
|
@click="childProjectsOpen = !childProjectsOpen"
|
||||||
class="collapse-project-button"
|
class="collapse-project-button"
|
||||||
>
|
>
|
||||||
<icon icon="chevron-down" :class="{ 'project-is-collapsed': isCollapsed }"/>
|
<icon icon="chevron-down" :class="{ 'project-is-collapsed': !childProjectsOpen }"/>
|
||||||
</BaseButton>
|
</BaseButton>
|
||||||
<span class="collapse-project-button-placeholder" v-else></span>
|
<span class="collapse-project-button-placeholder" v-else></span>
|
||||||
<BaseButton
|
<BaseButton
|
||||||
@ -40,10 +45,16 @@
|
|||||||
</ProjectSettingsDropdown>
|
</ProjectSettingsDropdown>
|
||||||
<span class="list-setting-spacer" v-else></span>
|
<span class="list-setting-spacer" v-else></span>
|
||||||
</section>
|
</section>
|
||||||
|
<ProjectsNavigation
|
||||||
|
v-if="childProjectsOpen"
|
||||||
|
v-model="childProjects"
|
||||||
|
:can-edit-order="true"
|
||||||
|
/>
|
||||||
|
</li>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import {computed} from 'vue'
|
import {computed, watch, ref} from 'vue'
|
||||||
import {useProjectStore} from '@/stores/projects'
|
import {useProjectStore} from '@/stores/projects'
|
||||||
import {useBaseStore} from '@/stores/base'
|
import {useBaseStore} from '@/stores/base'
|
||||||
|
|
||||||
@ -53,18 +64,24 @@ import BaseButton from '@/components/base/BaseButton.vue'
|
|||||||
import ProjectSettingsDropdown from '@/components/project/project-settings-dropdown.vue'
|
import ProjectSettingsDropdown from '@/components/project/project-settings-dropdown.vue'
|
||||||
import {getProjectTitle} from '@/helpers/getProjectTitle'
|
import {getProjectTitle} from '@/helpers/getProjectTitle'
|
||||||
import ColorBubble from '@/components/misc/colorBubble.vue'
|
import ColorBubble from '@/components/misc/colorBubble.vue'
|
||||||
|
import ProjectsNavigation from '@/components/home/ProjectsNavigation.vue'
|
||||||
|
|
||||||
defineProps<{
|
const props = defineProps<{
|
||||||
project: IProject,
|
project: IProject,
|
||||||
isCollapsed: boolean,
|
isLoading?: boolean,
|
||||||
canCollapse: boolean,
|
|
||||||
}>()
|
}>()
|
||||||
|
|
||||||
const emit = defineEmits(['collapse'])
|
|
||||||
|
|
||||||
const projectStore = useProjectStore()
|
const projectStore = useProjectStore()
|
||||||
const baseStore = useBaseStore()
|
const baseStore = useBaseStore()
|
||||||
const currentProject = computed(() => baseStore.currentProject)
|
const currentProject = computed(() => baseStore.currentProject)
|
||||||
|
|
||||||
|
const childProjectsOpen = ref(true)
|
||||||
|
|
||||||
|
const childProjects = computed(() => {
|
||||||
|
return projectStore.getChildProjects(props.project.id)
|
||||||
|
.sort((a, b) => a.position - b.position)
|
||||||
|
})
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<style lang="scss" scoped>
|
<style lang="scss" scoped>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user