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, isSessionLoaded } = useSession() const { unreadNotificationsCount, showNotificationsPanel } = useNotifications() const { form, toggleEditorPanel, saveShout, saveDraft, publishShout } = useEditorContext() const handleBellIconClick = (event: Event) => { event.preventDefault() if (!author()?.id) { showModal('auth') return } showNotificationsPanel() } const isEditorPage = createMemo(() => page().route === 'edit' || page().route === 'editSettings') const isNotificationsVisible = createMemo(() => author()?.id && !isEditorPage()) const isSaveButtonVisible = createMemo(() => author()?.id && isEditorPage()) const isCreatePostButtonVisible = createMemo(() => !isEditorPage()) const isAuthenticatedControlsVisible = createMemo(() => author()?.id && session()?.user?.email_verified) const handleBurgerButtonClick = () => { toggleEditorPanel() } const handleSaveClick = () => { const hasTopics = form.selectedTopics?.length > 0 if (hasTopics) { saveShout(form) } else { saveDraft(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) => ( } /> ) }