Skip to content

Commit

Permalink
fix: no auth locale list
Browse files Browse the repository at this point in the history
  • Loading branch information
Ponchimeow committed Oct 14, 2024
1 parent 745c46b commit 0d05386
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 31 deletions.
49 changes: 49 additions & 0 deletions src/components/common/LocaleCollapse.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import { ChevronDownIcon, ChevronRightIcon } from '@chakra-ui/icons'
import React, { useContext } from 'react'
import { Box, useDisclosure, Collapse } from '@chakra-ui/react'
import { List } from 'antd'
import styled from 'styled-components'
import LocaleContext, { SUPPORTED_LOCALES } from '../../contexts/LocaleContext'

const StyledCollapseIconWrapper = styled(Box)`
&& {
margin: auto 0;
}
`
const BlankIcon = styled.i`
display: inline-block;
width: 16px;
height: 16px;
`

const LocaleCollapse: React.FC = () => {
const { isOpen, onToggle } = useDisclosure()
const { currentLocale, setCurrentLocale } = useContext(LocaleContext)
return (
<>
<Box d="flex" justifyContent="space-between" cursor="pointer" onClick={onToggle}>
<Box>
<List.Item style={{ cursor: 'pointer' }}>
<BlankIcon className="mr-2" />
{SUPPORTED_LOCALES.find(supportedLocale => supportedLocale.locale === currentLocale)?.label}
</List.Item>
</Box>
<StyledCollapseIconWrapper>
{isOpen ? <ChevronDownIcon w="16px" /> : <ChevronRightIcon w="16px" />}
</StyledCollapseIconWrapper>
</Box>
<Collapse in={isOpen} animateOpacity style={{ background: '#f7f8f8', margin: '0 -12px' }}>
{SUPPORTED_LOCALES.filter(v => v.locale !== currentLocale).map(v => (
<Box ml="3rem" style={{ cursor: 'pointer' }}>
<List.Item key={v.locale} onClick={() => setCurrentLocale?.(v.locale)}>
<BlankIcon className="mr-2" />
{v.label}
</List.Item>
</Box>
))}
</Collapse>
</>
)
}

export default LocaleCollapse
32 changes: 1 addition & 31 deletions src/components/common/MemberProfileButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@ import { useIntl } from 'react-intl'
import { Link, useHistory } from 'react-router-dom'
import styled from 'styled-components'
import { useCustomRenderer } from '../../contexts/CustomRendererContext'
import LocaleContext, { SUPPORTED_LOCALES } from '../../contexts/LocaleContext'
import PodcastPlayerContext from '../../contexts/PodcastPlayerContext'
import { commonMessages } from '../../helpers/translation'
import { useNav } from '../../hooks/data'
import { PlusIcon } from '../../images/index'
import { AuthModalContext } from '../auth/AuthModal'
import { MemberAdminMenu } from './AdminMenu'
import GlobalSearchInput from './GlobalSearchInput'
import LocaleCollapse from './LocaleCollapse'
import MemberAvatar from './MemberAvatar'
import Responsive from './Responsive'

Expand Down Expand Up @@ -160,36 +160,6 @@ const DefaultLogout: React.VFC<{ onClick?: React.MouseEventHandler<HTMLDivElemen
)
}

const LocaleCollapse: React.FC = () => {
const { isOpen, onToggle } = useDisclosure()
const { currentLocale, setCurrentLocale } = useContext(LocaleContext)
return (
<>
<Box d="flex" justifyContent="space-between" cursor="pointer" onClick={onToggle}>
<Box>
<List.Item style={{ cursor: 'pointer' }}>
<BlankIcon className="mr-2" />
{SUPPORTED_LOCALES.find(supportedLocale => supportedLocale.locale === currentLocale)?.label}
</List.Item>
</Box>
<StyledCollapseIconWrapper>
{isOpen ? <ChevronDownIcon w="16px" /> : <ChevronRightIcon w="16px" />}
</StyledCollapseIconWrapper>
</Box>
<Collapse in={isOpen} animateOpacity style={{ background: '#f7f8f8', margin: '0 -12px' }}>
{SUPPORTED_LOCALES.filter(v => v.locale !== currentLocale).map(v => (
<Box ml="3rem" style={{ cursor: 'pointer' }}>
<List.Item key={v.locale} onClick={() => setCurrentLocale?.(v.locale)}>
<BlankIcon className="mr-2" />
{v.label}
</List.Item>
</Box>
))}
</Collapse>
</>
)
}

const MemberProfileButton: React.VFC<{
id: string
name: string
Expand Down
4 changes: 4 additions & 0 deletions src/containers/common/AuthButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,16 @@ import { Button, Popover } from 'antd'
import React, { useContext } from 'react'
import { useIntl } from 'react-intl'
import { AuthModalContext } from '../../components/auth/AuthModal'
import LocaleCollapse from '../../components/common/LocaleCollapse'
import { CustomNavLinks, StyledList, Wrapper } from '../../components/common/MemberProfileButton'
import Responsive from '../../components/common/Responsive'
import { useCustomRenderer } from '../../contexts/CustomRendererContext'
import { commonMessages } from '../../helpers/translation'
import { useAuthModal } from '../../hooks/auth'
import { useApp } from 'lodestar-app-element/src/contexts/AppContext'

const AuthButton: React.VFC = () => {
const { enabledModules } = useApp()
const { formatMessage } = useIntl()
const { renderAuthButton } = useCustomRenderer()
const { setVisible } = useContext(AuthModalContext)
Expand All @@ -35,6 +38,7 @@ const AuthButton: React.VFC = () => {
<Wrapper>
<StyledList split={false}>
<CustomNavLinks />
{enabledModules.locale ? <LocaleCollapse /> : null}
</StyledList>
</Wrapper>
}
Expand Down

0 comments on commit 0d05386

Please sign in to comment.