mirror of
https://github.com/Grasscutters/Cultivation.git
synced 2025-12-14 16:14:48 +01:00
dir options setting and default vlaue
This commit is contained in:
@@ -28,6 +28,12 @@ export default class DirInput extends React.Component<IProps, IState> {
|
||||
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( {
|
||||
|
||||
@@ -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<IProps, never> {
|
||||
interface IState {
|
||||
game_path: string
|
||||
}
|
||||
|
||||
export default class Options extends React.Component<IProps, IState> {
|
||||
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<IProps, never> {
|
||||
<Tr text="options.game_exec" />
|
||||
</div>
|
||||
<div className='OptionValue'>
|
||||
<DirInput onChange={this.setGameExec} />
|
||||
<DirInput onChange={this.setGameExec} value={this.state?.game_path}/>
|
||||
</div>
|
||||
</div>
|
||||
</Menu>
|
||||
|
||||
Reference in New Issue
Block a user