From 634af32400e2e7d9f82b0a561020d0692e6c994f Mon Sep 17 00:00:00 2001 From: kolaente Date: Mon, 10 Apr 2023 17:39:29 +0200 Subject: [PATCH] wip: use map instead of object to store projects --- package.json | 1 + pnpm-lock.yaml | 10 ++++--- src/components/home/ProjectsNavigation.vue | 12 ++++----- src/components/home/navigation.vue | 6 +++-- src/stores/projects.ts | 31 +++++++++++----------- src/views/project/ListProjects.vue | 3 ++- 6 files changed, 34 insertions(+), 29 deletions(-) diff --git a/package.json b/package.json index 7ca62c6bf..68d2f0a38 100644 --- a/package.json +++ b/package.json @@ -61,6 +61,7 @@ "bulma-css-variables": "0.9.33", "camel-case": "4.1.2", "codemirror": "5.65.12", + "core-js": "^3.30.0", "date-fns": "2.29.3", "dayjs": "1.11.7", "dompurify": "3.0.1", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index bd211c381..b3da73aa1 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -54,6 +54,9 @@ dependencies: codemirror: specifier: 5.65.12 version: 5.65.12 + core-js: + specifier: ^3.30.0 + version: 3.30.0 date-fns: specifier: 2.29.3 version: 2.29.3 @@ -4236,7 +4239,7 @@ packages: '@babel/core': 7.21.3 '@babel/preset-env': 7.20.2(@babel/core@7.21.3) browserslist: 4.21.5 - core-js: 3.29.1 + core-js: 3.30.0 magic-string: 0.30.0 regenerator-runtime: 0.13.11 systemjs: 6.14.0 @@ -6081,10 +6084,9 @@ packages: browserslist: 4.21.5 dev: true - /core-js@3.29.1: - resolution: {integrity: sha512-+jwgnhg6cQxKYIIjGtAHq2nwUOolo9eoFZ4sHfUH09BLXBgxnH4gA0zEd+t+BO2cNB8idaBtZFcFTRjQJRJmAw==} + /core-js@3.30.0: + resolution: {integrity: sha512-hQotSSARoNh1mYPi9O2YaWeiq/cEB95kOrFb4NCrO4RIFt1qqNpKsaE+vy/L3oiqvND5cThqXzUU3r9F7Efztg==} requiresBuild: true - dev: true /core-util-is@1.0.2: resolution: {integrity: sha512-3lqz5YjWTYnW6dlDa5TLaTCcShfar1e40rmcJVwCBJC6mWlFuj0eCHIElmG1g5kyuJ/GD+8Wn4FFCcz4gJPfaQ==} diff --git a/src/components/home/ProjectsNavigation.vue b/src/components/home/ProjectsNavigation.vue index 2b228c914..637c553f9 100644 --- a/src/components/home/ProjectsNavigation.vue +++ b/src/components/home/ProjectsNavigation.vue @@ -42,7 +42,7 @@ import type {IProject} from '@/modelTypes/IProject' import {useProjectStore} from '@/stores/projects' const props = defineProps<{ - modelValue?: IProject[], + modelValue?: Map, canEditOrder: boolean, canCollapse?: boolean, level?: number, @@ -59,11 +59,11 @@ const projectStore = useProjectStore() // Vue draggable will modify the projects list as it changes their position which will not work on a prop. // Hence, we'll clone the prop and work on the clone. -const availableProjects = ref([]) +const availableProjects = ref>(new Map()) watch( () => props.modelValue, projects => { - availableProjects.value = projects || [] + availableProjects.value = projects || new Map() }, {immediate: true}, ) @@ -77,14 +77,14 @@ async function saveProjectPosition(e: SortableEvent) { // If the project was dragged to the last position, Safari will report e.newIndex as the size of the projectsActive // array instead of using the position. Because the index is wrong in that case, dragging the project will fail. // To work around that we're explicitly checking that case here and decrease the index. - const newIndex = e.newIndex === projectsActive.length ? e.newIndex - 1 : e.newIndex + const newIndex = e.newIndex === projectsActive.size > 0 ? e.newIndex - 1 : e.newIndex const projectId = parseInt(e.item.dataset.projectId) const project = projectStore.getProjectById(projectId) const parentProjectId = e.to.parentNode.dataset.projectId ? parseInt(e.to.parentNode.dataset.projectId) : 0 - const projectBefore = projectsActive[newIndex - 1] ?? null - const projectAfter = projectsActive[newIndex + 1] ?? null + const projectBefore = projectsActive.get(newIndex - 1) ?? null + const projectAfter = projectsActive.get(newIndex + 1) ?? null projectUpdating.value[project.id] = true const position = calculateItemPosition( diff --git a/src/components/home/navigation.vue b/src/components/home/navigation.vue index 2f9275f24..868cc847d 100644 --- a/src/components/home/navigation.vue +++ b/src/components/home/navigation.vue @@ -85,9 +85,11 @@ const menuActive = computed(() => baseStore.menuActive) const projectsLoading = computed(() => projectStore.isLoading) const projects = computed(() => projectStore.notArchivedRootProjects - .sort((a, b) => a.position - b.position)) + // .sort((a, b) => a.position - b.position)) +) const favoriteProjects = computed(() => projectStore.favoriteProjects - .sort((a, b) => a.position - b.position)) + // .sort((a, b) => a.position - b.position)) +)