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>
32 lines
737 B
TypeScript
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,
|
|
}),
|
|
[],
|
|
);
|
|
}
|