Skip to content

Commit

Permalink
Added static language button and remove auth buttons
Browse files Browse the repository at this point in the history
Closes #85 and #88
  • Loading branch information
kachar committed Mar 2, 2021
1 parent be128ad commit 613987f
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 4 deletions.
6 changes: 3 additions & 3 deletions src/components/layout/AppNavBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { AppBar, Toolbar, IconButton, Grid, Hidden } from '@material-ui/core'
import { routes } from 'common/routes'
import PodkrepiLogo from 'components/brand/PodkrepiLogo'

import LocaleMenu from './LocaleMenu'
import LocaleButton from './LocaleButton'
import PublicMenu from './nav/PublicMenu'
import PrivateMenu from './nav/PrivateMenu'
import MainNavMenu from './nav/MainNavMenu'
Expand Down Expand Up @@ -94,9 +94,9 @@ export default function AppNavBar({ navMenuToggle }: AppBarDeckProps) {
<Grid item>
<MainNavMenu>
<Grid item>
<LocaleMenu />
<LocaleButton />
</Grid>
{session ? <PrivateMenu /> : <PublicMenu />}
{session ? <PrivateMenu /> : <PublicMenu disableAuth />}
</MainNavMenu>
</Grid>
</Grid>
Expand Down
34 changes: 34 additions & 0 deletions src/components/layout/LocaleButton.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { useCallback } from 'react'
import { useRouter } from 'next/router'
import { Button } from '@material-ui/core'
import { useTranslation } from 'react-i18next'

export default function LocaleMenu() {
const router = useRouter()
const { t } = useTranslation()
const changeLang = useCallback(
(locale: string) => (event: React.MouseEvent) => {
event.preventDefault()
// Same route different language
router.push(router.route, undefined, { locale })
},
[],
)
if (!router.locale) {
return null
}

if (router.locale === 'bg') {
return (
<Button variant="text" size="small" onClick={changeLang('en')}>
{t('EN')}
</Button>
)
}

return (
<Button variant="text" size="small" onClick={changeLang('bg')}>
{t('BG')}
</Button>
)
}
5 changes: 4 additions & 1 deletion src/components/layout/nav/PublicMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,11 @@ import { useTranslation } from 'react-i18next'
import { routes } from 'common/routes'
import LinkButton from 'components/common/LinkButton'

export default function PublicMenu() {
export default function PublicMenu({ disableAuth = false }: { disableAuth?: boolean }) {
const { t } = useTranslation()
if (disableAuth) {
return null
}
return (
<>
<Grid item>
Expand Down

0 comments on commit 613987f

Please sign in to comment.