import { For, Show, createSignal, createEffect, onMount, onCleanup } from 'solid-js' import { Icon } from './Icon' import { Modal } from './Modal' import { AuthModal } from './AuthModal' import { t } from '../../utils/intl' import { useModalStore } from '../../stores/ui' import { handleClientRouteLinkClick, router, Routes, useRouter } from '../../stores/router' import styles from './Header.module.scss' import { getPagePath } from '@nanostores/router' import { clsx } from 'clsx' import { HeaderAuth } from './HeaderAuth' import { SharePopup } from '../Article/SharePopup' const resources: { name: string; route: keyof Routes }[] = [ { name: t('zine'), route: 'home' }, { name: t('feed'), route: 'feed' }, { name: t('topics'), route: 'topics' } ] type Props = { title?: string isHeaderFixed?: boolean } export const Header = (props: Props) => { // signals const [getIsScrollingBottom, setIsScrollingBottom] = createSignal(false) const [getIsScrolled, setIsScrolled] = createSignal(false) const [fixed, setFixed] = createSignal(false) const [isSharePopupVisible, setIsSharePopupVisible] = createSignal(false) const [isProfilePopupVisible, setIsProfilePopupVisible] = createSignal(false) const { modal } = useModalStore() const { page } = useRouter() // methods const toggleFixed = () => setFixed((oldFixed) => !oldFixed) // effects let windowScrollTop = 0 createEffect(() => { const mainContent = document.querySelector('.main-content') as HTMLDivElement if (fixed() || modal() !== null) { windowScrollTop = window.scrollY mainContent.style.marginTop = `-${windowScrollTop}px` } document.body.classList.toggle('fixed', fixed() || modal() !== null) document.body.classList.toggle(styles.fixed, fixed() && !modal()) if (!fixed() && !modal()) { mainContent.style.marginTop = '' window.scrollTo(0, windowScrollTop) } }) onMount(() => { let scrollTop = window.scrollY const handleScroll = () => { setIsScrollingBottom(window.scrollY > scrollTop) setIsScrolled(window.scrollY > 0) scrollTop = window.scrollY } window.addEventListener('scroll', handleScroll, { passive: true }) onCleanup(() => { window.removeEventListener('scroll', handleScroll) }) }) return (
) }