2024-11-05 15:07:24 +08:00
|
|
|
import { useTranslation } from 'react-i18next'
|
2024-11-06 11:55:19 +08:00
|
|
|
import type { TFunction } from 'i18next'
|
2024-11-19 15:08:39 +08:00
|
|
|
import {
|
|
|
|
categoryKeys,
|
|
|
|
tagKeys,
|
|
|
|
} from './constants'
|
2024-11-05 15:07:24 +08:00
|
|
|
|
2024-11-05 17:35:18 +08:00
|
|
|
type Tag = {
|
|
|
|
name: string
|
|
|
|
label: string
|
|
|
|
}
|
|
|
|
|
2024-11-06 11:55:19 +08:00
|
|
|
export const useTags = (translateFromOut?: TFunction) => {
|
|
|
|
const { t: translation } = useTranslation()
|
|
|
|
const t = translateFromOut || translation
|
2024-11-05 15:07:24 +08:00
|
|
|
|
2024-11-19 15:08:39 +08:00
|
|
|
const tags = tagKeys.map((tag) => {
|
|
|
|
return {
|
|
|
|
name: tag,
|
|
|
|
label: t(`pluginTags.tags.${tag}`),
|
|
|
|
}
|
|
|
|
})
|
2024-11-05 17:35:18 +08:00
|
|
|
|
|
|
|
const tagsMap = tags.reduce((acc, tag) => {
|
|
|
|
acc[tag.name] = tag
|
|
|
|
return acc
|
|
|
|
}, {} as Record<string, Tag>)
|
|
|
|
|
|
|
|
return {
|
|
|
|
tags,
|
|
|
|
tagsMap,
|
|
|
|
}
|
2024-11-05 15:07:24 +08:00
|
|
|
}
|
2024-11-13 16:55:43 +08:00
|
|
|
|
|
|
|
type Category = {
|
|
|
|
name: string
|
|
|
|
label: string
|
|
|
|
}
|
|
|
|
|
|
|
|
export const useCategories = (translateFromOut?: TFunction) => {
|
|
|
|
const { t: translation } = useTranslation()
|
|
|
|
const t = translateFromOut || translation
|
|
|
|
|
2024-11-19 15:08:39 +08:00
|
|
|
const categories = categoryKeys.map((category) => {
|
2024-12-12 17:29:25 +08:00
|
|
|
if (category === 'agent') {
|
|
|
|
return {
|
2024-12-27 13:57:54 +08:00
|
|
|
name: 'agent_strategy',
|
2024-12-12 17:29:25 +08:00
|
|
|
label: t(`plugin.category.${category}s`),
|
|
|
|
}
|
|
|
|
}
|
2024-11-19 15:08:39 +08:00
|
|
|
return {
|
|
|
|
name: category,
|
|
|
|
label: t(`plugin.category.${category}s`),
|
|
|
|
}
|
|
|
|
})
|
2024-11-13 16:55:43 +08:00
|
|
|
|
|
|
|
const categoriesMap = categories.reduce((acc, category) => {
|
|
|
|
acc[category.name] = category
|
|
|
|
return acc
|
|
|
|
}, {} as Record<string, Category>)
|
|
|
|
|
|
|
|
return {
|
|
|
|
categories,
|
|
|
|
categoriesMap,
|
|
|
|
}
|
|
|
|
}
|