Files
Francesco Sansalvadore 156f904018 feat: floating mobile toolbar (#43444)
- move navigation components to `apps/studio/components/layouts/Navigation`
- add [FloatingMobileToolbar](https://github.com/supabase/supabase/pull/43444/changes#diff-3dffe47fd51ca851d612d8728e03b2dc344ec213d4f3a46a824d3fa32a7cc851) as quick access to tools such as search, assistant, inline editor, etc - behind feature flag and feature preview (true by default as it's a bit
annoying to have to enable it all the time as previews are stored in
local-storage)
- fix sidebar panels closing on viewport resizing (regression from previous pr)

https://github.com/user-attachments/assets/d6881e3b-5128-4306-bb82-3ca39c755dba

<img width="986" height="697" alt="Screenshot 2026-03-12 at 12 40 11"
src="https://github.com/user-attachments/assets/da8511e2-7d01-4237-b814-596031c747c5"
/>
2026-03-13 12:13:07 +00:00

134 lines
3.8 KiB
TypeScript

import { LOCAL_STORAGE_KEYS } from 'common'
import { useCustomContent } from 'hooks/custom-content/useCustomContent'
import { useIsFeatureEnabled } from 'hooks/misc/useIsFeatureEnabled'
import { useLocalStorageQuery } from 'hooks/misc/useLocalStorage'
import { withAuth } from 'hooks/misc/withAuth'
import { IS_PLATFORM } from 'lib/constants'
import { buildStudioPageTitle } from 'lib/page-title'
import Head from 'next/head'
import { useRouter } from 'next/router'
import type { PropsWithChildren } from 'react'
import { useEffect, useLayoutEffect, useMemo } from 'react'
import { useAppStateSnapshot } from 'state/app-state'
import { cn } from 'ui'
import { useMobileSheet } from '../Navigation/NavigationBar/MobileSheetContext'
import { AccountMenuContent } from './AccountMenuContent'
import { WithSidebar } from './WithSidebar'
export interface AccountLayoutProps {
title: string
}
const AccountLayout = ({ children, title }: PropsWithChildren<AccountLayoutProps>) => {
const router = useRouter()
const appSnap = useAppStateSnapshot()
const { setContent: setMobileSheetContent, registerOpenMenu } = useMobileSheet()
const showSecuritySettings = useIsFeatureEnabled('account:show_security_settings')
const { appTitle } = useCustomContent(['app:title'])
const brandTitle = appTitle || 'Supabase'
const [lastVisitedOrganization] = useLocalStorageQuery(
LOCAL_STORAGE_KEYS.LAST_VISITED_ORGANIZATION,
''
)
const backToDashboardURL =
appSnap.lastRouteBeforeVisitingAccountPage.length > 0
? appSnap.lastRouteBeforeVisitingAccountPage
: !!lastVisitedOrganization
? `/org/${lastVisitedOrganization}`
: '/organizations'
const currentPath = router.pathname
const pageTitle = buildStudioPageTitle({
section: title,
surface: 'Account',
brand: brandTitle,
})
const sections = useMemo(
() => [
{
key: 'account-settings',
heading: 'Account Settings',
links: [
{
key: 'preferences',
label: 'Preferences',
href: '/account/me',
isActive: currentPath === '/account/me',
},
{
key: 'access-tokens',
label: 'Access Tokens',
href: '/account/tokens',
isActive: currentPath === '/account/tokens' || currentPath === '/account/tokens/scoped',
},
...(showSecuritySettings
? [
{
key: 'security',
label: 'Security',
href: '/account/security',
isActive: currentPath === '/account/security',
},
]
: []),
],
},
{
key: 'logs',
heading: 'Logs',
links: [
{
key: 'audit-logs',
label: 'Audit Logs',
href: '/account/audit',
isActive: currentPath === '/account/audit',
},
],
},
],
[currentPath, showSecuritySettings]
)
useLayoutEffect(() => {
const unregister = registerOpenMenu(() => {
setMobileSheetContent(
<AccountMenuContent sections={sections} onCloseSheet={() => setMobileSheetContent(null)} />
)
})
return unregister
}, [registerOpenMenu, setMobileSheetContent, sections])
useEffect(() => {
if (!IS_PLATFORM) {
router.push('/project/default')
}
}, [router])
return (
<>
<Head>
<title>{pageTitle}</title>
<meta name="description" content="Supabase Studio" />
</Head>
<div className={cn('flex flex-col w-screen h-[calc(100vh-48px)]')}>
<WithSidebar
title=""
breadcrumbs={[]}
backToDashboardURL={backToDashboardURL}
sections={sections}
>
{children}
</WithSidebar>
</div>
</>
)
}
export default withAuth(AccountLayout)