diff --git a/components/PoisList/CategorySelector.vue b/components/PoisList/CategorySelector.vue index ab0baaf44..206159057 100644 --- a/components/PoisList/CategorySelector.vue +++ b/components/PoisList/CategorySelector.vue @@ -4,7 +4,7 @@ :model-value="categoryId" class="category-selector" solo - :items="Object.values(menuEntries).map((a) => a[0])" + :items="menuEntries" :label="$t(label)" variant="solo" rounded @@ -20,8 +20,8 @@ {{ item.title }} @@ -77,15 +77,13 @@ export default defineNuxtComponent({ }, computed: { - menuEntries(): { - [key: number]: [ - { - value: number - title: string - }, - ApiMenuCategory - ] - } { + menuEntries(): [ + { + value: number + title: string + category: ApiMenuCategory['category'] + } + ] { const menuIndex: { [key: number]: MenuItem } = {} this.menuItems .filter((menuItem) => !menuItem.hidden) @@ -94,59 +92,39 @@ export default defineNuxtComponent({ }) const locales = this.$i18n.locales - return Object.fromEntries( - ( - this.menuItems.filter( - (menuItem) => menuItem.category && !menuItem.hidden - ) as ApiMenuCategory[] - ) - .map((menuItem) => { - let parents: string[] = [] - let parentId = menuItem.parent_id - while (parentId) { - if (!menuIndex[parentId]) { - return undefined - } - const name = menuIndex[parentId].menu_group?.name.fr - if (name && menuIndex[parentId].parent_id) { - parents.push(name) - } - parentId = menuIndex[parentId].parent_id + const localeCompareOptions = locales.map( + (locale: string | LocaleObject) => + typeof locale === 'string' ? locale : locale.code + ) + return ( + this.menuItems.filter( + (menuItem) => menuItem.category && !menuItem.hidden + ) as ApiMenuCategory[] + ) + .map((menuItem) => { + let parents: string[] = [] + let parentId = menuItem.parent_id + while (parentId) { + if (!menuIndex[parentId]) { + return undefined + } + const name = menuIndex[parentId].menu_group?.name.fr + if (name && menuIndex[parentId].parent_id) { + parents.push(name) } + parentId = menuIndex[parentId].parent_id + } - return [ - { - value: menuItem.id, - title: [...parents.reverse(), menuItem.category.name.fr].join( - ' / ' - ), - }, - menuItem, - ] - }) - .filter( - ( - t - ): t is NonNullable< - [ - { - value: number - title: string - }, - ApiMenuCategory - ] - > => t != null - ) - .sort((a, b) => - a[0].title.localeCompare( - b[0].title, - locales.map((locale: string | LocaleObject) => - typeof locale === 'string' ? locale : locale.code - ) - ) - ) - .map((a) => [a[0].value, a]) - ) + return { + value: menuItem.id, + title: [...parents.reverse(), menuItem.category.name.fr].join( + ' / ' + ), + category: menuItem.category, + } + }) + .filter((t) => t != null) + .sort((a, b) => a.title.localeCompare(b.title, localeCompareOptions)) }, }, })