Skip to content

TaskView is a self-hosted project and task management platform focused on clarity, ownership, and control. TaskView is built for teams that want a transparent, self-hosted alternative to SaaS task managers.

2.3 KB
Raw Blame
<template>
  <div class="flex flex-col gap-2">
    <ProjectsList
      :projects="activeProjects"
      @save="handleSave"
      @delete="handleDelete"
      @archive="handleArchive"
      @add="handleAdd"
    />
    <ArchiveList
      :projects="archivedProjects"
      @save="handleSave"
      @delete="handleDelete"
      @restore="handleRestore"
    />
  </div>
</template>

<script setup lang="ts">
import { computed, watch } from 'vue'
import { storeToRefs } from 'pinia'
import { useRouter } from 'vue-router'
import { useGoalsStore } from '@/stores/goals.store'
import { useOrganizationStore } from '@/stores/organization.store'
import ProjectsList from '@/components/features/projects/ProjectsList.vue'
import ArchiveList from '@/components/features/projects/ArchiveList.vue'
import type { Project, ProjectSaveData } from '@/components/features/projects/types'
import { useProjectRoute } from '@/composables/useProjectRoute'
import { useInbox } from '@/composables/useInbox'

const router = useRouter()
const { projectRoute } = useProjectRoute()
const { isOwnInbox } = useInbox()

const goalsStore = useGoalsStore()
const orgStore = useOrganizationStore()
const { goals } = storeToRefs(goalsStore)

const activeProjects = computed(() => goals.value.filter(p => p.archive === 0 && !isOwnInbox(p)))
const archivedProjects = computed(() => goals.value.filter(p => p.archive === 1 && !isOwnInbox(p)))


watch(() => orgStore.currentOrg, async () => {
  goalsStore.initialized = false
  await goalsStore.fetchGoals()
})

async function handleSave(project: Project, data: ProjectSaveData) {
  await goalsStore.updateGoal({
    id: project.id,
    name: data.name,
    description: data.description,
    estimateUnit: data.estimateUnit,
  })
}

async function handleDelete(project: Project) {
  await goalsStore.deleteGoal(project.id)
}

async function handleArchive(project: Project) {
  await goalsStore.updateGoal({
    id: project.id,
    archive: 1,
  })
}

async function handleRestore(project: Project) {
  await goalsStore.updateGoal({
    id: project.id,
    archive: 0,
  })
}

async function handleAdd(name: string) {
  const newProject = await goalsStore.addGoal({
    name,
    ...(orgStore.currentOrg && { organizationId: orgStore.currentOrg.id }),
  })
  if (newProject) {
    router.push(projectRoute(newProject))
  }
}
</script>