Skip to content

Commit

Permalink
feat(panel): open url base on lang code
Browse files Browse the repository at this point in the history
  • Loading branch information
crimx committed May 27, 2018
1 parent be329bd commit efb5187
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 22 deletions.
15 changes: 8 additions & 7 deletions src/app-config/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { getALlDicts } from './dicts'
import { getAllContextMenus } from './context-menus'

const langUI = (browser.i18n.getUILanguage() || 'en')
const langCode = /^zh-CN|zh-TW|en$/.test(langUI)
const langCode: any = /^zh-CN|zh-TW|en$/.test(langUI)
? langUI === 'zh-HK'
? 'zh-TW'
: langUI
Expand Down Expand Up @@ -45,7 +45,7 @@ export interface AppConfigMutable {
animation: boolean

/** language code for locales */
langCode: string
langCode: 'en' | 'zh-CN' | 'zh-TW'

/** panel width */
panelWidth: number
Expand Down Expand Up @@ -208,14 +208,15 @@ export function appConfigFactory (): AppConfig {
dict: '',
list: [
'bing',
'youdao',
'macmillan',
'longman',
'cambridge',
'cobuild',
'websterlearner',
'eudic',
'longman',
'macmillan',
'oald',
'urban',
'eudic',
'websterlearner',
'youdao',
],
accent: 'uk' as ('us' | 'uk')
}
Expand Down
37 changes: 23 additions & 14 deletions src/content/components/DictPanel/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export interface DictPanelProps extends DictPanelDispatchers {
readonly isPinned: boolean
readonly dictionaries: DictionariesState['dictionaries']
readonly allDictsConfig: DictConfigs
readonly langCode: AppConfig['langCode']
readonly fontSize: number
readonly panelWidth: number
readonly isAnimation: boolean
Expand Down Expand Up @@ -57,6 +58,7 @@ export default class DictPanel extends React.Component<DictPanelProps> {
const {
isFav,
isPinned,
langCode,
handleDragAreaMouseDown,
handleDragAreaTouchStart,
searchText,
Expand Down Expand Up @@ -105,20 +107,27 @@ export default class DictPanel extends React.Component<DictPanelProps> {
closePanel,
})}
<div className={`panel-DictContainer${isAnimation ? ' isAnimate' : ''}`}>
{activeDicts.map(id => React.createElement(DictItem, {
key: id,
id,
text: (dictionaries.searchHistory[0] || selection.selectionInfo).text,
dictURL: allDictsConfig[id].page,
fontSize,
preferredHeight: allDictsConfig[id].preferredHeight,
panelWidth,
isAnimation,
searchStatus: (dictsInfo[id] as any).searchStatus,
searchResult: (dictsInfo[id] as any).searchResult,
searchText,
updateItemHeight,
}))}
{activeDicts.map(id => {
let dictURL = allDictsConfig[id].page
if (typeof dictURL !== 'string') {
dictURL = dictURL[langCode] || dictURL.en
}

return React.createElement(DictItem, {
key: id,
id,
text: (dictionaries.searchHistory[0] || selection.selectionInfo).text,
dictURL,
fontSize,
preferredHeight: allDictsConfig[id].preferredHeight,
panelWidth,
isAnimation,
searchStatus: (dictsInfo[id] as any).searchStatus,
searchResult: (dictsInfo[id] as any).searchResult,
searchText,
updateItemHeight,
})
})}
</div>
</PortalFrame>
)
Expand Down
3 changes: 2 additions & 1 deletion src/content/components/DictPanelPortal/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { Spring } from 'react-spring'
import DictPanel, { DictPanelDispatchers, DictPanelProps } from '../DictPanel'
import { MsgSelection } from '@/typings/message'
import { Omit } from '@/typings/helpers'
import { DictID, DictConfigs } from '@/app-config'
import { AppConfig, DictID, DictConfigs } from '@/app-config'

const isSaladictPopupPage = !!window.__SALADICT_POPUP_PAGE__

Expand All @@ -19,6 +19,7 @@ export interface DictPanelPortalProps extends DictPanelPortalDispatchers {
readonly isAnimation: boolean
readonly allDictsConfig: DictConfigs
readonly fontSize: number
readonly langCode: AppConfig['langCode']

readonly isFav: boolean
readonly isPinned: boolean
Expand Down
1 change: 1 addition & 0 deletions src/content/containers/DictPanelContainer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ export const mapStateToProps = ({
isAnimation: config.animation,
allDictsConfig: config.dicts.all,
fontSize: config.fontSize,
langCode: config.langCode,

selection,

Expand Down

0 comments on commit efb5187

Please sign in to comment.