"use client"; import { useEffect, useMemo, useState } from "react"; import { useTranslations } from "next-intl"; import Link from "next/link"; import { usePathname } from "next/navigation"; import { HELP_MODES } from "../types/help-article.types"; import { usePageUrlGenerator } from "../../../client"; import { useHelpFilter } from "../hooks/useHelpFilter"; import { HowToService } from "../../how-to/data/HowToService"; import type { HowToInterface } from "../../how-to/data/HowToInterface"; export function HelpSideNav() { const t = useTranslations(); const generateUrl = usePageUrlGenerator(); const pathname = usePathname(); const [articles, setArticles] = useState([]); useEffect(() => { let active = true; HowToService.findPublished() .then((list) => active && setArticles(list)) .catch(() => active && setArticles([])); return () => { active = false; }; }, []); // useHelpFilter indexes by title/summary/tags — map HowTo getters into the shape it expects. const indexable = useMemo( () => articles.map((a) => ({ id: a.id, title: a.name, summary: a.summary ?? "", tags: a.tags, mode: a.howToType ?? "", slug: a.slug ?? "", })), [articles], ); const { query, setQuery, filtered } = useHelpFilter(indexable as any); const filtering = query.trim().length > 0; const groups = useMemo( () => HELP_MODES.map((mode) => ({ mode, articles: articles .filter((a) => a.howToType === mode && !a.draft) .sort((x, y) => (x.order ?? 0) - (y.order ?? 0)), })), [articles], ); const isActive = (mode: string, slug: string) => pathname.endsWith(`/help/${mode}/${slug}`); return ( ); }