import { useEffect, useRef } from 'react'
import Link from 'next/link'
import BLOG from '@/blog.config'
import { useGlobal } from '@/lib/global'
const NavBar = (props) => {
const { customNav } = props
const { locale } = useGlobal()
let links = [
{ id: 2, name: locale.NAV.RSS, to: '/feed', show: true },
{ icon: 'fas fa-search', name: locale.NAV.SEARCH, to: '/search', show: true },
{ icon: 'fas fa-archive', name: locale.NAV.ARCHIVE, to: '/archive', show: true },
{ icon: 'fas fa-folder', name: locale.COMMON.CATEGORY, to: '/category', show: false },
{ icon: 'fas fa-tag', name: locale.COMMON.TAGS, to: '/tag', show: true }
]
if (customNav) {
links = links.concat(customNav)
}
return (
)
}
const Header = ({ navBarTitle, fullWidth }) => {
const useSticky = !BLOG.autoCollapsedNavBar
const navRef = useRef(null)
const sentinalRef = useRef([])
const handler = ([entry]) => {
if (navRef && navRef.current && useSticky) {
if (!entry.isIntersecting && entry !== undefined) {
navRef.current?.classList.add('sticky-nav-full')
} else {
navRef.current?.classList.remove('sticky-nav-full')
}
} else {
navRef.current?.classList.add('remove-sticky')
}
}
useEffect(() => {
const obvserver = new window.IntersectionObserver(handler)
obvserver.observe(sentinalRef.current)
// Don't touch this, I have no idea how it works XD
// return () => {
// if (sentinalRef.current) obvserver.unobserve(sentinalRef.current)
// }
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [sentinalRef])
return (
<>
{navBarTitle
? (
{navBarTitle}
)
: (
{BLOG.title},{' '}
{BLOG.description}
)}
>
)
}
export default Header