2023-07-13 07:22:08 -04:00
|
|
|
import { Toolbar } from '../Toolbar'
|
2023-07-27 18:59:40 -04:00
|
|
|
import UserSidebarMenu from './UserSidebarMenu'
|
2023-08-18 10:27:01 -04:00
|
|
|
import { ProjectWithEntryPointMetadata } from '../Router'
|
|
|
|
import ProjectSidebarMenu from './ProjectSidebarMenu'
|
2023-08-29 10:48:55 -04:00
|
|
|
import { useGlobalStateContext } from 'hooks/useGlobalStateContext'
|
2023-08-31 09:47:59 -04:00
|
|
|
import styles from './AppHeader.module.css'
|
2023-09-12 14:58:59 -04:00
|
|
|
import { NetworkHealthIndicator } from './NetworkHealthIndicator'
|
2023-07-13 07:22:08 -04:00
|
|
|
|
|
|
|
interface AppHeaderProps extends React.PropsWithChildren {
|
|
|
|
showToolbar?: boolean
|
2023-08-18 10:27:01 -04:00
|
|
|
project?: ProjectWithEntryPointMetadata
|
2023-08-06 21:29:26 -04:00
|
|
|
className?: string
|
2023-08-18 10:27:01 -04:00
|
|
|
enableMenu?: boolean
|
2023-07-13 07:22:08 -04:00
|
|
|
}
|
|
|
|
|
2023-08-06 21:29:26 -04:00
|
|
|
export const AppHeader = ({
|
|
|
|
showToolbar = true,
|
2023-08-18 10:27:01 -04:00
|
|
|
project,
|
2023-08-06 21:29:26 -04:00
|
|
|
children,
|
|
|
|
className = '',
|
2023-08-18 10:27:01 -04:00
|
|
|
enableMenu = false,
|
2023-08-06 21:29:26 -04:00
|
|
|
}: AppHeaderProps) => {
|
2023-08-29 10:48:55 -04:00
|
|
|
const {
|
|
|
|
auth: {
|
|
|
|
context: { user },
|
|
|
|
},
|
|
|
|
} = useGlobalStateContext()
|
2023-07-27 18:59:40 -04:00
|
|
|
|
2023-07-13 07:22:08 -04:00
|
|
|
return (
|
2023-08-06 21:29:26 -04:00
|
|
|
<header
|
|
|
|
className={
|
2023-09-16 01:23:11 -04:00
|
|
|
(showToolbar ? 'w-full grid ' : 'flex justify-between ') +
|
2023-08-31 09:47:59 -04:00
|
|
|
styles.header +
|
2023-08-31 10:41:24 -04:00
|
|
|
' overlaid-panes sticky top-0 z-20 py-1 px-5 bg-chalkboard-10/70 dark:bg-chalkboard-100/50 border-b dark:border-b-2 border-chalkboard-30 dark:border-chalkboard-90 items-center ' +
|
2023-08-06 21:29:26 -04:00
|
|
|
className
|
|
|
|
}
|
|
|
|
>
|
2023-08-18 10:27:01 -04:00
|
|
|
<ProjectSidebarMenu renderAsLink={!enableMenu} project={project} />
|
2023-07-13 07:22:08 -04:00
|
|
|
{/* Toolbar if the context deems it */}
|
|
|
|
{showToolbar && (
|
2023-09-16 01:23:11 -04:00
|
|
|
<div className="max-w-lg md:max-w-xl lg:max-w-2xl xl:max-w-4xl 2xl:max-w-5xl">
|
2023-07-13 07:22:08 -04:00
|
|
|
<Toolbar />
|
|
|
|
</div>
|
|
|
|
)}
|
2023-07-27 18:59:40 -04:00
|
|
|
{/* If there are children, show them, otherwise show User menu */}
|
2023-08-31 09:47:59 -04:00
|
|
|
{children || (
|
2023-09-12 14:58:59 -04:00
|
|
|
<div className="ml-auto flex items-center gap-1">
|
|
|
|
<NetworkHealthIndicator />
|
2023-08-31 09:47:59 -04:00
|
|
|
<UserSidebarMenu user={user} />
|
|
|
|
</div>
|
|
|
|
)}
|
2023-07-13 07:22:08 -04:00
|
|
|
</header>
|
|
|
|
)
|
|
|
|
}
|