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-10-16 13:28:41 -04:00
|
|
|
import { IndexLoaderData } from '../Router'
|
2023-08-18 10:27:01 -04:00
|
|
|
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-12-06 14:44:13 -05:00
|
|
|
import { useCommandsContext } from 'hooks/useCommandsContext'
|
|
|
|
import { ActionButton } from './ActionButton'
|
2023-07-13 07:22:08 -04:00
|
|
|
|
|
|
|
interface AppHeaderProps extends React.PropsWithChildren {
|
|
|
|
showToolbar?: boolean
|
2023-10-16 13:28:41 -04:00
|
|
|
project?: Omit<IndexLoaderData, 'code'>
|
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-12-06 14:44:13 -05:00
|
|
|
const { setCommandBarOpen } = useCommandsContext()
|
2023-10-11 13:36:54 +11:00
|
|
|
const { auth } = useGlobalStateContext()
|
|
|
|
const user = auth?.context?.user
|
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-12-06 14:44:13 -05:00
|
|
|
'w-full grid ' +
|
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-10-17 12:31:14 -04:00
|
|
|
<ProjectSidebarMenu
|
|
|
|
renderAsLink={!enableMenu}
|
|
|
|
project={project?.project}
|
|
|
|
file={project?.file}
|
|
|
|
/>
|
2023-07-13 07:22:08 -04:00
|
|
|
{/* Toolbar if the context deems it */}
|
2023-12-06 14:44:13 -05:00
|
|
|
<div className="flex-grow flex justify-center max-w-lg md:max-w-xl lg:max-w-2xl xl:max-w-4xl 2xl:max-w-5xl">
|
|
|
|
{showToolbar ? (
|
2023-07-13 07:22:08 -04:00
|
|
|
<Toolbar />
|
2023-12-06 14:44:13 -05:00
|
|
|
) : (
|
|
|
|
<ActionButton
|
|
|
|
Element="button"
|
|
|
|
onClick={() => setCommandBarOpen(true)}
|
|
|
|
className="text-sm self-center flex items-center w-fit gap-3"
|
|
|
|
>
|
|
|
|
Command Palette{' '}
|
|
|
|
<kbd className="bg-energy-10/50 dark:bg-chalkboard-100 dark:text-energy-10 inline-block px-1 py-0.5 border-energy-10 dark:border-chalkboard-90">
|
|
|
|
⌘K
|
|
|
|
</kbd>
|
|
|
|
</ActionButton>
|
|
|
|
)}
|
|
|
|
</div>
|
|
|
|
<div className="flex items-center gap-1 ml-auto">
|
|
|
|
{/* If there are children, show them, otherwise show User menu */}
|
|
|
|
{children || (
|
|
|
|
<>
|
|
|
|
<NetworkHealthIndicator />
|
|
|
|
<UserSidebarMenu user={user} />
|
|
|
|
</>
|
|
|
|
)}
|
|
|
|
</div>
|
2023-07-13 07:22:08 -04:00
|
|
|
</header>
|
|
|
|
)
|
|
|
|
}
|