Feature/toggle mobile header (#281)
- toggle language - toggle menu on current link
This commit is contained in:
parent
ea1de20466
commit
b85c05a8c3
|
@ -12,7 +12,7 @@ import { Icon } from '../../_shared/Icon'
|
||||||
import type { Topic } from '../../../graphql/types.gen'
|
import type { Topic } from '../../../graphql/types.gen'
|
||||||
|
|
||||||
import { useModalStore } from '../../../stores/ui'
|
import { useModalStore } from '../../../stores/ui'
|
||||||
import { router, useRouter } from '../../../stores/router'
|
import { router, ROUTES, useRouter } from '../../../stores/router'
|
||||||
|
|
||||||
import { getDescription } from '../../../utils/meta'
|
import { getDescription } from '../../../utils/meta'
|
||||||
|
|
||||||
|
@ -38,11 +38,14 @@ type HeaderSearchParams = {
|
||||||
source?: string
|
source?: string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const handleSwitchLanguage = (event) => {
|
||||||
|
location.href = `${location.href}${location.href.includes('?') ? '&' : '?'}lng=${event.target.value}`
|
||||||
|
}
|
||||||
|
|
||||||
export const Header = (props: Props) => {
|
export const Header = (props: Props) => {
|
||||||
const { t, lang } = useLocalize()
|
const { t, lang } = useLocalize()
|
||||||
|
|
||||||
const { modal } = useModalStore()
|
const { modal } = useModalStore()
|
||||||
|
const { page } = useRouter()
|
||||||
const {
|
const {
|
||||||
actions: { requireAuthentication }
|
actions: { requireAuthentication }
|
||||||
} = useSession()
|
} = useSession()
|
||||||
|
@ -59,7 +62,6 @@ export const Header = (props: Props) => {
|
||||||
const [isTopicsVisible, setIsTopicsVisible] = createSignal(false)
|
const [isTopicsVisible, setIsTopicsVisible] = createSignal(false)
|
||||||
const [isZineVisible, setIsZineVisible] = createSignal(false)
|
const [isZineVisible, setIsZineVisible] = createSignal(false)
|
||||||
const [isFeedVisible, setIsFeedVisible] = createSignal(false)
|
const [isFeedVisible, setIsFeedVisible] = createSignal(false)
|
||||||
|
|
||||||
const toggleFixed = () => setFixed((oldFixed) => !oldFixed)
|
const toggleFixed = () => setFixed((oldFixed) => !oldFixed)
|
||||||
|
|
||||||
const tag = (topic: Topic) =>
|
const tag = (topic: Topic) =>
|
||||||
|
@ -148,6 +150,15 @@ export const Header = (props: Props) => {
|
||||||
setRandomTopics(topics)
|
setRandomTopics(topics)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
const handleToggleMenuByLink = (event: MouseEvent, route: keyof typeof ROUTES) => {
|
||||||
|
if (!fixed()) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
event.preventDefault()
|
||||||
|
if (page().route === route) {
|
||||||
|
toggleFixed()
|
||||||
|
}
|
||||||
|
}
|
||||||
return (
|
return (
|
||||||
<header
|
<header
|
||||||
class={styles.mainHeader}
|
class={styles.mainHeader}
|
||||||
|
@ -196,6 +207,7 @@ export const Header = (props: Props) => {
|
||||||
routeName="home"
|
routeName="home"
|
||||||
active={isZineVisible()}
|
active={isZineVisible()}
|
||||||
body={t('journal')}
|
body={t('journal')}
|
||||||
|
onClick={(event) => handleToggleMenuByLink(event, 'home')}
|
||||||
/>
|
/>
|
||||||
<Link
|
<Link
|
||||||
onMouseOver={() => toggleSubnavigation(true, setIsFeedVisible)}
|
onMouseOver={() => toggleSubnavigation(true, setIsFeedVisible)}
|
||||||
|
@ -203,6 +215,7 @@ export const Header = (props: Props) => {
|
||||||
routeName="feed"
|
routeName="feed"
|
||||||
active={isFeedVisible()}
|
active={isFeedVisible()}
|
||||||
body={t('feed')}
|
body={t('feed')}
|
||||||
|
onClick={(event) => handleToggleMenuByLink(event, 'feed')}
|
||||||
/>
|
/>
|
||||||
<Link
|
<Link
|
||||||
onMouseOver={() => toggleSubnavigation(true, setIsTopicsVisible)}
|
onMouseOver={() => toggleSubnavigation(true, setIsTopicsVisible)}
|
||||||
|
@ -210,12 +223,14 @@ export const Header = (props: Props) => {
|
||||||
routeName="topics"
|
routeName="topics"
|
||||||
active={isTopicsVisible()}
|
active={isTopicsVisible()}
|
||||||
body={t('topics')}
|
body={t('topics')}
|
||||||
|
onClick={(event) => handleToggleMenuByLink(event, 'topics')}
|
||||||
/>
|
/>
|
||||||
<Link
|
<Link
|
||||||
onMouseOver={(event) => hideSubnavigation(event, 0)}
|
onMouseOver={(event) => hideSubnavigation(event, 0)}
|
||||||
onMouseOut={(event) => hideSubnavigation(event, 0)}
|
onMouseOut={(event) => hideSubnavigation(event, 0)}
|
||||||
routeName="authors"
|
routeName="authors"
|
||||||
body={t('authors')}
|
body={t('authors')}
|
||||||
|
onClick={(event) => handleToggleMenuByLink(event, 'authors')}
|
||||||
/>
|
/>
|
||||||
<Link
|
<Link
|
||||||
onMouseOver={() => toggleSubnavigation(true, setIsKnowledgeBaseVisible)}
|
onMouseOver={() => toggleSubnavigation(true, setIsKnowledgeBaseVisible)}
|
||||||
|
@ -223,6 +238,7 @@ export const Header = (props: Props) => {
|
||||||
routeName="guide"
|
routeName="guide"
|
||||||
body={t('Knowledge base')}
|
body={t('Knowledge base')}
|
||||||
active={isKnowledgeBaseVisible()}
|
active={isKnowledgeBaseVisible()}
|
||||||
|
onClick={(event) => handleToggleMenuByLink(event, 'guide')}
|
||||||
/>
|
/>
|
||||||
</ul>
|
</ul>
|
||||||
|
|
||||||
|
@ -283,8 +299,12 @@ export const Header = (props: Props) => {
|
||||||
<h4>{t('Newsletter')}</h4>
|
<h4>{t('Newsletter')}</h4>
|
||||||
<Subscribe variant={'mobileSubscription'} />
|
<Subscribe variant={'mobileSubscription'} />
|
||||||
|
|
||||||
<h4>{t('Newsletter')}</h4>
|
<h4>{t('Language')}</h4>
|
||||||
<select class={styles.languageSelectorMobile}>
|
<select
|
||||||
|
class={styles.languageSelectorMobile}
|
||||||
|
onChange={handleSwitchLanguage}
|
||||||
|
value={lang()}
|
||||||
|
>
|
||||||
<option value="ru">🇷🇺 Русский</option>
|
<option value="ru">🇷🇺 Русский</option>
|
||||||
<option value="en">🇬🇧 English</option>
|
<option value="en">🇬🇧 English</option>
|
||||||
</select>
|
</select>
|
||||||
|
|
|
@ -10,13 +10,17 @@ type Props = {
|
||||||
routeName?: keyof typeof ROUTES
|
routeName?: keyof typeof ROUTES
|
||||||
body: string
|
body: string
|
||||||
active?: boolean
|
active?: boolean
|
||||||
|
onClick?: (event: MouseEvent) => void
|
||||||
}
|
}
|
||||||
|
|
||||||
export const Link = (props: Props) => {
|
export const Link = (props: Props) => {
|
||||||
const { page } = useRouter()
|
const { page } = useRouter()
|
||||||
const isSelected = page().route === props.routeName
|
const isSelected = page().route === props.routeName
|
||||||
return (
|
return (
|
||||||
<li classList={{ 'view-switcher__item--selected': page().route === props.routeName }}>
|
<li
|
||||||
|
onClick={props.onClick}
|
||||||
|
classList={{ 'view-switcher__item--selected': page().route === props.routeName }}
|
||||||
|
>
|
||||||
<ConditionalWrapper
|
<ConditionalWrapper
|
||||||
condition={!isSelected && Boolean(props.routeName)}
|
condition={!isSelected && Boolean(props.routeName)}
|
||||||
wrapper={(children) => <a href={getPagePath(router, props.routeName)}>{children}</a>}
|
wrapper={(children) => <a href={getPagePath(router, props.routeName)}>{children}</a>}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user