Skip to content

Commit

Permalink
fix(options): entry incorrect initial form state
Browse files Browse the repository at this point in the history
Closes #865
  • Loading branch information
crimx committed Jun 23, 2020
1 parent e0e962e commit f009670
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 33 deletions.
2 changes: 2 additions & 0 deletions src/options/components/Entries/ContextMenus/EditeModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ export const EditModal: FC<EditModalProps> = ({ menuID, onClose }) => {
}
})

if (allMenus === null) return null

return (
<Modal
visible={!!menuID}
Expand Down
62 changes: 30 additions & 32 deletions src/options/components/Entries/DictAuths.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ export const DictAuths: FC = () => {
const { t } = useTranslate(['options', 'dicts'])
const dictAuths = useObservableGetState(config$$, null, 'dictAuth')

if (dictAuths === null) return null

const formItems: SaladictFormItem[] = [
{
key: 'dictauthstitle',
Expand All @@ -24,41 +26,37 @@ export const DictAuths: FC = () => {
}
]

if (dictAuths) {
objectKeys(dictAuths).forEach(dictID => {
const auth = dictAuths[dictID]!
const configPath = getConfigPath('dictAuth', dictID)
const title = t(`dicts:${dictID}.name`)
objectKeys(dictAuths).forEach(dictID => {
const auth = dictAuths[dictID]!
const configPath = getConfigPath('dictAuth', dictID)
const title = t(`dicts:${dictID}.name`)

objectKeys(auth).forEach((key, i, keys) => {
const isLast = i + 1 === keys.length
formItems.push({
name: configPath + '.' + key,
label: (
<span>
{i === 0 ? title + ' ' : ''}
<code>{key}</code>
</span>
),
help: isLast ? (
<Trans message={t('dictAuth.dictHelp')}>
<a
href={
require(`@/components/dictionaries/${dictID}/auth.ts`).url
}
target="_blank"
rel="nofollow noopener noreferrer"
>
{title}
</a>
</Trans>
) : null,
style: { marginBottom: isLast ? 10 : 5 },
children: <Input />
})
objectKeys(auth).forEach((key, i, keys) => {
const isLast = i + 1 === keys.length
formItems.push({
name: configPath + '.' + key,
label: (
<span>
{i === 0 ? title + ' ' : ''}
<code>{key}</code>
</span>
),
help: isLast ? (
<Trans message={t('dictAuth.dictHelp')}>
<a
href={require(`@/components/dictionaries/${dictID}/auth.ts`).url}
target="_blank"
rel="nofollow noopener noreferrer"
>
{title}
</a>
</Trans>
) : null,
style: { marginBottom: isLast ? 10 : 5 },
children: <Input />
})
})
}
})

return <SaladictForm items={formItems} />
}
4 changes: 3 additions & 1 deletion src/options/components/Entries/Pronunciation.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export const Pronunciation: FC = () => {
const globals = useContext(GlobalsContext)
const zdicAudio = useObservableGetState(
profile$$,
false,
null,
'dicts',
'all',
'zdic',
Expand All @@ -27,6 +27,8 @@ export const Pronunciation: FC = () => {
[zdicAudio]
)

if (zdicAudio === null) return null

return (
<SaladictForm
items={[
Expand Down

0 comments on commit f009670

Please sign in to comment.