From da9af0273f1fb2aa0c0fe45e1196916e7631cf9c Mon Sep 17 00:00:00 2001 From: Henrique Dias Date: Fri, 31 May 2019 09:23:21 +0100 Subject: [PATCH] fix: use electron dir picker on IPFS Desktop (#1034) License: MIT Signed-off-by: Henrique Dias --- src/bundles/ipfs-desktop.js | 4 ++++ src/files/file-input/FileInput.js | 21 +++++++++++++++++++-- 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/src/bundles/ipfs-desktop.js b/src/bundles/ipfs-desktop.js index 815022c90..578c4dc02 100644 --- a/src/bundles/ipfs-desktop.js +++ b/src/bundles/ipfs-desktop.js @@ -34,6 +34,10 @@ if (window.ipfsDesktop) { window.ipfsDesktop.toggleSetting(setting) }, + doDesktopSelectDirectory: () => () => { + return window.ipfsDesktop.selectDirectory() + }, + init: store => { store.doDesktopStartListening() } diff --git a/src/files/file-input/FileInput.js b/src/files/file-input/FileInput.js index 78c40162a..517780a27 100644 --- a/src/files/file-input/FileInput.js +++ b/src/files/file-input/FileInput.js @@ -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 @@ -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 }) @@ -94,7 +107,7 @@ class FileInput extends React.Component { {t('addFile')} - @@ -131,4 +144,8 @@ class FileInput extends React.Component { } } -export default translate('files')(FileInput) +export default connect( + 'selectIsIpfsDesktop', + 'doDesktopSelectDirectory', + translate('files')(FileInput) +)