Skip to content

Commit

Permalink
Category selector need unfiltered menu items
Browse files Browse the repository at this point in the history
  • Loading branch information
frodrigo committed Feb 26, 2024
1 parent 3f3f51f commit c27da58
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 23 deletions.
5 changes: 3 additions & 2 deletions components/Home/Embedded.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<script lang="ts">
import type { FitBoundsOptions } from 'maplibre-gl'
import { mapActions } from 'pinia'
import { mapActions, mapState } from 'pinia'
import { defineNuxtComponent, useRequestHeaders } from '#app'
import HomeMixin from '~/components/Home/HomeMixin'
Expand All @@ -26,6 +26,7 @@ export default defineNuxtComponent({
mixins: [HomeMixin],
computed: {
...mapState(menuStore, ['menuItems']),
fitBoundsPaddingOptions(): FitBoundsOptions['padding'] {
return {
top: 100,
Expand Down Expand Up @@ -146,7 +147,7 @@ export default defineNuxtComponent({
:boundary-area="boundaryArea || settings.polygon.data"
/>
<CategorySelector
:menu-items="Object.values(apiMenuCategory || {})"
:menu-items="menuItems || []"
label="categorySelector.placeholderAdd"
class="tw-p-4 tw-absolute tw-z-1 tw-w-full"
@category-change="onMenuChange"
Expand Down
25 changes: 9 additions & 16 deletions components/PoisList/CategorySelector.vue
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export default defineNuxtComponent({
props: {
menuItems: {
type: Array as PropType<ApiMenuCategory[]>,
type: Array as PropType<Record<number, MenuItem>>,
required: true,
},
categoryId: {
Expand All @@ -44,42 +44,35 @@ export default defineNuxtComponent({
computed: {
menuEntries(): Array<{ value: number, title: string, category: ApiMenuCategory['category'] } | undefined> {
const menuIndex: { [key: number]: MenuItem } = {}
this.menuItems
.filter(menuItem => !menuItem.hidden)
.forEach((menuItem) => {
menuIndex[menuItem.id] = menuItem
})
const locales = this.$i18n.locales
const localeCompareOptions = locales.map(
(locale: string | LocaleObject) =>
typeof locale === 'string' ? locale : locale.code,
)
return this.menuItems.filter(
return Object.values(this.menuItems).filter(
menuItem => menuItem.category && !menuItem.hidden,
)
.map((menuItem) => {
const parents: string[] = []
let parentId = menuItem.parent_id
while (parentId) {
if (!menuIndex[parentId])
if (!this.menuItems[parentId])
return undefined
const name = menuIndex[parentId].menu_group?.name.fr
if (name && menuIndex[parentId].parent_id)
parents.push(name)
const name = this.menuItems[parentId].menu_group?.name.fr
if (name && this.menuItems[parentId].parent_id)
parents.unshift(name)
parentId = menuIndex[parentId].parent_id
parentId = this.menuItems[parentId].parent_id
}
return {
value: menuItem.id,
title: [...parents.reverse(), menuItem.category.name.fr].join(
title: [...parents, (menuItem as ApiMenuCategory).category.name.fr].join(
' / ',
),
category: menuItem.category,
category: (menuItem as ApiMenuCategory).category,
}
})
.filter(t => t !== undefined)
Expand Down
8 changes: 3 additions & 5 deletions components/PoisList/PoisList.vue
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,10 @@ export default defineNuxtComponent({
},
computed: {
...mapState(menuStore, ['apiMenuCategory']),
...mapState(menuStore, ['menuItems']),
category(): ApiMenuCategory | undefined {
return Object.values(this.apiMenuCategory || {}).find(
menuItem => menuItem.id === this.categoryId,
)
return (this.menuItems || {})[this.categoryId] as ApiMenuCategory
},
fields(): FieldsListItem[] {
Expand Down Expand Up @@ -121,7 +119,7 @@ export default defineNuxtComponent({
</template>
<template #body>
<CategorySelector
:menu-items="apiMenuCategory || []"
:menu-items="menuItems || []"
:category-id="categoryId"
@category-change="onMenuChange"
/>
Expand Down

0 comments on commit c27da58

Please sign in to comment.