mirror of
https://github.com/netbirdio/docs.git
synced 2026-04-18 08:26:35 +00:00
- Replaced motion.header with a standard header in Layout component. - Removed layout props from motion elements in NavigationAPI and NavigationDocs components for improved performance and clarity. - Updated AnnouncementBannerProvider to make the banner always visible, removing scroll-based hiding logic.
94 lines
2.2 KiB
JavaScript
94 lines
2.2 KiB
JavaScript
import {
|
|
createContext,
|
|
useCallback,
|
|
useContext,
|
|
useEffect,
|
|
useMemo,
|
|
useState,
|
|
} from 'react'
|
|
|
|
import { useLocalStorage } from '@/hooks/useLocalStorage'
|
|
|
|
const BANNER_ENABLED = true
|
|
|
|
export const announcement = {
|
|
tag: '',
|
|
text: 'NetBird v0.60 Released - Native SSH Access',
|
|
link: '/manage/peers/ssh',
|
|
linkText: 'Read Release Documentation',
|
|
linkAlt: 'Learn more about the NetBird v0.60 release',
|
|
isExternal: false,
|
|
closeable: true,
|
|
}
|
|
|
|
const AnnouncementContext = createContext({
|
|
close: () => {},
|
|
isVisible: false,
|
|
bannerHeight: 0,
|
|
reportHeight: () => {},
|
|
})
|
|
|
|
export function AnnouncementBannerProvider({ children }) {
|
|
let [mounted, setMounted] = useState(false)
|
|
let [closedAnnouncement, setClosedAnnouncement] = useLocalStorage(
|
|
'netbird-announcement',
|
|
undefined
|
|
)
|
|
let announcementId = announcement.text
|
|
let [bannerHeight, setBannerHeight] = useState(0)
|
|
|
|
let close = () => {
|
|
setClosedAnnouncement(announcementId)
|
|
}
|
|
|
|
let isActive = useMemo(() => {
|
|
if (!mounted) return false
|
|
if (!BANNER_ENABLED) return false
|
|
return closedAnnouncement !== announcementId
|
|
}, [announcementId, closedAnnouncement, mounted])
|
|
|
|
let isVisible = isActive // Always visible when active, regardless of scroll
|
|
|
|
let reportHeight = useCallback((height) => {
|
|
setBannerHeight(height)
|
|
}, [])
|
|
|
|
useEffect(() => {
|
|
setMounted(true)
|
|
return () => setMounted(false)
|
|
}, [])
|
|
|
|
// Removed scroll-based hiding to make banner always sticky
|
|
// useEffect(() => {
|
|
// if (typeof window === 'undefined') {
|
|
// return
|
|
// }
|
|
|
|
// function handleScroll() {
|
|
// setIsHiddenByScroll(window.scrollY > 30)
|
|
// }
|
|
|
|
// handleScroll()
|
|
// window.addEventListener('scroll', handleScroll, { passive: true })
|
|
// return () => window.removeEventListener('scroll', handleScroll)
|
|
// }, [])
|
|
|
|
useEffect(() => {
|
|
if (!isVisible && bannerHeight !== 0) {
|
|
setBannerHeight(0)
|
|
}
|
|
}, [bannerHeight, isVisible])
|
|
|
|
return (
|
|
<AnnouncementContext.Provider
|
|
value={{ close, isVisible, bannerHeight, reportHeight }}
|
|
>
|
|
{children}
|
|
</AnnouncementContext.Provider>
|
|
)
|
|
}
|
|
|
|
export function useAnnouncements() {
|
|
return useContext(AnnouncementContext)
|
|
}
|