Sort categories by translated name (#5307)
* Sort categories by translated name * Use locale and numeric * Remove @modrinth/ui import
This commit is contained in:
@@ -154,19 +154,23 @@ interface Category {
|
||||
}
|
||||
|
||||
const tags = useGeneratedState()
|
||||
const { formatMessage } = useVIntl()
|
||||
const { formatMessage, locale } = useVIntl()
|
||||
|
||||
const { projectV2: project, patchProject } = injectProjectPageContext()
|
||||
|
||||
const formatCategoryName = (categoryName: string) => {
|
||||
return formatCategory(formatMessage, categoryName)
|
||||
}
|
||||
|
||||
const { saved, current, saving, reset, save } = useSavable(
|
||||
() => ({
|
||||
selectedTags: sortedCategories(tags.value).filter(
|
||||
selectedTags: sortedCategories(tags.value, formatCategoryName, locale.value).filter(
|
||||
(x: Category) =>
|
||||
x.project_type === project.value.actualProjectType &&
|
||||
(project.value.categories.includes(x.name) ||
|
||||
project.value.additional_categories.includes(x.name)),
|
||||
) as Category[],
|
||||
featuredTags: sortedCategories(tags.value).filter(
|
||||
featuredTags: sortedCategories(tags.value, formatCategoryName, locale.value).filter(
|
||||
(x: Category) =>
|
||||
x.project_type === project.value.actualProjectType &&
|
||||
project.value.categories.includes(x.name),
|
||||
@@ -212,7 +216,7 @@ const { saved, current, saving, reset, save } = useSavable(
|
||||
|
||||
const categoryLists = computed(() => {
|
||||
const lists: Record<string, Category[]> = {}
|
||||
sortedCategories(tags.value).forEach((x: Category) => {
|
||||
sortedCategories(tags.value, formatCategoryName, locale.value).forEach((x: Category) => {
|
||||
if (x.project_type === project.value.actualProjectType) {
|
||||
const header = x.header
|
||||
if (!lists[header]) {
|
||||
@@ -253,9 +257,11 @@ const multipleResolutionTagsWarning = computed(() => {
|
||||
})
|
||||
|
||||
const allTagsSelectedWarning = computed(() => {
|
||||
const categoriesForProjectType = sortedCategories(tags.value).filter(
|
||||
(x: Category) => x.project_type === project.value.actualProjectType,
|
||||
)
|
||||
const categoriesForProjectType = sortedCategories(
|
||||
tags.value,
|
||||
formatCategoryName,
|
||||
locale.value,
|
||||
).filter((x: Category) => x.project_type === project.value.actualProjectType)
|
||||
const totalSelectedTags = current.value.selectedTags.length
|
||||
|
||||
if (
|
||||
|
||||
@@ -104,22 +104,6 @@ export default defineNuxtPlugin((nuxtApp) => {
|
||||
getProjectTypeForUrlShorthand(type, loaders, tags),
|
||||
)
|
||||
nuxtApp.provide('cycleValue', cycleValue)
|
||||
nuxtApp.provide('sortedCategories', () => {
|
||||
return tagStore.value.categories.slice().sort((a, b) => {
|
||||
const headerCompare = a.header.localeCompare(b.header)
|
||||
if (headerCompare !== 0) {
|
||||
return headerCompare
|
||||
}
|
||||
if (a.header === 'resolutions' && b.header === 'resolutions') {
|
||||
return a.name.replace(/\D/g, '') - b.name.replace(/\D/g, '')
|
||||
} else if (a.header === 'performance impact' && b.header === 'performance impact') {
|
||||
const x = ['potato', 'low', 'medium', 'high', 'screenshot']
|
||||
|
||||
return x.indexOf(a.name) - x.indexOf(b.name)
|
||||
}
|
||||
return 0
|
||||
})
|
||||
})
|
||||
})
|
||||
export const formatNumber = (number, abbreviate = true) => {
|
||||
const x = +number
|
||||
|
||||
Reference in New Issue
Block a user