Skip to content

Commit

Permalink
fix(panel): hide dicts when the selection lang does not match
Browse files Browse the repository at this point in the history
  • Loading branch information
crimx committed May 25, 2018
1 parent 21d32d1 commit b099b5f
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 8 deletions.
4 changes: 2 additions & 2 deletions src/content/components/DictPanel/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ export default class DictPanel extends React.Component<DictPanelProps> {

const {
dicts: dictsInfo,
selected: selectedDicts,
active: activeDicts,
} = dictionaries

// wrap iframe into DictPanel so that react
Expand All @@ -105,7 +105,7 @@ export default class DictPanel extends React.Component<DictPanelProps> {
closePanel,
})}
<div className={`panel-DictContainer${isAnimation ? ' isAnimate' : ''}`}>
{selectedDicts.map(id => React.createElement(DictItem, {
{activeDicts.map(id => React.createElement(DictItem, {
key: id,
id,
text: (dictionaries.searchHistory[0] || selection.selectionInfo).text,
Expand Down
22 changes: 17 additions & 5 deletions src/content/redux/modules/dictionaries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ interface DictionariesPayload {
[ActionType.SEARCH_START]: {
toOnhold: DictID[]
toStart: DictID[]
toActive?: DictID[]
info: SelectionInfo
}
[ActionType.SEARCH_END]: {
Expand Down Expand Up @@ -63,6 +64,7 @@ type DictState = {
export type DictionariesState = {
readonly dictionaries: {
readonly selected: AppConfig['dicts']['selected']
readonly active: DictID[]
readonly dicts: {
readonly [k in DictID]?: DictState
}
Expand All @@ -75,6 +77,7 @@ const initConfig = appConfigFactory()
export const initState: DictionariesState = {
dictionaries: {
selected: initConfig.dicts.selected,
active: [],
dicts: initConfig.dicts.selected
.reduce((state, id) => {
state[id] = {
Expand Down Expand Up @@ -109,6 +112,7 @@ export const reducer: DictsReducer = {
dictionaries: {
...dictionaries,
selected,
active: [],
dicts: selected.reduce((newState, id) => {
newState[id] = dictionaries.dicts[id] || {
searchStatus: SearchStatus.OnHold,
Expand Down Expand Up @@ -138,7 +142,7 @@ export const reducer: DictsReducer = {
}
}
},
[ActionType.SEARCH_START] (state, { toStart, toOnhold, info }) {
[ActionType.SEARCH_START] (state, { toStart, toOnhold, toActive, info }) {
const { dictionaries } = state
const history = dictionaries.searchHistory

Expand Down Expand Up @@ -166,6 +170,7 @@ export const reducer: DictsReducer = {
...state,
dictionaries: {
...dictionaries,
active: toActive || dictionaries.active,
// don't create history for same info
searchHistory: info === history[0]
? history
Expand Down Expand Up @@ -295,19 +300,26 @@ export function searchText (arg?: { id?: DictID, info?: SelectionInfo }): Dispat
const { selected: selectedDicts, all: allDicts } = state.config.dicts
const toStart: DictID[] = []
const toOnhold: DictID[] = []
const toActive: DictID[] = []

selectedDicts.forEach(id => {
if (
!allDicts[id].defaultUnfold ||
const isInvalidLang = (
(!allDicts[id].selectionLang.chs && isContainChinese(info.text)) ||
(!allDicts[id].selectionLang.eng && isContainEnglish(info.text))
) {
)

if (!isInvalidLang) {
toActive.push(id)
}

if (!allDicts[id].defaultUnfold || isInvalidLang) {
toOnhold.push(id)
} else {
toStart.push(id)
}
})

dispatch(searchStart({ toStart, toOnhold, info }))
dispatch(searchStart({ toStart, toOnhold, toActive, info }))
toStart.forEach(doSearch)

if (!isSaladictInternalPage &&
Expand Down
2 changes: 1 addition & 1 deletion src/content/redux/modules/widget.ts
Original file line number Diff line number Diff line change
Expand Up @@ -485,7 +485,7 @@ export function updateItemHeight (id: DictID, height: number): DispatcherThunk {
const winHeight = window.innerHeight
const newHeight = Math.min(
winHeight * state.config.panelMaxHeightRatio,
30 + state.config.dicts.selected
30 + state.dictionaries.active
.reduce((sum, id) => sum + (dictHeights[id] || 30), 0),
)

Expand Down

0 comments on commit b099b5f

Please sign in to comment.