Sort categories by translated name (#5307)

* Sort categories by translated name

* Use locale and numeric

* Remove @modrinth/ui import
This commit is contained in:
Jerozgen
2026-02-09 04:19:04 +03:00
committed by GitHub
parent 4eb0f0c206
commit a8c5e036d0
4 changed files with 26 additions and 73 deletions

View File

@@ -1,6 +1,6 @@
import type { Labrinth } from '@modrinth/api-client'
import { ClientIcon, getCategoryIcon, getLoaderIcon, ServerIcon } from '@modrinth/assets'
import { sortByNameOrNumber } from '@modrinth/utils'
import { sortedCategories } from '@modrinth/utils'
import { type Component, computed, readonly, type Ref, ref } from 'vue'
import { type LocationQueryRaw, type LocationQueryValue, useRoute } from 'vue-router'
@@ -114,26 +114,14 @@ export function useSearch(
const toggledGroups = ref<string[]>([])
const overriddenProvidedFilterTypes = ref<string[]>([])
const { formatMessage } = useVIntl()
const { formatMessage, locale } = useVIntl()
const formatCategoryName = (categoryName: string) => {
return formatCategory(formatMessage, categoryName)
}
const filters = computed(() => {
const categoryFilters: Record<string, FilterType> = {}
const sortedCategories = sortByNameOrNumber(tags.value.categories.slice(), ['header', 'name'])
sortedCategories.sort((a, b) => {
if (a.header === 'performance impact' && b.header === 'performance impact') {
const qualityOrder = ['potato', 'low', 'medium', 'high', 'screenshot']
const aIndex = qualityOrder.indexOf(a.name)
const bIndex = qualityOrder.indexOf(b.name)
if (aIndex !== -1 && bIndex !== -1) {
return aIndex - bIndex
}
if (aIndex !== -1) return -1
if (bIndex !== -1) return 1
}
return 0
})
for (const category of sortedCategories) {
for (const category of sortedCategories(tags.value, formatCategoryName, locale.value)) {
const filterTypeId = `category_${category.project_type}_${category.header}`
if (!categoryFilters[filterTypeId]) {
categoryFilters[filterTypeId] = {