useOrgMenuNavigation.ts38 lines · main
| 1 | 'use client' |
| 2 | |
| 3 | import { useCallback, useState } from 'react' |
| 4 | |
| 5 | import { getOrgMenuComponent } from './mobileOrgMenuRegistry' |
| 6 | import type { OrgNavItem } from './OrgMenuContent.utils' |
| 7 | |
| 8 | export function orgItemHasSubmenu(item: OrgNavItem): boolean { |
| 9 | return getOrgMenuComponent(item.key) !== null |
| 10 | } |
| 11 | |
| 12 | interface UseOrgMenuNavigationParams { |
| 13 | initialSectionKey: string | null |
| 14 | } |
| 15 | |
| 16 | export function useOrgMenuNavigation({ initialSectionKey }: UseOrgMenuNavigationParams) { |
| 17 | const [viewLevel, setViewLevel] = useState<'top' | 'section'>( |
| 18 | initialSectionKey ? 'section' : 'top' |
| 19 | ) |
| 20 | const [selectedSectionKey, setSelectedSectionKey] = useState<string | null>(initialSectionKey) |
| 21 | |
| 22 | const handleSubmenuClick = useCallback((item: OrgNavItem) => { |
| 23 | setSelectedSectionKey(item.key) |
| 24 | setViewLevel('section') |
| 25 | }, []) |
| 26 | |
| 27 | const handleBackToTop = useCallback(() => { |
| 28 | setViewLevel('top') |
| 29 | setSelectedSectionKey(null) |
| 30 | }, []) |
| 31 | |
| 32 | return { |
| 33 | viewLevel, |
| 34 | selectedSectionKey, |
| 35 | handleSubmenuClick, |
| 36 | handleBackToTop, |
| 37 | } |
| 38 | } |