feature/projects-all-the-way-down #3323
|
@ -85,10 +85,8 @@ import ProjectsNavigation from '@/components/home/ProjectsNavigation.vue'
|
|||
const baseStore = useBaseStore()
|
||||
dpschen marked this conversation as resolved
Outdated
|
||||
const projectStore = useProjectStore()
|
||||
|
||||
const projects = computed(() => projectStore.notArchivedRootProjects
|
||||
.sort((a, b) => a.position - b.position))
|
||||
const favoriteProjects = computed(() => projectStore.favoriteProjects
|
||||
.sort((a, b) => a.position - b.position))
|
||||
const projects = computed(() => projectStore.notArchivedRootProjects)
|
||||
dpschen
commented
This sorts the returned computed of the store Error in vue developer tools:
This sorts the returned computed of the store
=> sort already in store OR create copy (worse performance)
Error in vue developer tools:
> [Vue warn] Set operation on key "0" failed: target is readonly. [...]
konrad
commented
Now sorting in store, that seems to work (or at least there are no errors now) Now sorting in store, that seems to work (or at least there are no errors now)
|
||||
const favoriteProjects = computed(() => projectStore.favoriteProjects)
|
||||
</script>
|
||||
|
||||
dpschen marked this conversation as resolved
Outdated
dpschen
commented
Simplify to
Simplify to
```ts
.sort((a, b) => a.position - b.position)
```
konrad
commented
Done. Done.
dpschen
commented
This sorts the returned computed of the store Error in vue developer tools:
This sorts the returned computed of the store
=> sort already in store OR create copy (worse performance)
Error in vue developer tools:
> [Vue warn] Set operation on key "0" failed: target is readonly. [...]
konrad
commented
Fixed as well. Fixed as well.
|
||||
<style lang="scss" scoped>
|
||||
|
|
|
@ -32,7 +32,8 @@ export const useProjectStore = defineStore('project', () => {
|
|||
|
||||
// The projects are stored as an object which has the project ids as keys.
|
||||
const projects = ref<ProjectState>({})
|
||||
const projectsArray = computed(() => Object.values(projects.value))
|
||||
const projectsArray = computed(() => Object.values(projects.value)
|
||||
.sort((a, b) => a.position - b.position))
|
||||
const notArchivedRootProjects = computed(() => projectsArray.value
|
||||
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.
|
||||
.filter(p => p.parentProjectId === 0 && !p.isArchived))
|
||||
const favoriteProjects = computed(() => projectsArray.value
|
||||
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.
|
||||
|
|
This computed as well.