RealtimeLayout.tsx 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. import { useRouter } from 'next/router'
  2. import type { PropsWithChildren } from 'react'
  3. import { ProjectLayout } from '../ProjectLayout'
  4. import { generateRealtimeMenu } from './RealtimeMenu.utils'
  5. import { ProductMenu } from '@/components/ui/ProductMenu'
  6. import { ProductMenuShortcuts } from '@/components/ui/ProductMenu/ProductMenuShortcuts'
  7. import { useSelectedProjectQuery } from '@/hooks/misc/useSelectedProject'
  8. import { withAuth } from '@/hooks/misc/withAuth'
  9. /**
  10. * Menu-only component for the Realtime section. Used by the desktop sidebar and by the
  11. * mobile sheet submenu. Must not wrap ProjectLayout so that opening the realtime submenu
  12. * in the mobile sheet does not overwrite registerOpenMenu and break the menu button.
  13. */
  14. export const RealtimeProductMenu = () => {
  15. const router = useRouter()
  16. const { data: project } = useSelectedProjectQuery()
  17. const page = router.pathname.split('/')[4]
  18. return <ProductMenu page={page} menu={generateRealtimeMenu(project ?? undefined)} />
  19. }
  20. export interface RealtimeLayoutProps {
  21. title: string
  22. }
  23. export const RealtimeLayout = ({ title, children }: PropsWithChildren<RealtimeLayoutProps>) => {
  24. const { data: project } = useSelectedProjectQuery()
  25. const router = useRouter()
  26. const page = router.pathname.split('/')[4]
  27. const menu = generateRealtimeMenu(project)
  28. return (
  29. <ProjectLayout
  30. product="Realtime"
  31. browserTitle={{ section: title }}
  32. productMenu={<ProductMenu page={page} menu={menu} />}
  33. isBlocking={false}
  34. >
  35. <ProductMenuShortcuts menu={menu} />
  36. {children}
  37. </ProjectLayout>
  38. )
  39. }
  40. export default withAuth(RealtimeLayout)