Skip to content

Commit

Permalink
refactor(panel): add mta box hiding
Browse files Browse the repository at this point in the history
  • Loading branch information
crimx committed Oct 30, 2020
1 parent 1922c09 commit 77e30f9
Show file tree
Hide file tree
Showing 10 changed files with 36 additions and 22 deletions.
3 changes: 2 additions & 1 deletion src/_locales/en/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,8 @@ export const locale: typeof _locale = {
always: 'Keep Unfolding',
never: 'Never Unfold',
once: 'Unfold Once',
popup: 'Only On Browser Action'
popup: 'Only On Browser Action',
hide: 'Hide'
},
dict_selected: 'Selected Dicts'
}
Expand Down
3 changes: 2 additions & 1 deletion src/_locales/zh-CN/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,8 @@ export const locale = {
always: '保持展开',
never: '从不展开',
once: '展开一次',
popup: '只在右上弹框展开'
popup: '只在右上弹框展开',
hide: '隐藏'
},
dict_selected: '已选词典'
}
Expand Down
3 changes: 2 additions & 1 deletion src/_locales/zh-TW/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,8 @@ export const locale: typeof _locale = {
always: '保持展開',
never: '永遠不展開',
once: '展開一次',
popup: '只在右上彈框展開'
popup: '只在右上彈框展開',
hide: '隱藏'
},
dict_selected: '已選字典'
}
Expand Down
2 changes: 1 addition & 1 deletion src/app-config/profiles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { DeepReadonly } from '@/typings/helpers'
import { genUniqueKey } from '@/_helpers/uniqueKey'
import { getAllDicts } from './dicts'

export type MtaAutoUnfold = '' | 'once' | 'always' | 'popup'
export type MtaAutoUnfold = '' | 'once' | 'always' | 'popup' | 'hide'

export type ProfileMutable = ReturnType<typeof _getDefaultProfile>
export type Profile = DeepReadonly<ProfileMutable>
Expand Down
3 changes: 1 addition & 2 deletions src/content/components/DictPanel/DictPanel.container.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import { DictListContainer } from '../DictList/DictList.container'
import { WaveformBoxContainer } from '../WaveformBox/WaveformBox.container'

const menuBar = <MenuBarContainer />
const mtaBox = <MtaBoxContainer />
const dictList = <DictListContainer />
const waveformBox = <WaveformBoxContainer />

Expand All @@ -35,7 +34,7 @@ const mapStateToProps: MapStateToProps<
panelCSS: state.config.panelCSS,
darkMode: state.config.darkMode,
menuBar,
mtaBox,
mtaBox: state.isShowMtaBox ? <MtaBoxContainer /> : null,
dictList,
waveformBox: state.activeProfile.waveform ? waveformBox : null,
dragStartCoord: state.dragStartCoord
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import { DictListContainer } from '../DictList/DictList.container'
import { WaveformBoxContainer } from '../WaveformBox/WaveformBox.container'

const menuBar = <MenuBarContainer />
const mtaBox = <MtaBoxContainer />
const dictList = <DictListContainer />
const waveformBox = <WaveformBoxContainer />

Expand All @@ -27,7 +26,7 @@ const mapStateToProps = (
panelCSS: state.config.panelCSS,
fontSize: state.config.fontSize,
menuBar,
mtaBox,
mtaBox: state.isShowMtaBox ? <MtaBoxContainer /> : null,
dictList,
waveformBox,
width: ownProps.width,
Expand Down
1 change: 1 addition & 0 deletions src/content/components/MtaBox/MtaBox.container.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ const mapStateToProps: MapStateToProps<
text: state.text,
shouldFocus:
!state.activeProfile.mtaAutoUnfold ||
state.activeProfile.mtaAutoUnfold !== 'hide' ||
((state.isQSPanel || isQuickSearchPage()) && state.config.qsFocus) ||
isPopupPage()
})
Expand Down
27 changes: 16 additions & 11 deletions src/content/redux/modules/action-handlers/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,17 +34,22 @@ export const actionHandlers: ActionHandlers<State, ActionCatalog> = {
profiles: payload
}),

NEW_ACTIVE_PROFILE: (state, { payload }) => ({
...state,
activeProfile: payload,
isExpandMtaBox:
payload.mtaAutoUnfold === 'once' ||
payload.mtaAutoUnfold === 'always' ||
(payload.mtaAutoUnfold === 'popup' && isPopupPage()),
renderedDicts: state.renderedDicts.filter(({ id }) =>
payload.dicts.selected.includes(id)
)
}),
NEW_ACTIVE_PROFILE: (state, { payload }) => {
const isShowMtaBox = payload.mtaAutoUnfold !== 'hide'
return {
...state,
activeProfile: payload,
isShowMtaBox,
isExpandMtaBox:
isShowMtaBox &&
(payload.mtaAutoUnfold === 'once' ||
payload.mtaAutoUnfold === 'always' ||
(payload.mtaAutoUnfold === 'popup' && isPopupPage())),
renderedDicts: state.renderedDicts.filter(({ id }) =>
payload.dicts.selected.includes(id)
)
}
},

NEW_SELECTION: newSelection,

Expand Down
10 changes: 7 additions & 3 deletions src/content/redux/modules/state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ export const initState = async () => {

const url = window.location.href

const isShowMtaBox = activeProfile.mtaAutoUnfold !== 'hide'

return {
config,
profiles,
Expand Down Expand Up @@ -59,10 +61,12 @@ export const initState = async () => {
},
isShowBowl: false,
isShowDictPanel: isStandalonePage(),
isShowMtaBox,
isExpandMtaBox:
activeProfile.mtaAutoUnfold === 'once' ||
activeProfile.mtaAutoUnfold === 'always' ||
(activeProfile.mtaAutoUnfold === 'popup' && isPopupPage()),
isShowMtaBox &&
(activeProfile.mtaAutoUnfold === 'once' ||
activeProfile.mtaAutoUnfold === 'always' ||
(activeProfile.mtaAutoUnfold === 'popup' && isPopupPage())),
isExpandWaveformBox: false,
isPinned: false,
/** Is current word in Notebook */
Expand Down
3 changes: 3 additions & 0 deletions src/options/components/Entries/DictPanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ export const DictPanel: FC = () => {
<Select.Option value="popup">
{t('profile.opt.mtaAutoUnfold.popup')}
</Select.Option>
<Select.Option value="hide">
{t('profile.opt.mtaAutoUnfold.hide')}
</Select.Option>
</Select>
)
},
Expand Down

0 comments on commit 77e30f9

Please sign in to comment.