Skip to content

Commit

Permalink
fix: incorrect language switch data
Browse files Browse the repository at this point in the history
feat: remove deprecated usage

refactor: remove unused code

chore: release v0.4.1
  • Loading branch information
Dunqing committed Aug 29, 2022
1 parent 30482b5 commit e31ef0c
Show file tree
Hide file tree
Showing 9 changed files with 55 additions and 53 deletions.
2 changes: 1 addition & 1 deletion packages/create-ant-design-pro/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "create-ant-design-pro",
"version": "0.4.0",
"version": "0.4.1",
"packageManager": "[email protected]",
"description": "",
"keywords": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { defaultLangUConfigMap } from './constants'
import { getAllLocales } from './utils'
import React from 'react'
import { Dropdown, Menu } from 'antd'
import { ItemType } from 'antd/lib/menu/hooks/useItems'
import type { CSSProperties } from 'react'
import type { DropDownProps, MenuProps } from 'antd'
import { useLayout } from '@/layouts'
Expand Down Expand Up @@ -70,34 +71,35 @@ export const SelectLang: React.FC<SelectLangProps> = (props) => {
}
)

const allLangUIConfig: LocalData[] =
const allLangUIConfig: ItemType[] = (
postLocalesData?.(defaultLangUConfig) || defaultLangUConfig
).map((item) => {
return {
...item,
key: item.lang,
style: { minWidth: '160px' },
icon: (
<span
role="img"
aria-label={item?.label || 'en-US'}
style={{ marginRight: '8px' }}
>
{item?.icon || '🌐'}
</span>
),
}
})

const handleClick: MenuProps['onClick'] = onItemClick
? (params) => onItemClick(params)
: changeLang

const menuItemStyle = { minWidth: '160px' }
const menuItemIconStyle = { marginRight: '8px' }
const langMenu = (
<Menu selectedKeys={[locale]} onClick={handleClick}>
{allLangUIConfig.map((localeObj) => {
return (
<Menu.Item
key={localeObj.lang || localeObj.key}
style={menuItemStyle}
>
<span
role="img"
aria-label={localeObj?.label || 'en-US'}
style={menuItemIconStyle}
>
{localeObj?.icon || '🌐'}
</span>
{localeObj?.label || 'en-US'}
</Menu.Item>
)
})}
</Menu>
<Menu
selectedKeys={[locale]}
items={allLangUIConfig}
onClick={handleClick}
></Menu>
)

const inlineStyle = {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { defaultLangUConfigMap } from './constants'

export const getAllLocales = () => {
return Object.keys(import.meta.glob('../../*.ts')).map((key) =>
key.replace('../../', '').replace('.ts', '')
return Object.keys(import.meta.glob('../../locales/*.ts')).map((key) =>
key.replace('../../locales/', '').replace('.ts', '')
) as (keyof typeof defaultLangUConfigMap)[]
}
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ const Login: React.FC = () => {
})
message.success(defaultLoginSuccessMessage)
/** 此方法会跳转到 redirect 参数所在的位置 */
if (!history) return
const query = new URLSearchParams(location.search)
const redirect = query.get('redirect')
navigate(redirect || '/')
Expand Down
2 changes: 1 addition & 1 deletion packages/layout/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ant-design-pro-layout",
"version": "0.4.0",
"version": "0.4.1",
"packageManager": "[email protected]",
"description": "",
"keywords": [],
Expand Down
2 changes: 1 addition & 1 deletion packages/vite-plugin-antd-layout/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "vite-plugin-antd-layout",
"version": "0.4.0",
"version": "0.4.1",
"packageManager": "[email protected]",
"description": "",
"keywords": [],
Expand Down
46 changes: 24 additions & 22 deletions playground/src/components/SelectLang/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { defaultLangUConfigMap } from './constants'
import { getAllLocales } from './utils'
import React from 'react'
import { Dropdown, Menu } from 'antd'
import { ItemType } from 'antd/lib/menu/hooks/useItems'
import type { CSSProperties } from 'react'
import type { DropDownProps, MenuProps } from 'antd'
import { useLayout } from '@/layouts'
Expand Down Expand Up @@ -70,34 +71,35 @@ export const SelectLang: React.FC<SelectLangProps> = (props) => {
}
)

const allLangUIConfig: LocalData[] =
const allLangUIConfig: ItemType[] = (
postLocalesData?.(defaultLangUConfig) || defaultLangUConfig
).map((item) => {
return {
...item,
key: item.lang,
style: { minWidth: '160px' },
icon: (
<span
role="img"
aria-label={item?.label || 'en-US'}
style={{ marginRight: '8px' }}
>
{item?.icon || '🌐'}
</span>
),
}
})

const handleClick: MenuProps['onClick'] = onItemClick
? (params) => onItemClick(params)
: changeLang

const menuItemStyle = { minWidth: '160px' }
const menuItemIconStyle = { marginRight: '8px' }
const langMenu = (
<Menu selectedKeys={[locale]} onClick={handleClick}>
{allLangUIConfig.map((localeObj) => {
return (
<Menu.Item
key={localeObj.lang || localeObj.key}
style={menuItemStyle}
>
<span
role="img"
aria-label={localeObj?.label || 'en-US'}
style={menuItemIconStyle}
>
{localeObj?.icon || '🌐'}
</span>
{localeObj?.label || 'en-US'}
</Menu.Item>
)
})}
</Menu>
<Menu
selectedKeys={[locale]}
items={allLangUIConfig}
onClick={handleClick}
></Menu>
)

const inlineStyle = {
Expand Down
4 changes: 2 additions & 2 deletions playground/src/components/SelectLang/utils.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { defaultLangUConfigMap } from './constants'

export const getAllLocales = () => {
return Object.keys(import.meta.glob('../../*.ts')).map((key) =>
key.replace('../../', '').replace('.ts', '')
return Object.keys(import.meta.glob('../../locales/*.ts')).map((key) =>
key.replace('../../locales/', '').replace('.ts', '')
) as (keyof typeof defaultLangUConfigMap)[]
}
1 change: 0 additions & 1 deletion playground/src/pages/user/Login/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ const Login: React.FC = () => {
})
message.success(defaultLoginSuccessMessage)
/** 此方法会跳转到 redirect 参数所在的位置 */
if (!history) return
const query = new URLSearchParams(location.search)
const redirect = query.get('redirect')
navigate(redirect || '/')
Expand Down

1 comment on commit e31ef0c

@vercel
Copy link

@vercel vercel bot commented on e31ef0c Aug 29, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.