mirror of
https://github.com/supabase/supabase.git
synced 2026-10-05 09:25:06 +03:00
- consolidate `top level menu` and `contextual menu` into nested menu on mobile - remove legacy mobile submenu
28 lines
1.0 KiB
TypeScript
28 lines
1.0 KiB
TypeScript
'use client'
|
|
|
|
import { useRouter } from 'next/router'
|
|
import { useLayoutEffect } from 'react'
|
|
|
|
import { OrgMenuContent } from '../ProjectLayout/LayoutHeader/MobileMenuContent/OrgMenuContent'
|
|
import { useMobileSheet } from '../ProjectLayout/NavigationBar/MobileSheetContext'
|
|
import { getPathnameWithoutQuery, isOrgMenuScope } from './OrganizationLayout.utils'
|
|
|
|
/**
|
|
* Registers the org menu with the mobile sheet when in org scope (/org/...).
|
|
* Unregisters when navigating away. Call from OrganizationLayout.
|
|
*/
|
|
export function useRegisterOrgMenu() {
|
|
const router = useRouter()
|
|
const { setContent: setMobileSheetContent, registerOpenMenu } = useMobileSheet()
|
|
|
|
useLayoutEffect(() => {
|
|
const pathname = getPathnameWithoutQuery(router.asPath, router.pathname)
|
|
if (!isOrgMenuScope(pathname)) return
|
|
|
|
const unregister = registerOpenMenu(() => {
|
|
setMobileSheetContent(<OrgMenuContent onCloseSheet={() => setMobileSheetContent(null)} />)
|
|
})
|
|
return unregister
|
|
}, [router.asPath, router.pathname, registerOpenMenu, setMobileSheetContent])
|
|
}
|