2023-07-18 16:57:14 +08:00
|
|
|
'use client'
|
2025-06-24 09:10:30 +08:00
|
|
|
import React, { useState } from 'react'
|
2023-07-18 16:57:14 +08:00
|
|
|
import { usePathname } from 'next/navigation'
|
|
|
|
import s from './index.module.css'
|
2025-06-24 09:10:30 +08:00
|
|
|
import { useEventEmitterContextContext } from '@/context/event-emitter'
|
2024-07-09 15:05:40 +08:00
|
|
|
import classNames from '@/utils/classnames'
|
2023-07-18 16:57:14 +08:00
|
|
|
|
|
|
|
type HeaderWrapperProps = {
|
|
|
|
children: React.ReactNode
|
|
|
|
}
|
|
|
|
|
|
|
|
const HeaderWrapper = ({
|
|
|
|
children,
|
|
|
|
}: HeaderWrapperProps) => {
|
|
|
|
const pathname = usePathname()
|
2024-12-23 11:17:49 +08:00
|
|
|
const isBordered = ['/apps', '/datasets', '/datasets/create', '/tools'].includes(pathname)
|
2025-06-30 22:00:35 +08:00
|
|
|
// Check if the current path is a workflow canvas & fullscreen
|
2025-06-24 09:10:30 +08:00
|
|
|
const inWorkflowCanvas = pathname.endsWith('/workflow')
|
|
|
|
const workflowCanvasMaximize = localStorage.getItem('workflow-canvas-maximize') === 'true'
|
|
|
|
const [hideHeader, setHideHeader] = useState(workflowCanvasMaximize)
|
|
|
|
const { eventEmitter } = useEventEmitterContextContext()
|
|
|
|
|
|
|
|
eventEmitter?.useSubscription((v: any) => {
|
|
|
|
if (v?.type === 'workflow-canvas-maximize')
|
|
|
|
setHideHeader(v.payload)
|
|
|
|
})
|
|
|
|
|
2023-07-18 16:57:14 +08:00
|
|
|
return (
|
|
|
|
<div className={classNames(
|
2025-06-27 13:22:29 +08:00
|
|
|
'sticky left-0 right-0 top-0 z-[15] flex min-h-[56px] shrink-0 grow-0 basis-auto flex-col',
|
2023-07-18 16:57:14 +08:00
|
|
|
s.header,
|
2024-12-13 17:29:09 +08:00
|
|
|
isBordered ? 'border-b border-divider-regular' : '',
|
2025-06-30 22:00:35 +08:00
|
|
|
hideHeader && inWorkflowCanvas && 'hidden',
|
2023-07-18 16:57:14 +08:00
|
|
|
)}
|
|
|
|
>
|
2023-11-27 11:47:48 +08:00
|
|
|
{children}
|
2023-07-18 16:57:14 +08:00
|
|
|
</div>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
export default HeaderWrapper
|