Skip to content

Commit

Permalink
fix: use electron dir picker on IPFS Desktop (#1034)
Browse files Browse the repository at this point in the history
License: MIT
Signed-off-by: Henrique Dias <[email protected]>
  • Loading branch information
hacdias authored May 31, 2019
1 parent 070d6f6 commit da9af02
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
4 changes: 4 additions & 0 deletions src/bundles/ipfs-desktop.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ if (window.ipfsDesktop) {
window.ipfsDesktop.toggleSetting(setting)
},

doDesktopSelectDirectory: () => () => {
return window.ipfsDesktop.selectDirectory()
},

init: store => {
store.doDesktopStartListening()
}
Expand Down
21 changes: 19 additions & 2 deletions src/files/file-input/FileInput.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import React from 'react'
import PropTypes from 'prop-types'
import { connect } from 'redux-bundler-react'
import { translate } from 'react-i18next'
import { filesToStreams } from '../../lib/files'
// Icons
Expand Down Expand Up @@ -56,6 +57,18 @@ class FileInput extends React.Component {
})
}

handleAddFolder = async () => {
if (!this.props.isIpfsDesktop) {
return this.folderInput.click()
}

this.toggleDropdown()
const files = await this.props.doDesktopSelectDirectory()
if (files) {
this.props.onAddFiles(files)
}
}

componentDidUpdate (prev) {
if (this.props.addProgress === 100 && prev.addProgress !== 100) {
this.setState({ force100: true })
Expand Down Expand Up @@ -94,7 +107,7 @@ class FileInput extends React.Component {
<DocumentIcon className='fill-aqua w2 mr1' />
{t('addFile')}
</Option>
<Option onClick={() => this.folderInput.click()}>
<Option onClick={this.handleAddFolder}>
<FolderIcon className='fill-aqua w2 mr1' />
{t('addFolder')}
</Option>
Expand Down Expand Up @@ -131,4 +144,8 @@ class FileInput extends React.Component {
}
}

export default translate('files')(FileInput)
export default connect(
'selectIsIpfsDesktop',
'doDesktopSelectDirectory',
translate('files')(FileInput)
)

0 comments on commit da9af02

Please sign in to comment.