diff --git a/src/features/toc/core/__snapshots__/buildMenu.test.ts.snap b/src/features/toc/core/__snapshots__/buildMenuSection.test.ts.snap similarity index 84% rename from src/features/toc/core/__snapshots__/buildMenu.test.ts.snap rename to src/features/toc/core/__snapshots__/buildMenuSection.test.ts.snap index bbc64bd..d6be9d2 100644 --- a/src/features/toc/core/__snapshots__/buildMenu.test.ts.snap +++ b/src/features/toc/core/__snapshots__/buildMenuSection.test.ts.snap @@ -1,6 +1,6 @@ // Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html -exports[`toc/buildMenu > should build a menu and highlight current page 1`] = ` +exports[`toc/buildMenuSection > should build a menu and highlight current page 1`] = ` [ { "defaultOpenState": false, @@ -35,7 +35,7 @@ exports[`toc/buildMenu > should build a menu and highlight current page 1`] = ` ] `; -exports[`toc/buildMenu > should build a menu even if there are no current page 1`] = ` +exports[`toc/buildMenuSection > should build a menu even if there are no current page 1`] = ` [ { "defaultOpenState": false, @@ -70,7 +70,7 @@ exports[`toc/buildMenu > should build a menu even if there are no current page 1 ] `; -exports[`toc/buildMenu > should build a nested menu 1`] = ` +exports[`toc/buildMenuSection > should build a nested menu 1`] = ` [ { "defaultOpenState": false, @@ -95,9 +95,9 @@ exports[`toc/buildMenu > should build a nested menu 1`] = ` ] `; -exports[`toc/buildMenu > should build an empty menu if there are no top level ids 1`] = `[]`; +exports[`toc/buildMenuSection > should build an empty menu if there are no top level ids 1`] = `[]`; -exports[`toc/buildMenu > should show page children 1`] = ` +exports[`toc/buildMenuSection > should show page children 1`] = ` [ { "defaultOpenState": true, diff --git a/src/features/toc/core/buildMenu.test.ts b/src/features/toc/core/buildMenuSection.test.ts similarity index 76% rename from src/features/toc/core/buildMenu.test.ts rename to src/features/toc/core/buildMenuSection.test.ts index 2f3e329..330d41a 100644 --- a/src/features/toc/core/buildMenu.test.ts +++ b/src/features/toc/core/buildMenuSection.test.ts @@ -1,18 +1,18 @@ import { describe, expect, it } from 'vitest' import type { TableOfContent } from '../types' -import { buildMenu } from './buildMenu' +import { buildMenuSection } from './buildMenuSection' import { getBreadCrumbs } from './getBreadCrumbs' import tocFlat from '../../../test/fixtures/toc/flat.json' import tocTwoLevels from '../../../test/fixtures/toc/two-levels.json' -describe('toc/buildMenu', () => { +describe('toc/buildMenuSection', () => { it('should build a menu and highlight current page', () => { const toc: TableOfContent = tocFlat const currentUrl = 'bar.html' const breadcrumbs = getBreadCrumbs(toc, currentUrl) - const menu = buildMenu(toc, { url: currentUrl, breadcrumbs }) + const menu = buildMenuSection(toc, { url: currentUrl, breadcrumbs }) expect(menu).toMatchSnapshot() }) @@ -21,7 +21,7 @@ describe('toc/buildMenu', () => { const toc: TableOfContent = tocFlat const currentUrl = '' const breadcrumbs = getBreadCrumbs(toc, currentUrl) - const menu = buildMenu(toc, { url: currentUrl, breadcrumbs }) + const menu = buildMenuSection(toc, { url: currentUrl, breadcrumbs }) expect(menu).toMatchSnapshot() }) @@ -31,7 +31,7 @@ describe('toc/buildMenu', () => { const currentUrl = '' const parentId = 'this-id-does-not-exist' const breadcrumbs = getBreadCrumbs(toc, currentUrl) - const menu = buildMenu(toc, { url: currentUrl, breadcrumbs, parentId }) + const menu = buildMenuSection(toc, { url: currentUrl, breadcrumbs, parentId }) expect(menu).toEqual([]) }) @@ -43,7 +43,7 @@ describe('toc/buildMenu', () => { } const currentUrl = '' const breadcrumbs = getBreadCrumbs(toc, currentUrl) - const menu = buildMenu(toc, { url: currentUrl, breadcrumbs }) + const menu = buildMenuSection(toc, { url: currentUrl, breadcrumbs }) expect(menu).toMatchSnapshot() }) @@ -52,7 +52,7 @@ describe('toc/buildMenu', () => { const toc: TableOfContent = tocTwoLevels const currentUrl = 'bar.html' const breadcrumbs = getBreadCrumbs(toc, currentUrl) - const menu = buildMenu(toc, { url: currentUrl, breadcrumbs }) + const menu = buildMenuSection(toc, { url: currentUrl, breadcrumbs }) expect(menu).toMatchSnapshot() }) @@ -61,7 +61,7 @@ describe('toc/buildMenu', () => { const toc: TableOfContent = tocTwoLevels const currentUrl = 'bar-features.html' const breadcrumbs = getBreadCrumbs(toc, currentUrl) - const menu = buildMenu(toc, { url: currentUrl, parentId: 'bar', breadcrumbs }) + const menu = buildMenuSection(toc, { url: currentUrl, parentId: 'bar', breadcrumbs }) expect(menu).toMatchSnapshot() }) diff --git a/src/features/toc/core/buildMenu.ts b/src/features/toc/core/buildMenuSection.ts similarity index 95% rename from src/features/toc/core/buildMenu.ts rename to src/features/toc/core/buildMenuSection.ts index 3e34446..e701209 100644 --- a/src/features/toc/core/buildMenu.ts +++ b/src/features/toc/core/buildMenuSection.ts @@ -44,7 +44,7 @@ const getPagesForParent = (toc: TableOfContent, parentId?: PageId): PageId[] => return toc.entities.pages[parentId]?.pages ?? [] } -export const buildMenu = (toc: TableOfContent, options: BuildMenuOptions): MenuItem[] => { +export const buildMenuSection = (toc: TableOfContent, options: BuildMenuOptions): MenuItem[] => { const { url, parentId, diff --git a/src/features/toc/index.ts b/src/features/toc/index.ts index a321103..2de36bb 100644 --- a/src/features/toc/index.ts +++ b/src/features/toc/index.ts @@ -1,5 +1,5 @@ export { useGetTocQuery } from './api/useGetTocQuery' -export { buildMenu } from './core/buildMenu' +export { buildMenuSection } from './core/buildMenuSection' export { getBreadCrumbs } from './core/getBreadCrumbs' export { getCurrentPage } from './core/getCurrentPage' export * from './types' diff --git a/src/features/toc/ui/Menu/Context/hooks.ts b/src/features/toc/ui/Menu/Context/hooks.ts index 5b4e667..dcdf95a 100644 --- a/src/features/toc/ui/Menu/Context/hooks.ts +++ b/src/features/toc/ui/Menu/Context/hooks.ts @@ -1,14 +1,14 @@ import { useContext } from 'react' -import { buildMenu } from '../../../core/buildMenu' +import { buildMenuSection } from '../../../core/buildMenuSection' import type { PageId, SectionHighlight } from '../../../types' import { LocationContext, TocContext } from './contexts' -export const useMenuItems = (parentId: PageId = '', level: number = 0, highlight: SectionHighlight) => { +export const useSectionItems = (parentId: PageId = '', level: number = 0, highlight: SectionHighlight) => { const { toc } = useContext(TocContext) const currentLocation = useContext(LocationContext) - const items = buildMenu(toc, { + const items = buildMenuSection(toc, { url: currentLocation.url, breadcrumbs: currentLocation.breadcrumbs, parentId, diff --git a/src/features/toc/ui/Menu/Section/Section.tsx b/src/features/toc/ui/Menu/Section/Section.tsx index 5b9dffd..17a0e0b 100644 --- a/src/features/toc/ui/Menu/Section/Section.tsx +++ b/src/features/toc/ui/Menu/Section/Section.tsx @@ -1,5 +1,5 @@ import type { PageId, SectionHighlight } from '../../../types' -import { useMenuItems } from '../Context/hooks' +import { useSectionItems } from '../Context/hooks' import { Item, ItemToggle } from '../Item/Item' type SectionProps = { @@ -9,7 +9,7 @@ type SectionProps = { } export function Section({ parentId, level, highlight }: SectionProps): JSX.Element { - const items = useMenuItems(parentId, level, highlight) + const items = useSectionItems(parentId, level, highlight) return ( <>