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 newIndex = e.newIndex === projectsActive.length ? e.newIndex - 1 : e.newIndex
const projectId = parseInt(e.item.dataset.projectId) 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 parentProjectId = e.to.parentNode.dataset.projectId ? parseInt(e.to.parentNode.dataset.projectId) : 0
const projectBefore = projectsActive[newIndex - 1] ?? null 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 // 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 loadedProjectId.value = 0
const projectFromStore = projectStore.getProjectById(projectData.id) const projectFromStore = projectStore.projects[projectData.id]
if (projectFromStore !== null) { if (projectFromStore) {
baseStore.setBackground(null) baseStore.setBackground(null)
baseStore.setBlurHash(null) baseStore.setBlurHash(null)
baseStore.handleSetCurrentProject({project: projectFromStore}) baseStore.handleSetCurrentProject({project: projectFromStore})

View File

@ -145,12 +145,12 @@ const foundProjects = computed(() => {
const history = getHistory() const history = getHistory()
const allProjects = [ const allProjects = [
...new Set([ ...new Set([
...history.map((l) => projectStore.getProjectById(l.id)), ...history.map((l) => projectStore.projects[l.id]),
...projectStore.searchProject(project), ...projectStore.searchProject(project),
]), ]),
] ]
return allProjects.filter((l) => typeof l !== 'undefined' && l !== null) return allProjects.filter(l => Boolean(l))
}) })
// FIXME: use fuzzysearch // FIXME: use fuzzysearch
@ -369,7 +369,7 @@ function searchTasks() {
const r = await taskService.getAll({}, params) as DoAction<ITask>[] const r = await taskService.getAll({}, params) as DoAction<ITask>[]
foundTasks.value = r.map((t) => { foundTasks.value = r.map((t) => {
t.type = ACTION_TYPE.TASK t.type = ACTION_TYPE.TASK
const project = projectStore.getProjectById(t.projectId) const project = projectStore.projects[t.projectId]
if (project !== null) { if (project !== null) {
t.title = `${t.title} (${project.title})` t.title = `${t.title} (${project.title})`
} }

View File

@ -222,12 +222,12 @@ async function findTasks(newQuery: string) {
function mapRelatedTasks(tasks: ITask[]) { function mapRelatedTasks(tasks: ITask[]) {
return tasks.map(task => { return tasks.map(task => {
// by doing this here once we can save a lot of duplicate calls in the template // 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 { return {
...task, ...task,
differentProject: differentProject:
(project !== null && (project &&
task.projectId !== props.projectId && task.projectId !== props.projectId &&
project?.title) || null, project?.title) || null,
} }

View File

@ -14,12 +14,12 @@
<router-link <router-link
:to="taskDetailRoute" :to="taskDetailRoute"
:class="{ 'done': task.done, 'show-project': showProject && project !== null}" :class="{ 'done': task.done, 'show-project': showProject && project}"
class="tasktext" class="tasktext"
> >
<span> <span>
<router-link <router-link
v-if="showProject && project !== null" v-if="showProject && typeof project !== 'undefined'"
:to="{ name: 'project.list', params: { projectId: task.projectId } }" :to="{ name: 'project.list', params: { projectId: task.projectId } }"
class="task-project" class="task-project"
:class="{'mr-2': task.hexColor !== ''}" :class="{'mr-2': task.hexColor !== ''}"
@ -104,7 +104,7 @@
</progress> </progress>
<router-link <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 } }" :to="{ name: 'project.list', params: { projectId: task.projectId } }"
class="task-project" class="task-project"
v-tooltip="$t('task.detail.belongsToProject', {project: project.title})" v-tooltip="$t('task.detail.belongsToProject', {project: project.title})"
@ -209,8 +209,8 @@ const baseStore = useBaseStore()
const projectStore = useProjectStore() const projectStore = useProjectStore()
const taskStore = useTaskStore() const taskStore = useTaskStore()
const project = computed(() => projectStore.getProjectById(task.value.projectId)) const project = computed(() => projectStore.projects[task.value.projectId])
const projectColor = computed(() => project.value !== null ? project.value.hexColor : '') const projectColor = computed(() => project.value ? project.value?.hexColor : '')
const currentProject = computed(() => { const currentProject = computed(() => {
return typeof baseStore.currentProject === 'undefined' ? { return typeof baseStore.currentProject === 'undefined' ? {

View File

@ -360,7 +360,7 @@ const router = createRouter({
saveProjectView(to.params.projectId, to.name) saveProjectView(to.params.projectId, to.name)
// Properly set the page title when a task popup is closed // Properly set the page title when a task popup is closed
const projectStore = useProjectStore() const projectStore = useProjectStore()
const projectFromStore = projectStore.getProjectById(Number(to.params.projectId)) const projectFromStore = projectStore.projects[Number(to.params.projectId)]
if(projectFromStore) { if(projectFromStore) {
setTitle(projectFromStore.title) setTitle(projectFromStore.title)
} }

View File

@ -36,9 +36,6 @@ export const useProjectStore = defineStore('project', () => {
.filter(p => !p.isArchived && p.isFavorite)) .filter(p => !p.isArchived && p.isFavorite))
const hasProjects = computed(() => projects.value ? true : false) 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(() => { const getChildProjects = computed(() => {
return (id: IProject['id']) => projectsArray.value.filter(p => p.parentProjectId === id) || [] return (id: IProject['id']) => projectsArray.value.filter(p => p.parentProjectId === id) || []
}) })
@ -190,7 +187,6 @@ export const useProjectStore = defineStore('project', () => {
favoriteProjects: readonly(favoriteProjects), favoriteProjects: readonly(favoriteProjects),
hasProjects: readonly(hasProjects), hasProjects: readonly(hasProjects),
getProjectById,
getChildProjects, getChildProjects,
findProjectByExactname, findProjectByExactname,
searchProject, searchProject,
@ -229,7 +225,7 @@ export function useProject(projectId: MaybeRef<IProject['id']>) {
() => project.parentProjectId, () => project.parentProjectId,
projectId => { projectId => {
if (project.parentProjectId) { if (project.parentProjectId) {
parentProject.value = projectStore.getProjectById(project.parentProjectId) parentProject.value = projectStore.projects[project.parentProjectId]
} }
}, },
{immediate: true}, {immediate: true},

View File

@ -74,8 +74,8 @@ const projectHistory = computed(() => {
} }
return getHistory() return getHistory()
.map(l => projectStore.getProjectById(l.id)) .map(l => projectStore.projects[l.id])
.filter((l): l is IProject => l !== null) .filter(l => Boolean(l))
}) })
const migratorsEnabled = computed(() => configStore.availableMigrators?.length > 0) const migratorsEnabled = computed(() => configStore.availableMigrators?.length > 0)

View File

@ -29,7 +29,7 @@ const props = defineProps({
}) })
const projectStore = useProjectStore() const projectStore = useProjectStore()
const project = computed(() => projectStore.getProjectById(props.projectId)) const project = computed(() => projectStore.projects[props.projectId])
const htmlDescription = computed(() => { const htmlDescription = computed(() => {
const description = project.value?.description || '' const description = project.value?.description || ''
if (description === '') { if (description === '') {

View File

@ -31,7 +31,7 @@ const projectStore = useProjectStore()
const router = useRouter() const router = useRouter()
const route = useRoute() 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})) useTitle(() => t('project.archive.title', {project: project.value.title}))
async function archiveProject() { async function archiveProject() {

View File

@ -43,7 +43,7 @@ const router = useRouter()
const totalTasks = ref<number | null>(null) const totalTasks = ref<number | null>(null)
const project = computed(() => projectStore.getProjectById(route.params.projectId)) const project = computed(() => projectStore.projects[route.params.projectId])
watchEffect( watchEffect(
() => { () => {

View File

@ -39,9 +39,9 @@ const parentProject = ref<IProject | null>(null)
watch( watch(
() => route.params.projectId, () => route.params.projectId,
projectId => { projectId => {
const project = projectStore.getProjectById(route.params.projectId) const project = projectStore.projects[route.params.projectId]
if (project.parentProjectId) { if (project.parentProjectId) {
parentProject.value = projectStore.getProjectById(project.parentProjectId) parentProject.value = projectStore.projects[project.parentProjectId]
} }
}, },
{immediate: true}, {immediate: true},

View File

@ -539,7 +539,7 @@ const visible = ref(false)
const taskId = toRef(props, 'taskId') 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(() => { watchEffect(() => {
baseStore.handleSetCurrentProject({ baseStore.handleSetCurrentProject({
project: project.value, project: project.value,

View File

@ -245,7 +245,7 @@ watch(
const projectStore = useProjectStore() const projectStore = useProjectStore()
const defaultProject = computed({ const defaultProject = computed({
get: () => projectStore.getProjectById(settings.value.defaultProjectId) || undefined, get: () => projectStore.projects[settings.value.defaultProjectId],
set(l) { set(l) {
settings.value.defaultProjectId = l ? l.id : DEFAULT_PROJECT_ID settings.value.defaultProjectId = l ? l.id : DEFAULT_PROJECT_ID
}, },