From 96b8c0012988e4586718a11a77419b7752edeb80 Mon Sep 17 00:00:00 2001 From: Ku6epXBOCTuK Date: Tue, 25 Aug 2026 11:44:36 +0500 Subject: [PATCH] fix: get names from categories --- web/src/lib/categories.ts | 22 ++++++++++++---------- web/src/lib/registry.test.ts | 2 +- web/src/routes/list-tools/+page.svelte | 8 ++++---- 3 files changed, 17 insertions(+), 15 deletions(-) diff --git a/web/src/lib/categories.ts b/web/src/lib/categories.ts index 821202e..8a6fda0 100644 --- a/web/src/lib/categories.ts +++ b/web/src/lib/categories.ts @@ -7,14 +7,16 @@ export type CategoryId = | 'generate' | 'filters'; -export type Category = { id: CategoryId; label: string }; - -export const CATEGORIES: Category[] = [ - { id: 'convert', label: 'Конвертация' }, - { id: 'alpha', label: 'Прозрачность' }, - { id: 'color', label: 'Цвет' }, - { id: 'geometry', label: 'Геометрия' }, - { id: 'filters', label: 'Фильтры' }, - { id: 'analyze', label: 'Анализ' }, - { id: 'generate', label: 'Генерация' } +/** + * Порядок категорий в каталоге. Человекочитаемые названия живут в словарях + * i18n: секция categories, ключ = CategoryId. + */ +export const CATEGORIES: readonly CategoryId[] = [ + 'convert', + 'alpha', + 'color', + 'geometry', + 'filters', + 'analyze', + 'generate' ]; diff --git a/web/src/lib/registry.test.ts b/web/src/lib/registry.test.ts index e0e6115..453f548 100644 --- a/web/src/lib/registry.test.ts +++ b/web/src/lib/registry.test.ts @@ -21,7 +21,7 @@ describe('реестр инструментов', () => { }); it.each(TOOLS.map((t) => [t.id, t] as const))('%s: категория валидна', (_, tool) => { - expect(CATEGORIES.map((c) => c.id)).toContain(tool.category); + expect(CATEGORIES).toContain(tool.category); }); it.each(TOOLS.map((t) => [t.id, t] as const))('%s: исполнители определены', (_, tool) => { diff --git a/web/src/routes/list-tools/+page.svelte b/web/src/routes/list-tools/+page.svelte index bfcf87f..a21468b 100644 --- a/web/src/routes/list-tools/+page.svelte +++ b/web/src/routes/list-tools/+page.svelte @@ -15,11 +15,11 @@

{t('catalog.heading')}

{t('catalog.lead', { count: TOOLS.length })}

-{#each CATEGORIES as category (category.id)} - {@const categoryTools = TOOLS.filter((tool) => tool.category === category.id)} +{#each CATEGORIES as category (category)} + {@const categoryTools = TOOLS.filter((tool) => tool.category === category)} {#if categoryTools.length > 0} -
-

{t(`categories.${category.id}`)}

+
+

{t(`categories.${category}`)}

{#each categoryTools as tool (tool.id)}