import { getPagePath } from '@nanostores/router' import { clsx } from 'clsx' import { Show, createMemo, createSignal, onCleanup, onMount } from 'solid-js' import { useEditorContext } from '../../context/editor' import { useLocalize } from '../../context/localize' import { useNotifications } from '../../context/notifications' import { useSession } from '../../context/session' import { router, useRouter } from '../../stores/router' import { showModal } from '../../stores/ui' import { Userpic } from '../Author/Userpic' import { Button } from '../_shared/Button' import { Icon } from '../_shared/Icon' import { Popover } from '../_shared/Popover' import { ShowOnlyOnClient } from '../_shared/ShowOnlyOnClient' import { Popup } from '../_shared/Popup' import styles from './Header/Header.module.scss' import { ProfilePopup } from './ProfilePopup' type Props = { setIsProfilePopupVisible: (value: boolean) => void } type IconedButtonProps = { value: string icon: string action: () => void } const MD_WIDTH_BREAKPOINT = 992 export const HeaderAuth = (props: Props) => { const { t } = useLocalize() const { page } = useRouter() const { session, author, isAuthenticated, isSessionLoaded } = useSession() const { unreadNotificationsCount, showNotificationsPanel } = useNotifications() const { form, toggleEditorPanel, saveShout, publishShout } = useEditorContext() const handleBellIconClick = (event: Event) => { event.preventDefault() if (!isAuthenticated()) { showModal('auth') return } showNotificationsPanel() } const isEditorPage = createMemo(() => page().route === 'edit' || page().route === 'editSettings') const isNotificationsVisible = createMemo(() => isAuthenticated() && !isEditorPage()) const isSaveButtonVisible = createMemo(() => isAuthenticated() && isEditorPage()) const isCreatePostButtonVisible = createMemo(() => !isEditorPage()) const isAuthenticatedControlsVisible = createMemo( () => isAuthenticated() && session()?.user?.email_verified, ) const handleBurgerButtonClick = () => { toggleEditorPanel() } const handleSaveButtonClick = () => { saveShout(form) } const [width, setWidth] = createSignal(0) const [editorMode, setEditorMode] = createSignal(t('Editing')) onMount(() => { const handleResize = () => setWidth(window.innerWidth) handleResize() window.addEventListener('resize', handleResize) onCleanup(() => window.removeEventListener('resize', handleResize)) }) const renderIconedButton = (buttonProps: IconedButtonProps) => { return ( {buttonProps.value}} variant={'light'} onClick={buttonProps.action} class={styles.editorControl} /> } > {(ref) => ( } /> ) }