import { useEffect, useRef } from 'react' import Link from 'next/link' import BLOG from '@/blog.config' import { useGlobal } from '@/lib/global' import CONFIG_NOBELIUM from '../config_nobelium' import { SvgIcon } from './SvgIcon' const Nav = props => { const { navBarTitle, fullWidth, siteInfo } = props 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 <>
} const NavBar = props => { const { customNav } = props const { locale } = useGlobal() let links = [ { id: 2, name: locale.NAV.RSS, to: '/feed', show: BLOG.ENABLE_RSS && CONFIG_NOBELIUM.MENU_RSS, target: '_blank' }, { icon: 'fas fa-search', name: locale.NAV.SEARCH, to: '/search', show: CONFIG_NOBELIUM.MENU_SEARCH }, { icon: 'fas fa-archive', name: locale.NAV.ARCHIVE, to: '/archive', show: CONFIG_NOBELIUM.MENU_ARCHIVE }, { icon: 'fas fa-folder', name: locale.COMMON.CATEGORY, to: '/category', show: CONFIG_NOBELIUM.MENU_CATEGORY }, { icon: 'fas fa-tag', name: locale.COMMON.TAGS, to: '/tag', show: CONFIG_NOBELIUM.MENU_TAG } ] if (customNav) { links = links.concat(customNav) } return (
) } export default Nav