Skip to content

Commit

Permalink
add bundle files write
Browse files Browse the repository at this point in the history
  • Loading branch information
hacdias committed May 24, 2018
1 parent fb34b81 commit ceb57ab
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 6 deletions.
15 changes: 15 additions & 0 deletions src/bundles/files.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { createAsyncResourceBundle, createSelector } from 'redux-bundler'
import { join } from '../lib/path'

const bundle = createAsyncResourceBundle({
name: 'files',
Expand Down Expand Up @@ -102,4 +103,18 @@ bundle.doFilesMakeDir = (path) => ({dispatch, getIpfs, store}) => {
})
}

bundle.doFilesWrite = (root, files) => ({dispatch, getIpfs, store}) => {
dispatch({ type: 'FILES_WRITE_STARTED' })

return Promise.all(files.map((file) => {
const target = join(root, file.name)
return getIpfs().files.write(target, file.content, { create: true })
})).then(() => {
store.doFetchFiles()
dispatch({ type: 'FILES_WRITE_FINISHED' })
}).catch((error) => {
dispatch({ type: 'FILES_WRITE_ERRORED', payload: error })
})
}

export default bundle
7 changes: 1 addition & 6 deletions src/files/files-list/FilesList.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import PropTypes from 'prop-types'
import Checkbox from '../../components/checkbox/Checkbox'
import SelectedActions from '../selected-actions/SelectedActions'
import File from '../file/File'
import { join } from '../../lib/path'
import './FilesList.css'

const ORDER_BY_NAME = 'name'
Expand All @@ -18,12 +19,6 @@ function compare (a, b, asc) {
}
}

function join (a, b) {
if (a.endsWith('/')) a = a.slice(0, -1)
if (b.startsWith('/')) b = b.slice(1)
return `${a}/${b}`
}

class FileList extends React.Component {
static propTypes = {
className: PropTypes.string,
Expand Down
6 changes: 6 additions & 0 deletions src/lib/path.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,9 @@ export function quickSplitPath (str) {
address: res[0] // /ipfs/QmHash/foo/bar
}
}

export function join (a, b) {
if (a.endsWith('/')) a = a.slice(0, -1)
if (b.startsWith('/')) b = b.slice(1)
return `${a}/${b}`
}

0 comments on commit ceb57ab

Please sign in to comment.