Finished translations / bug fixes

This commit is contained in:
Sebastian Seedorf
2022-08-20 14:47:04 +02:00
parent 664f766cb6
commit 2fd010e003
13 changed files with 162 additions and 66 deletions

View File

@@ -1,16 +1,28 @@
import { FC, useState } from 'react'
import { forwardRef, ForwardRefRenderFunction, useImperativeHandle, useState } from 'react'
import { FactorySelect } from '../FactorySelect/FactorySelect'
import { useGroups } from '../../contexts/GroupProvider'
import { i18n, I18n } from '../../shared/I18n/I18n'
import { useIntl } from 'react-intl'
export const Preferences: FC = () => {
interface Handle {
addGroup(preferredName: string, exported?: string[], mall?: string[]): boolean
}
const PreferencesBase: ForwardRefRenderFunction<Handle> = (_, forwardedRef) => {
const intl = useIntl()
const DEFAULT_NAME = i18n(intl, 'page.home.group.add.default_group_name')
useImperativeHandle(forwardedRef, () => ({
addGroup(preferredName: string, exported?: string[], mall?: string[]) {
const name = newGroupValue !== DEFAULT_NAME ? newGroupValue : preferredName
const result = addGroup(name, exported, mall)
result && setNewGroupValue(DEFAULT_NAME)
return result
}
}))
const { addGroup, baseFactories, setBaseFactories, ignoredFactories, setIgnoredFactories } =
useGroups()
const [newGroupValue, setNewGroupValue] = useState(
i18n(intl, 'page.home.group.add.default_group_name')
)
const [newGroupValue, setNewGroupValue] = useState(DEFAULT_NAME)
return (
<>
<fieldset>
@@ -49,7 +61,7 @@ export const Preferences: FC = () => {
disabled={!newGroupValue}
onClick={() => {
addGroup(newGroupValue)
setNewGroupValue('New group')
setNewGroupValue(DEFAULT_NAME)
}}
>
<I18n id={'page.home.group.add.button_text'} values={{ name: newGroupValue }} />
@@ -58,3 +70,5 @@ export const Preferences: FC = () => {
</>
)
}
export const Preferences = forwardRef(PreferencesBase)