Skip to content

Commit

Permalink
wip: add actions
Browse files Browse the repository at this point in the history
License: MIT
Signed-off-by: Henrique Dias <hacdias@gmail.com>
  • Loading branch information
hacdias committed Aug 19, 2021
1 parent 59c908b commit 7fef182
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 5 deletions.
13 changes: 13 additions & 0 deletions src/bundles/files/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,19 @@ const actions = () => ({
}
}),

/**
* Imports given `source` CAR file to the provided `root` path. On completion
* (success or fail) will trigger `doFilesFetch` to update the state.
* @param {FileStream[]} source
* @param {string} root
*/
doImportCar: (source, root) => spawn(ACTIONS.IMPORT_CAR, async function * (ipfs, { store }) {
console.log(source, root)

// const res = await ipfs.dag.import(source)
console.log(ipfs.dag)
}),

/**
* Deletes `files` with provided paths. On completion (success sor fail) will
* trigger `doFilesFetch` to update the state.
Expand Down
2 changes: 2 additions & 0 deletions src/bundles/files/consts.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ export const ACTIONS = {
MAKE_DIR: ('FILES_MAKEDIR'),
/** @type {'FILES_WRITE'} */
WRITE: ('FILES_WRITE'),
/** @type {'IMPORT_CAR'} */
IMPORT_CAR: ('IMPORT_CAR'),
/** @type {'FILES_DOWNLOADLINK'} */
DOWNLOAD_LINK: ('FILES_DOWNLOADLINK'),
/** @type {'FILES_SHARE_LINK'} */
Expand Down
11 changes: 10 additions & 1 deletion src/files/FilesPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import Header from './header/Header'
import FileImportStatus from './file-import-status/FileImportStatus'

const FilesPage = ({
doFetchPinningServices, doFilesFetch, doPinsFetch, doFilesSizeGet, doFilesDownloadLink, doFilesWrite, doFilesAddPath, doUpdateHash,
doFetchPinningServices, doFilesFetch, doPinsFetch, doFilesSizeGet, doFilesDownloadLink, doFilesWrite, doImportCar, doFilesAddPath, doUpdateHash,
doFilesUpdateSorting, doFilesNavigateTo, doFilesMove, doSetCliOptions, doFetchRemotePins, remotePins, doExploreUserProvidedPath,
ipfsProvider, ipfsConnected, doFilesMakeDir, doFilesShareLink, doFilesDelete, doSetPinning, onRemotePinClick,
files, filesPathInfo, pinningServices, toursEnabled, handleJoyrideCallback, isCliTutorModeEnabled, cliOptions, t
Expand Down Expand Up @@ -66,12 +66,19 @@ const FilesPage = ({
const { abort } = await downloadFile(url, filename, updater, method)
setDownloadAbort(() => abort)
}

const onAddFiles = (raw, root = '') => {
if (root === '') root = files.path

doFilesWrite(raw, root)
}

const onImportCar = (raw, root = '') => {
if (root === '') root = files.path

doImportCar(raw, root)
}

const onAddByPath = (path) => doFilesAddPath(files.path, path)
const onInspect = (cid) => doUpdateHash(`/explore/ipfs/${cid}`)
const showModal = (modal, files = null) => setModals({ show: modal, files: files })
Expand Down Expand Up @@ -211,6 +218,7 @@ const FilesPage = ({
files={files}
onNavigate={doFilesNavigateTo}
onAddFiles={onAddFiles}
onImportCar={onImportCar}
onMove={doFilesMove}
onAddByPath={(files) => showModal(ADD_BY_PATH, files)}
onNewFolder={(files) => showModal(NEW_FOLDER, files)}
Expand Down Expand Up @@ -272,6 +280,7 @@ export default connect(
'selectFilesSorting',
'selectToursEnabled',
'doFilesWrite',
'doImportCar',
'doFilesDownloadLink',
'doExploreUserProvidedPath',
'doFilesSizeGet',
Expand Down
19 changes: 16 additions & 3 deletions src/files/file-input/FileInput.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,13 @@ class FileInput extends React.Component {
}

onAddByCar = () => {
window.alert('TODO')
// TODO
this.toggleDropdown()
return this.carInput.click()
}

onCarInputChange = (input) => async () => {
this.props.onImportCar(normalizeFiles(input.files))
input.value = null
}

onNewFolder = () => {
Expand Down Expand Up @@ -122,6 +127,13 @@ class FileInput extends React.Component {
webkitdirectory='true'
ref={el => { this.folderInput = el }}
onChange={this.onInputChange(this.folderInput)} />

<input
id='car-input'
type='file'
className='dn'
ref={el => { this.carInput = el }}
onChange={this.onCarInputChange(this.carInput)} />
</div>
)
}
Expand All @@ -131,7 +143,8 @@ FileInput.propTypes = {
t: PropTypes.func.isRequired,
onAddFiles: PropTypes.func.isRequired,
onAddByPath: PropTypes.func.isRequired,
onNewFolder: PropTypes.func.isRequired
onNewFolder: PropTypes.func.isRequired,
onImportCar: PropTypes.func.isRequired
}

export default connect(
Expand Down
3 changes: 2 additions & 1 deletion src/files/header/Header.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,9 @@ class Header extends React.Component {
{ (files && files.type === 'directory' && filesPathInfo.isMfs)
? <FileInput
onNewFolder={this.props.onNewFolder}
onAddFiles={this.props.onAddFiles}
onAddByPath={this.props.onAddByPath}
onImportCar={this.props.onImportCar}
onAddFiles={this.props.onAddFiles}
onCliTutorMode={this.props.onCliTutorMode}
/>
: <div ref={el => { this.dotsWrapper = el }}>
Expand Down

0 comments on commit 7fef182

Please sign in to comment.