fix: remove getProjectById and replace all usages of it

This commit is contained in:
kolaente 2023-04-12 11:13:55 +02:00
parent 9402344b7e
commit 78158bcba5
Signed by: konrad
GPG Key ID: F40E70337AB24C9B
14 changed files with 24 additions and 28 deletions

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))
})
// 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)
const getProjectById = computed(() => {
return (id: IProject['id']) => typeof projects.value[id] !== 'undefined' ? projects.value[id] : null
})
const getChildProjects = computed(() => {
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]
}
},
{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)
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
},