2022-11-13 19:35:57 +00:00
|
|
|
import styles from './Header.module.scss'
|
|
|
|
import { clsx } from 'clsx'
|
2023-03-23 17:15:50 +00:00
|
|
|
import { router, useRouter } from '../../stores/router'
|
2023-02-17 09:21:02 +00:00
|
|
|
|
2022-11-14 17:41:05 +00:00
|
|
|
import { Icon } from '../_shared/Icon'
|
2023-04-20 13:58:56 +00:00
|
|
|
import { createMemo, createSignal, Show } from 'solid-js'
|
2022-11-13 19:35:57 +00:00
|
|
|
import Notifications from './Notifications'
|
|
|
|
import { ProfilePopup } from './ProfilePopup'
|
|
|
|
import Userpic from '../Author/Userpic'
|
|
|
|
import { showModal, useWarningsStore } from '../../stores/ui'
|
2022-11-15 16:16:31 +00:00
|
|
|
import { ShowOnlyOnClient } from '../_shared/ShowOnlyOnClient'
|
2022-11-14 10:02:08 +00:00
|
|
|
import { useSession } from '../../context/session'
|
2023-02-17 09:21:02 +00:00
|
|
|
import { useLocalize } from '../../context/localize'
|
2023-03-23 17:15:50 +00:00
|
|
|
import { getPagePath } from '@nanostores/router'
|
2023-04-05 21:51:01 +00:00
|
|
|
import { Button } from '../_shared/Button'
|
2023-05-01 18:32:32 +00:00
|
|
|
// import { useEditorContext } from '../../context/editor'
|
2022-11-13 19:35:57 +00:00
|
|
|
|
|
|
|
type HeaderAuthProps = {
|
|
|
|
setIsProfilePopupVisible: (value: boolean) => void
|
|
|
|
}
|
|
|
|
|
|
|
|
export const HeaderAuth = (props: HeaderAuthProps) => {
|
2023-02-17 09:21:02 +00:00
|
|
|
const { t } = useLocalize()
|
2022-11-13 19:35:57 +00:00
|
|
|
const { page } = useRouter()
|
|
|
|
const [visibleWarnings, setVisibleWarnings] = createSignal(false)
|
|
|
|
const { warnings } = useWarningsStore()
|
|
|
|
|
2022-12-06 16:03:55 +00:00
|
|
|
const { session, isSessionLoaded, isAuthenticated } = useSession()
|
2022-11-13 19:35:57 +00:00
|
|
|
|
2023-05-01 18:32:32 +00:00
|
|
|
// const {
|
|
|
|
// actions: { toggleEditorPanel }
|
|
|
|
// } = useEditorContext()
|
2023-04-26 02:37:29 +00:00
|
|
|
|
2022-11-13 19:35:57 +00:00
|
|
|
const toggleWarnings = () => setVisibleWarnings(!visibleWarnings())
|
|
|
|
|
|
|
|
const handleBellIconClick = (event: Event) => {
|
|
|
|
event.preventDefault()
|
|
|
|
|
|
|
|
if (!isAuthenticated()) {
|
|
|
|
showModal('auth')
|
|
|
|
return
|
|
|
|
}
|
|
|
|
toggleWarnings()
|
|
|
|
}
|
|
|
|
|
2023-04-20 13:58:56 +00:00
|
|
|
const isEditorPage = createMemo(() => page().route === 'create' || page().route === 'edit')
|
|
|
|
|
|
|
|
const showNotifications = createMemo(() => isAuthenticated() && !isEditorPage())
|
|
|
|
const showSaveButton = createMemo(() => isAuthenticated() && isEditorPage())
|
|
|
|
const showCreatePostButton = createMemo(() => isAuthenticated() && !isEditorPage())
|
|
|
|
|
2023-05-01 18:32:32 +00:00
|
|
|
// eslint-disable-next-line unicorn/consistent-function-scoping
|
|
|
|
const handleBurgerButtonClick = () => {
|
|
|
|
// TODO: implement me
|
|
|
|
console.log('Burger clicked')
|
|
|
|
}
|
|
|
|
|
2022-11-13 19:35:57 +00:00
|
|
|
return (
|
2022-11-15 16:16:31 +00:00
|
|
|
<ShowOnlyOnClient>
|
2023-02-17 09:21:02 +00:00
|
|
|
<Show when={isSessionLoaded()} keyed={true}>
|
2023-03-10 17:42:48 +00:00
|
|
|
<div class={clsx(styles.usernav, 'col')}>
|
2022-11-13 19:35:57 +00:00
|
|
|
<div class={clsx(styles.userControl, styles.userControl, 'col')}>
|
2023-04-20 13:58:56 +00:00
|
|
|
<Show when={showCreatePostButton()}>
|
2023-03-23 17:15:50 +00:00
|
|
|
<div class={clsx(styles.userControlItem, styles.userControlItemVerbose)}>
|
|
|
|
<a href={getPagePath(router, 'create')}>
|
|
|
|
<span class={styles.textLabel}>{t('Create post')}</span>
|
|
|
|
<Icon name="pencil" class={styles.icon} />
|
|
|
|
</a>
|
|
|
|
</div>
|
|
|
|
</Show>
|
2022-11-13 19:35:57 +00:00
|
|
|
|
2023-04-20 13:58:56 +00:00
|
|
|
<Show when={showNotifications()}>
|
2022-11-13 19:35:57 +00:00
|
|
|
<div class={styles.userControlItem}>
|
|
|
|
<a href="#" onClick={handleBellIconClick}>
|
|
|
|
<div>
|
|
|
|
<Icon name="bell-white" counter={isAuthenticated() ? warnings().length : 1} />
|
|
|
|
</div>
|
|
|
|
</a>
|
|
|
|
</div>
|
|
|
|
</Show>
|
|
|
|
|
2023-04-20 13:58:56 +00:00
|
|
|
<Show when={showSaveButton()}>
|
2023-04-05 21:51:01 +00:00
|
|
|
<div class={clsx(styles.userControlItem, styles.userControlItemVerbose)}>
|
2023-04-12 20:32:38 +00:00
|
|
|
<Button
|
|
|
|
value={
|
|
|
|
<>
|
|
|
|
<span class={styles.textLabel}>{t('Save')}</span>
|
|
|
|
<Icon name="save" class={styles.icon} />
|
|
|
|
</>
|
|
|
|
}
|
|
|
|
variant={'outline'}
|
|
|
|
/>
|
2023-04-05 21:51:01 +00:00
|
|
|
</div>
|
|
|
|
|
|
|
|
<div class={clsx(styles.userControlItem, styles.userControlItemVerbose)}>
|
2023-04-12 20:32:38 +00:00
|
|
|
<Button
|
|
|
|
value={
|
|
|
|
<>
|
|
|
|
<span class={styles.textLabel}>{t('Publish')}</span>
|
|
|
|
<Icon name="publish" class={styles.icon} />
|
|
|
|
</>
|
|
|
|
}
|
|
|
|
variant={'outline'}
|
|
|
|
/>
|
2023-04-05 21:51:01 +00:00
|
|
|
</div>
|
2023-04-06 21:40:34 +00:00
|
|
|
|
|
|
|
<div class={clsx(styles.userControlItem, styles.userControlItemVerbose)}>
|
2023-05-01 18:32:32 +00:00
|
|
|
<Button
|
|
|
|
value={<Icon name="burger" />}
|
|
|
|
variant={'outline'}
|
|
|
|
onClick={handleBurgerButtonClick}
|
|
|
|
/>
|
2023-04-06 21:40:34 +00:00
|
|
|
</div>
|
2023-04-05 21:51:01 +00:00
|
|
|
</Show>
|
|
|
|
|
2022-11-13 19:35:57 +00:00
|
|
|
<Show when={visibleWarnings()}>
|
|
|
|
<div class={clsx(styles.userControlItem, 'notifications')}>
|
|
|
|
<Notifications />
|
|
|
|
</div>
|
|
|
|
</Show>
|
|
|
|
|
|
|
|
<Show
|
2023-04-05 21:51:01 +00:00
|
|
|
when={isAuthenticated() && page().route !== 'create'}
|
2022-11-13 19:35:57 +00:00
|
|
|
fallback={
|
|
|
|
<div class={clsx(styles.userControlItem, styles.userControlItemVerbose, 'loginbtn')}>
|
2022-11-15 16:16:31 +00:00
|
|
|
<a href="?modal=auth&mode=login">
|
2022-11-13 19:35:57 +00:00
|
|
|
<span class={styles.textLabel}>{t('Enter')}</span>
|
2022-11-26 16:51:08 +00:00
|
|
|
<Icon name="user-default" class={styles.icon} />
|
2022-11-13 19:35:57 +00:00
|
|
|
</a>
|
|
|
|
</div>
|
|
|
|
}
|
|
|
|
>
|
|
|
|
<div class={clsx(styles.userControlItem, styles.userControlItemInbox)}>
|
|
|
|
<a href="/inbox">
|
|
|
|
{/*FIXME: replace with route*/}
|
|
|
|
<div classList={{ entered: page().path === '/inbox' }}>
|
|
|
|
<Icon name="inbox-white" counter={session()?.news?.unread || 0} />
|
|
|
|
</div>
|
|
|
|
</a>
|
|
|
|
</div>
|
|
|
|
<ProfilePopup
|
|
|
|
onVisibilityChange={(isVisible) => {
|
|
|
|
props.setIsProfilePopupVisible(isVisible)
|
|
|
|
}}
|
|
|
|
containerCssClass={styles.control}
|
|
|
|
trigger={
|
|
|
|
<div class={styles.userControlItem}>
|
|
|
|
<button class={styles.button}>
|
|
|
|
<div classList={{ entered: page().path === `/${session().user?.slug}` }}>
|
2023-04-20 13:58:56 +00:00
|
|
|
<Userpic user={session().user} class={styles.userpic} />
|
2022-11-13 19:35:57 +00:00
|
|
|
</div>
|
|
|
|
</button>
|
|
|
|
</div>
|
|
|
|
}
|
|
|
|
/>
|
|
|
|
</Show>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</Show>
|
2022-11-15 16:16:31 +00:00
|
|
|
</ShowOnlyOnClient>
|
2022-11-13 19:35:57 +00:00
|
|
|
)
|
|
|
|
}
|