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 { useUI } from '~/context/ui' import type { Author } from '~/graphql/schema/core.gen' 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 { A, useLocation } from '@solidjs/router' 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 { showModal } = useUI() const { session, isSessionLoaded } = useSession() const author = createMemo(() => session()?.user?.app_data?.profile as Author) const { unreadNotificationsCount, showNotificationsPanel } = useNotifications() const { form, toggleEditorPanel, publishShout } = useEditorContext() const handleBellIconClick = (event: Event) => { event.preventDefault() if (!session()?.access_token) { showModal('auth') return } showNotificationsPanel() } const loc = useLocation() const isEditorPage = createMemo(() => loc?.pathname.startsWith('/edit')) const isNotificationsVisible = createMemo(() => session()?.access_token && !isEditorPage()) const isSaveButtonVisible = createMemo(() => session()?.access_token && isEditorPage()) const isCreatePostButtonVisible = createMemo(() => !isEditorPage()) const isAuthenticatedControlsVisible = createMemo( () => session()?.access_token && session()?.user?.email_verified ) const handleBurgerButtonClick = () => { toggleEditorPanel() } 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) => ( } /> ) }