import { For, Show, createSignal, createMemo, createEffect, onMount, onCleanup } from 'solid-js' import Private from './Private' import Notifications from './Notifications' import { Icon } from './Icon' import { Modal } from './Modal' import { Popup } from './Popup' import AuthModal from './AuthModal' import { t } from '../../utils/intl' import {useModalStore, showModal, useWarningsStore, toggleModal} from '../../stores/ui' import { useAuthStore } from '../../stores/auth' import { handleClientRouteLinkClick, router, Routes, useRouter } from '../../stores/router' import styles from './Header.module.scss' import stylesPopup from './Popup.module.scss' import privateStyles from './Private.module.scss' import { getPagePath } from '@nanostores/router' import { getLogger } from '../../utils/logger' import { clsx } from 'clsx' const log = getLogger('header') const resources: { name: string; route: keyof Routes }[] = [ { name: t('zine'), route: 'home' }, { name: t('feed'), route: 'feed' }, { name: t('topics'), route: 'topics' } ] const handleEnterClick = () => { showModal('auth') } 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 [visibleWarnings, setVisibleWarnings] = createSignal(false) // stores const { getWarnings } = useWarningsStore() const { session } = useAuthStore() const { getModal } = useModalStore() const { getPage } = useRouter() // methods const toggleWarnings = () => setVisibleWarnings(!visibleWarnings()) const toggleFixed = () => setFixed(!fixed()) // effects createEffect(() => { const isFixed = fixed() || (getModal() && getModal() !== 'share'); document.body.classList.toggle('fixed', isFixed); document.body.classList.toggle(styles.fixed, isFixed && !getModal()); }, [fixed(), getModal()]) // derived const authorized = createMemo(() => session()?.user?.slug) const handleBellIconClick = () => { if (!authorized()) { showModal('auth') return } toggleWarnings() } 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 (
) }