Simpl-Resultat/src/hooks/useCategoryTaxonomy.ts
le king fu 742aa9ec3c
All checks were successful
PR Check / rust (push) Successful in 22m44s
PR Check / frontend (push) Successful in 2m17s
PR Check / rust (pull_request) Successful in 22m4s
PR Check / frontend (pull_request) Successful in 2m15s
feat(categories): add categoryTaxonomyService + useCategoryTaxonomy hook (#116)
Source of truth for the v1 IPC taxonomy on the TS side. Loads the bundled
JSON, exposes typed helpers (findById, findByPath, getLeaves, getParentById)
used by the upcoming Guide (#117) and Migration (#121) pages.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-04-20 20:53:15 -04:00

32 lines
737 B
TypeScript

import { useMemo } from "react";
import {
getTaxonomyV1,
findById,
findByPath,
getLeaves,
getParentById,
type Taxonomy,
type TaxonomyNode,
type TaxonomyLeaf,
} from "../services/categoryTaxonomyService";
export interface UseCategoryTaxonomyResult {
taxonomy: Taxonomy;
findById: (id: number) => TaxonomyNode | null;
findByPath: (path: string[]) => TaxonomyNode | null;
getLeaves: () => TaxonomyLeaf[];
getParentById: (id: number) => TaxonomyNode | null;
}
export function useCategoryTaxonomy(): UseCategoryTaxonomyResult {
return useMemo<UseCategoryTaxonomyResult>(
() => ({
taxonomy: getTaxonomyV1(),
findById,
findByPath,
getLeaves,
getParentById,
}),
[],
);
}