diff --git a/ui/component/common/file-selector.jsx b/ui/component/common/file-selector.jsx index ea298efc8..9341b0952 100644 --- a/ui/component/common/file-selector.jsx +++ b/ui/component/common/file-selector.jsx @@ -1,6 +1,6 @@ // @flow import * as React from 'react'; - +import { remote } from 'electron'; import Button from 'component/button'; import { FormField } from 'component/common/form'; @@ -49,11 +49,22 @@ class FileSelector extends React.PureComponent { } const file = files[0]; + if (this.props.onFileChosen) { this.props.onFileChosen(file); } }; + handleDirectoryInputSelection = () => { + remote.dialog.showOpenDialog({ properties: ['openDirectory'] }).then(result => { + const path = result && result.filePaths[0]; + if (path) { + // $FlowFixMe + this.props.onFileChosen({ path }); + } + }); + }; + fileInputButton = () => { this.fileInput.current.click(); }; @@ -80,7 +91,7 @@ class FileSelector extends React.PureComponent { autoFocus={autoFocus} button="secondary" disabled={disabled} - onClick={this.fileInputButton} + onClick={type === 'openDirectory' ? this.handleDirectoryInputSelection : this.fileInputButton} label={__('Browse')} /> } @@ -90,7 +101,7 @@ class FileSelector extends React.PureComponent { style={{ display: 'none' }} accept={accept} ref={this.fileInput} - onChange={() => this.handleFileInputSelection()} + onChange={() => (type === 'openDirectory' ? () => {} : this.handleFileInputSelection())} webkitdirectory={type === 'openDirectory' ? 'True' : null} /> diff --git a/ui/component/walletBackup/view.jsx b/ui/component/walletBackup/view.jsx index aa25c3d1c..3592cbdfb 100644 --- a/ui/component/walletBackup/view.jsx +++ b/ui/component/walletBackup/view.jsx @@ -144,7 +144,7 @@ class WalletBackup extends React.PureComponent { label={__('Create Backup')} onClick={() => this.backupWalletDir(lbryumWalletDir)} /> -