diff --git a/src/ui/components/common/DirInput.tsx b/src/ui/components/common/DirInput.tsx index 0901292..631a639 100644 --- a/src/ui/components/common/DirInput.tsx +++ b/src/ui/components/common/DirInput.tsx @@ -28,6 +28,12 @@ export default class DirInput extends React.Component { this.handleIconClick = this.handleIconClick.bind(this) } + static getDerivedStateFromProps(props: IProps, state: IState) { + if (!props.value || state.value !== '') return state + + return { value: props.value || '' } + } + async componentDidMount() { const translation = await translate('components.select_file') this.setState( { diff --git a/src/ui/components/menu/Options.tsx b/src/ui/components/menu/Options.tsx index 6295089..ec48a5a 100644 --- a/src/ui/components/menu/Options.tsx +++ b/src/ui/components/menu/Options.tsx @@ -3,15 +3,33 @@ import DirInput from '../common/DirInput' import Menu from './Menu' import Tr from '../../../utils/language' import './Options.css' -import { setConfigOption } from '../../../utils/configuration' +import { getConfigOption, setConfigOption } from '../../../utils/configuration' interface IProps { closeFn: () => void; } -export default class Options extends React.Component { +interface IState { + game_path: string +} + +export default class Options extends React.Component { constructor(props: IProps) { super(props) + + this.state = { + game_path: '', + } + } + + componentDidMount() { + getConfigOption('game_path').then((value: string) => { + this.setState({ + game_path: value || '' + }) + }) + + this.forceUpdate() } setGameExec(value: string) { @@ -26,7 +44,7 @@ export default class Options extends React.Component {
- +