mirror of
https://github.com/Grasscutters/Cultivation.git
synced 2025-12-14 08:04:52 +01:00
fix up dirinput
This commit is contained in:
@@ -20,7 +20,7 @@ export default class TopBar extends React.Component<IProps, IState> {
|
||||
super(props)
|
||||
|
||||
app.getVersion().then(version => {
|
||||
this.setState({ version })
|
||||
this.state = { version }
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
@@ -7,6 +7,7 @@ import './DirInput.css'
|
||||
|
||||
interface IProps {
|
||||
value?: string
|
||||
onChange?: (value: string) => void
|
||||
}
|
||||
|
||||
interface IState {
|
||||
@@ -24,10 +25,23 @@ export default class DirInput extends React.Component<IProps, IState> {
|
||||
this.handleIconClick = this.handleIconClick.bind(this)
|
||||
}
|
||||
|
||||
handleIconClick() {
|
||||
open().then(path => {
|
||||
console.log(path)
|
||||
async handleIconClick() {
|
||||
let path = await open({
|
||||
filters: [
|
||||
{ name: 'Executable files', extensions: ['exe'] }
|
||||
]
|
||||
})
|
||||
|
||||
if (Array.isArray(path)) path = path[0]
|
||||
if (!path) return
|
||||
|
||||
this.setState({
|
||||
value: path
|
||||
})
|
||||
|
||||
console.log(this.state)
|
||||
|
||||
if (this.props.onChange) this.props.onChange(path)
|
||||
}
|
||||
|
||||
render() {
|
||||
|
||||
@@ -21,6 +21,10 @@ export default class TextInput extends React.Component<IProps, IState> {
|
||||
}
|
||||
}
|
||||
|
||||
static getDerivedStateFromProps(props: IProps, state: IState) {
|
||||
return { value: props.value || '' }
|
||||
}
|
||||
|
||||
render() {
|
||||
return (
|
||||
<input readOnly={this.props.readOnly || false} placeholder={this.props.placeholder || ''} className="TextInput" value={this.state.value} onChange={(e) => {
|
||||
|
||||
Reference in New Issue
Block a user