From d1e4a9d59741d6407af2184f4d40b927da73c70a Mon Sep 17 00:00:00 2001 From: SpikeHD Date: Tue, 10 May 2022 01:13:30 -0700 Subject: [PATCH] fix up dirinput --- src/ui/components/TopBar.tsx | 2 +- src/ui/components/common/DirInput.tsx | 20 +++++++++++++++++--- src/ui/components/common/TextInput.tsx | 4 ++++ 3 files changed, 22 insertions(+), 4 deletions(-) diff --git a/src/ui/components/TopBar.tsx b/src/ui/components/TopBar.tsx index 7b66d75..d3d76af 100644 --- a/src/ui/components/TopBar.tsx +++ b/src/ui/components/TopBar.tsx @@ -20,7 +20,7 @@ export default class TopBar extends React.Component { super(props) app.getVersion().then(version => { - this.setState({ version }) + this.state = { version } }) } diff --git a/src/ui/components/common/DirInput.tsx b/src/ui/components/common/DirInput.tsx index 837a76c..fd71e3b 100644 --- a/src/ui/components/common/DirInput.tsx +++ b/src/ui/components/common/DirInput.tsx @@ -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 { 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() { diff --git a/src/ui/components/common/TextInput.tsx b/src/ui/components/common/TextInput.tsx index b106192..2d5f8d1 100644 --- a/src/ui/components/common/TextInput.tsx +++ b/src/ui/components/common/TextInput.tsx @@ -21,6 +21,10 @@ export default class TextInput extends React.Component { } } + static getDerivedStateFromProps(props: IProps, state: IState) { + return { value: props.value || '' } + } + render() { return ( {