'use client' import { useRef } from 'react' import { useTranslation } from 'react-i18next' import { useContext } from 'use-context-selector' import { useMount } from 'ahooks' import cn from '@/utils/classnames' import { Apps02 } from '@/app/components/base/icons/src/vender/line/others' import I18n from '@/context/i18n' import { getLanguage } from '@/i18n/language' import { useStore as useLabelStore } from '@/app/components/tools/labels/store' import { fetchLabelList } from '@/service/tools' type Props = { value: string onSelect: (type: string) => void } const Icon = ({ svgString, active }: { svgString: string; active: boolean }) => { const svgRef = useRef(null) const SVGParser = (svg: string) => { if (!svg) return null const parser = new DOMParser() const doc = parser.parseFromString(svg, 'image/svg+xml') return doc.documentElement } useMount(() => { const svgElement = SVGParser(svgString) if (svgRef.current && svgElement) svgRef.current.appendChild(svgElement) }) return } const Category = ({ value, onSelect, }: Props) => { const { t } = useTranslation() const { locale } = useContext(I18n) const language = getLanguage(locale) const labelList = useLabelStore(s => s.labelList) const setLabelList = useLabelStore(s => s.setLabelList) useMount(() => { fetchLabelList().then((res) => { setLabelList(res) }) }) return (
{t('tools.addToolModal.category').toLocaleUpperCase()}
onSelect('')}> {t('tools.type.all')}
{labelList.map(label => (
onSelect(label.name)}>
{label.label[language]}
))}
) } export default Category