fix up dirinput

This commit is contained in:
SpikeHD
2022-05-10 01:13:30 -07:00
parent 870f873d0f
commit d1e4a9d597
3 changed files with 22 additions and 4 deletions

View File

@@ -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 }
})
}

View File

@@ -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() {

View File

@@ -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) => {