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) => ( } class={styles.editorControl} /> )} ) } return ( {t('Create post')} {editorMode()} } variant="bordered" popupCssClass={styles.editorPopup} > setEditorMode(t('Preview'))} > {t('Preview')} Посмотрите, как материал будет выглядеть при публикации setEditorMode(t('Editing'))} > {t('Editing')} Изменяйте текст напрямую в редакторе setEditorMode(t('Commenting'))} > {t('Commenting')} Предлагайте правки и комментарии, чтобы сделать материал лучше {renderIconedButton({ value: t('Publish'), icon: 'publish', action: () => publishShout(form), })} {(ref) => ( } variant={'light'} onClick={handleBurgerButtonClick} class={styles.settingsControl} /> )} {t('Create post')} {t('Enter')} {/**/} } > { props.setIsProfilePopupVisible(isVisible) }} containerCssClass={styles.control} trigger={ } /> ) }