mirror of
https://github.com/Grasscutters/Cultivation.git
synced 2025-12-16 09:04:45 +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)
|
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() {
|
async componentDidMount() {
|
||||||
const translation = await translate('components.select_file')
|
const translation = await translate('components.select_file')
|
||||||
this.setState( {
|
this.setState( {
|
||||||
|
|||||||
@@ -3,15 +3,33 @@ import DirInput from '../common/DirInput'
|
|||||||
import Menu from './Menu'
|
import Menu from './Menu'
|
||||||
import Tr from '../../../utils/language'
|
import Tr from '../../../utils/language'
|
||||||
import './Options.css'
|
import './Options.css'
|
||||||
import { setConfigOption } from '../../../utils/configuration'
|
import { getConfigOption, setConfigOption } from '../../../utils/configuration'
|
||||||
|
|
||||||
interface IProps {
|
interface IProps {
|
||||||
closeFn: () => void;
|
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) {
|
constructor(props: IProps) {
|
||||||
super(props)
|
super(props)
|
||||||
|
|
||||||
|
this.state = {
|
||||||
|
game_path: '',
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
componentDidMount() {
|
||||||
|
getConfigOption('game_path').then((value: string) => {
|
||||||
|
this.setState({
|
||||||
|
game_path: value || ''
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
this.forceUpdate()
|
||||||
}
|
}
|
||||||
|
|
||||||
setGameExec(value: string) {
|
setGameExec(value: string) {
|
||||||
@@ -26,7 +44,7 @@ export default class Options extends React.Component<IProps, never> {
|
|||||||
<Tr text="options.game_exec" />
|
<Tr text="options.game_exec" />
|
||||||
</div>
|
</div>
|
||||||
<div className='OptionValue'>
|
<div className='OptionValue'>
|
||||||
<DirInput onChange={this.setGameExec} />
|
<DirInput onChange={this.setGameExec} value={this.state?.game_path}/>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</Menu>
|
</Menu>
|
||||||
|
|||||||
Reference in New Issue
Block a user