feature/projects-all-the-way-down #3323
|
@ -80,7 +80,7 @@ async function saveProjectPosition(e: SortableEvent) {
|
|||
const newIndex = e.newIndex === projectsActive.length ? e.newIndex - 1 : e.newIndex
|
||||
|
||||
const projectId = parseInt(e.item.dataset.projectId)
|
||||
const project = projectStore.getProjectById(projectId)
|
||||
const project = projectStore.projects[projectId]
|
||||
|
||||
const parentProjectId = e.to.parentNode.dataset.projectId ? parseInt(e.to.parentNode.dataset.projectId) : 0
|
||||
const projectBefore = projectsActive[newIndex - 1] ?? null
|
||||
|
|
|
@ -130,8 +130,8 @@ watch(
|
|||
|
||||
// Set the current project to the one we're about to load so that the title is already shown at the top
|
||||
loadedProjectId.value = 0
|
||||
const projectFromStore = projectStore.getProjectById(projectData.id)
|
||||
if (projectFromStore !== null) {
|
||||
const projectFromStore = projectStore.projects[projectData.id]
|
||||
if (projectFromStore) {
|
||||
baseStore.setBackground(null)
|
||||
baseStore.setBlurHash(null)
|
||||
baseStore.handleSetCurrentProject({project: projectFromStore})
|
||||
|
|
|
@ -145,12 +145,12 @@ const foundProjects = computed(() => {
|
|||
const history = getHistory()
|
||||
const allProjects = [
|
||||
...new Set([
|
||||
...history.map((l) => projectStore.getProjectById(l.id)),
|
||||
...history.map((l) => projectStore.projects[l.id]),
|
||||
...projectStore.searchProject(project),
|
||||
]),
|
||||
]
|
||||
|
||||
return allProjects.filter((l) => typeof l !== 'undefined' && l !== null)
|
||||
return allProjects.filter(l => Boolean(l))
|
||||
dpschen marked this conversation as resolved
Outdated
|
||||
})
|
||||
|
||||
// FIXME: use fuzzysearch
|
||||
|
@ -369,7 +369,7 @@ function searchTasks() {
|
|||
const r = await taskService.getAll({}, params) as DoAction<ITask>[]
|
||||
foundTasks.value = r.map((t) => {
|
||||
t.type = ACTION_TYPE.TASK
|
||||
const project = projectStore.getProjectById(t.projectId)
|
||||
const project = projectStore.projects[t.projectId]
|
||||
if (project !== null) {
|
||||
t.title = `${t.title} (${project.title})`
|
||||
}
|
||||
|
|
|
@ -222,12 +222,12 @@ async function findTasks(newQuery: string) {
|
|||
function mapRelatedTasks(tasks: ITask[]) {
|
||||
return tasks.map(task => {
|
||||
// by doing this here once we can save a lot of duplicate calls in the template
|
||||
const project = projectStore.getProjectById(task.ProjectId)
|
||||
const project = projectStore.projects[task.ProjectId]
|
||||
|
||||
return {
|
||||
...task,
|
||||
differentProject:
|
||||
(project !== null &&
|
||||
(project &&
|
||||
task.projectId !== props.projectId &&
|
||||
project?.title) || null,
|
||||
}
|
||||
|
|
|
@ -14,12 +14,12 @@
|
|||
|
||||
<router-link
|
||||
:to="taskDetailRoute"
|
||||
:class="{ 'done': task.done, 'show-project': showProject && project !== null}"
|
||||
:class="{ 'done': task.done, 'show-project': showProject && project}"
|
||||
class="tasktext"
|
||||
>
|
||||
<span>
|
||||
<router-link
|
||||
v-if="showProject && project !== null"
|
||||
v-if="showProject && typeof project !== 'undefined'"
|
||||
:to="{ name: 'project.list', params: { projectId: task.projectId } }"
|
||||
class="task-project"
|
||||
:class="{'mr-2': task.hexColor !== ''}"
|
||||
|
@ -104,7 +104,7 @@
|
|||
</progress>
|
||||
|
||||
<router-link
|
||||
v-if="!showProject && currentProject.id !== task.projectId && project !== null"
|
||||
v-if="!showProject && currentProject.id !== task.projectId && project"
|
||||
:to="{ name: 'project.list', params: { projectId: task.projectId } }"
|
||||
class="task-project"
|
||||
v-tooltip="$t('task.detail.belongsToProject', {project: project.title})"
|
||||
|
@ -209,8 +209,8 @@ const baseStore = useBaseStore()
|
|||
const projectStore = useProjectStore()
|
||||
const taskStore = useTaskStore()
|
||||
|
||||
const project = computed(() => projectStore.getProjectById(task.value.projectId))
|
||||
const projectColor = computed(() => project.value !== null ? project.value.hexColor : '')
|
||||
const project = computed(() => projectStore.projects[task.value.projectId])
|
||||
const projectColor = computed(() => project.value ? project.value?.hexColor : '')
|
||||
|
||||
const currentProject = computed(() => {
|
||||
return typeof baseStore.currentProject === 'undefined' ? {
|
||||
|
|
|
@ -360,7 +360,7 @@ const router = createRouter({
|
|||
saveProjectView(to.params.projectId, to.name)
|
||||
// Properly set the page title when a task popup is closed
|
||||
const projectStore = useProjectStore()
|
||||
const projectFromStore = projectStore.getProjectById(Number(to.params.projectId))
|
||||
const projectFromStore = projectStore.projects[Number(to.params.projectId)]
|
||||
if(projectFromStore) {
|
||||
setTitle(projectFromStore.title)
|
||||
}
|
||||
|
|
|
@ -36,9 +36,6 @@ export const useProjectStore = defineStore('project', () => {
|
|||
.filter(p => !p.isArchived && p.isFavorite))
|
||||
const hasProjects = computed(() => projects.value ? true : false)
|
||||
dpschen
commented
Since Afaik there is no way around something like:
Since `projects` is of type object (defined by its type) this shouldn't work because `!!{} === true`.
Even if it would be undefined or null sometimes this should use `Boolean(projects.value)` for clarity instead.
Afaik there is no way around something like:
```ts
computed(() => Boolean(projectsArray.value.length))
```
konrad
commented
Fixed. Fixed.
|
||||
|
||||
const getProjectById = computed(() => {
|
||||
return (id: IProject['id']) => typeof projects.value[id] !== 'undefined' ? projects.value[id] : null
|
||||
})
|
||||
const getChildProjects = computed(() => {
|
||||
dpschen
commented
This computed seems really unnecessary. Reason: We can achieve the same (and faster) by using:
This computed seems really unnecessary. Reason: We can achieve the same (and faster) by using: `projects.value[id]`. Since `projects` is exported we should replace uses of this computed. We might need to create new simple computeds where used. Depending on usecase something like
```ts
const myProject = computed(() => projects.value[myProjectId.value])
```
konrad
commented
We've actually been using computed for most uses of the store computed anyway. I've changed it to use the We've actually been using computed for most uses of the store computed anyway. I've changed it to use the `projects` property of the store directly.
|
||||
return (id: IProject['id']) => projectsArray.value.filter(p => p.parentProjectId === id) || []
|
||||
})
|
||||
|
@ -190,7 +187,6 @@ export const useProjectStore = defineStore('project', () => {
|
|||
favoriteProjects: readonly(favoriteProjects),
|
||||
hasProjects: readonly(hasProjects),
|
||||
|
||||
getProjectById,
|
||||
getChildProjects,
|
||||
findProjectByExactname,
|
||||
searchProject,
|
||||
|
@ -229,7 +225,7 @@ export function useProject(projectId: MaybeRef<IProject['id']>) {
|
|||
() => project.parentProjectId,
|
||||
projectId => {
|
||||
if (project.parentProjectId) {
|
||||
parentProject.value = projectStore.getProjectById(project.parentProjectId)
|
||||
parentProject.value = projectStore.projects[project.parentProjectId]
|
||||
}
|
||||
},
|
||||
dpschen
commented
This changes project before calling update. was that intended? What happens if This changes project before calling update. was that intended? What happens if `parentProject.value.id` is undefined?
konrad
commented
It was not intended. I've changed it now so that it checks it before and provides a proper fallback. It was not intended. I've changed it now so that it checks it before and provides a proper fallback.
|
||||
{immediate: true},
|
||||
|
|
|
@ -74,8 +74,8 @@ const projectHistory = computed(() => {
|
|||
}
|
||||
|
||||
return getHistory()
|
||||
.map(l => projectStore.getProjectById(l.id))
|
||||
.filter((l): l is IProject => l !== null)
|
||||
.map(l => projectStore.projects[l.id])
|
||||
.filter(l => Boolean(l))
|
||||
})
|
||||
|
||||
const migratorsEnabled = computed(() => configStore.availableMigrators?.length > 0)
|
||||
|
|
|
@ -29,7 +29,7 @@ const props = defineProps({
|
|||
})
|
||||
|
||||
const projectStore = useProjectStore()
|
||||
const project = computed(() => projectStore.getProjectById(props.projectId))
|
||||
const project = computed(() => projectStore.projects[props.projectId])
|
||||
const htmlDescription = computed(() => {
|
||||
const description = project.value?.description || ''
|
||||
if (description === '') {
|
||||
|
|
|
@ -31,7 +31,7 @@ const projectStore = useProjectStore()
|
|||
const router = useRouter()
|
||||
const route = useRoute()
|
||||
|
||||
const project = computed(() => projectStore.getProjectById(route.params.projectId))
|
||||
const project = computed(() => projectStore.projects[route.params.projectId])
|
||||
useTitle(() => t('project.archive.title', {project: project.value.title}))
|
||||
|
||||
async function archiveProject() {
|
||||
|
|
|
@ -43,7 +43,7 @@ const router = useRouter()
|
|||
|
||||
const totalTasks = ref<number | null>(null)
|
||||
|
||||
const project = computed(() => projectStore.getProjectById(route.params.projectId))
|
||||
const project = computed(() => projectStore.projects[route.params.projectId])
|
||||
|
||||
watchEffect(
|
||||
() => {
|
||||
|
|
|
@ -39,9 +39,9 @@ const parentProject = ref<IProject | null>(null)
|
|||
watch(
|
||||
() => route.params.projectId,
|
||||
projectId => {
|
||||
const project = projectStore.getProjectById(route.params.projectId)
|
||||
const project = projectStore.projects[route.params.projectId]
|
||||
if (project.parentProjectId) {
|
||||
parentProject.value = projectStore.getProjectById(project.parentProjectId)
|
||||
parentProject.value = projectStore.projects[project.parentProjectId]
|
||||
}
|
||||
},
|
||||
{immediate: true},
|
||||
|
|
|
@ -539,7 +539,7 @@ const visible = ref(false)
|
|||
|
||||
konrad marked this conversation as resolved
Outdated
dpschen
commented
`getProjectById` returns `undefined` if there is no project with that id. So why not use that directly?
konrad
commented
Done Done
|
||||
const taskId = toRef(props, 'taskId')
|
||||
|
||||
const project = computed(() => task.projectId ? projectStore.getProjectById(task.projectId) : null)
|
||||
const project = computed(() => task.projectId ? projectStore.projects[task.projectId] : null)
|
||||
watchEffect(() => {
|
||||
baseStore.handleSetCurrentProject({
|
||||
project: project.value,
|
||||
|
|
|
@ -245,7 +245,7 @@ watch(
|
|||
|
||||
const projectStore = useProjectStore()
|
||||
const defaultProject = computed({
|
||||
get: () => projectStore.getProjectById(settings.value.defaultProjectId) || undefined,
|
||||
get: () => projectStore.projects[settings.value.defaultProjectId],
|
||||
set(l) {
|
||||
settings.value.defaultProjectId = l ? l.id : DEFAULT_PROJECT_ID
|
||||
},
|
||||
|
|
If projects are archived they won't show up here automatically?
yes.
We didn't include archived namespaces if I understand the code correctly.
That's correct, so now we don't show archived projects.
Okay. I still don't understand where the archived filterting happens now (didn't check in detail) but if you are aware all good :)