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
14 changed files with 24 additions and 28 deletions
Showing only changes of commit 78158bcba5 - Show all commits

View File

@ -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

View File

@ -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})

View File

@ -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

If projects are archived they won't show up here automatically?

If projects are archived they won't show up here automatically?

yes.

yes.

We didn't include archived namespaces if I understand the code correctly.

We didn't include archived namespaces if I understand the code correctly.

That's correct, so now we don't show archived projects.

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

Okay. I still don't understand where the archived filterting happens now (didn't check in detail) but if you are aware all good :)
})
// 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})`
}

View File

@ -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,
}

View File

@ -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' ? {

View File

@ -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)
}

View File

@ -36,9 +36,6 @@ export const useProjectStore = defineStore('project', () => {
.filter(p => !p.isArchived && p.isFavorite))
const hasProjects = computed(() => projects.value ? true : false)

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:

computed(() => Boolean(projectsArray.value.length))
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)) ```

Fixed.

Fixed.
const getProjectById = computed(() => {
return (id: IProject['id']) => typeof projects.value[id] !== 'undefined' ? projects.value[id] : null
})
const getChildProjects = computed(() => {

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

const myProject = computed(() => projects.value[myProjectId.value])
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]) ```

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.

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]
}
},

This changes project before calling update. was that intended? What happens if parentProject.value.id is undefined?

This changes project before calling update. was that intended? What happens if `parentProject.value.id` is undefined?

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},

View File

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

View File

@ -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 === '') {

View File

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

View File

@ -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(
() => {

View File

@ -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},

View File

@ -539,7 +539,7 @@ const visible = ref(false)
konrad marked this conversation as resolved Outdated

getProjectById returns undefined if there is no project with that id. So why not use that directly?

`getProjectById` returns `undefined` if there is no project with that id. So why not use that directly?

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,

View File

@ -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
},