Skip to content

Commit

Permalink
Modal UX working, need to clean up code
Browse files Browse the repository at this point in the history
  • Loading branch information
MattWong-ca committed Dec 7, 2024
1 parent a85432f commit 481e7a9
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 23 deletions.
27 changes: 22 additions & 5 deletions src/bundles/files/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -405,15 +405,32 @@ const actions = () => ({
* @param {string} root - Destination directory in IPFS
*/
doFilesAddBulkCid: (source, root) => spawn(ACTIONS.ADD_BY_PATH, async function * (ipfs, { store }) {
console.log('Action parameters:', { source, root })
console.log('Arguments:', arguments)

ensureMFS(store)
console.log('doFilesAddBulkCid source', source)

if (source.length !== 1) {
throw new Error('Please provide exactly one text file')
// Ensure source is properly passed
if (!source) {
throw new Error('Source is required')
}

// If source is passed as first argument of spawn callback
const actualSource = Array.isArray(source) ? source : arguments[0]
console.log('Actual source:', actualSource)

if (!Array.isArray(actualSource)) {
throw new Error('Source must be an array')
}

const fileStream = actualSource[0]
console.log('fileStream:', fileStream)

if (!fileStream || !fileStream.content) {
throw new Error('Invalid file format')
}

// Read the text file content
const file = source[0]
const file = fileStream
const content = await new Response(file.content).text()

const lines = content.split('\n').map(line => line.trim()).filter(Boolean)
Expand Down
2 changes: 2 additions & 0 deletions src/files/FilesPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,9 @@ const FilesPage = ({
}

const onBulkCidImport = (raw, root = '') => {
console.log('FilesPage onBulkCidImport:', { raw, root, filesPath: files.path })
if (root === '') root = files.path
console.log('Calling doFilesAddBulkCid with:', { raw, root })
doFilesAddBulkCid(raw, root)
}

Expand Down
2 changes: 1 addition & 1 deletion src/files/file-input/FileInput.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ class FileInput extends React.Component {
{t('newFolder')}
</Option>
<Option
// onClick={this.onAddBulkCid}
// onClick={this.onAddBulkCid} // This worked before
onClick={this.onBulkCidImport}
// TO-DO:
// id='add-bulk-cid'
Expand Down
4 changes: 2 additions & 2 deletions src/files/modals/Modals.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@ class Modals extends React.Component {
this.leave()
}

onBulkCidImport = () => {
this.props.onBulkCidImport()
onBulkCidImport = (files, root) => {
this.props.onBulkCidImport(files, root)
this.leave()
}

Expand Down
37 changes: 22 additions & 15 deletions src/files/modals/bulk-import-modal/BulkImportModal.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,25 @@ class BulkImportModal extends React.Component {
this.setState({ [name]: value })
}

onBulkCidInputChange = (input) => async () => {
console.log('input: ', input)
this.setState({ selectedFile: input.files })
onBulkCidInputChange = (event) => {
const files = event.target.files
console.log('files: ', files)
this.setState({ selectedFile: files[0] })
// console.log('input: ', input)
// this.setState({ selectedFile: input.files })
}

onSubmit = () => {
console.log('Files to import:', this.state.selectedFile)
this.props.onBulkCidImport(normalizeFiles(this.state.selectedFile))
// input.value = null
selectFile = async () => {
return this.bulkCidInputt.click()
}

onSubmit = async () => {
console.log('BulkImportModal onSubmit:', this.state.selectedFile)
if (this.state.selectedFile) {
const normalizedFiles = normalizeFiles([this.state.selectedFile])
console.log('Calling onBulkCidImport with:', { normalizedFiles, root: '/files' })
await this.props.onBulkCidImport(normalizedFiles, '/files')
}
}

get inputClass () {
Expand All @@ -72,13 +82,13 @@ class BulkImportModal extends React.Component {

render () {
const {
t, onCancel, className
t, tReady, onCancel, onSubmit, className, ...props
} = this.props

const codeClass = 'w-100 mb1 pa1 tl bg-snow f7 charcoal-muted truncate'

return (
<Modal className={className} onCancel={onCancel}>
<Modal {...props} className={className} onCancel={onCancel}>
<ModalBody title={'Bulk Import with Text File'} Icon={Icon}>
<div className='mb3 flex flex-column items-center'>
<p className='mt0 charcoal tl w-100'>{'Upload a text file with a list of CIDs (names are optional).' + ' ' + 'Example:'}</p>
Expand All @@ -90,19 +100,16 @@ class BulkImportModal extends React.Component {
className='dn'
multiple
accept='.txt'
onChange={this.onBulkCidInputChange(this.bulkCidInput)}
onChange={this.onBulkCidInputChange}
// className='input-reset'
// id='bulk-import'
ref={el => {
console.log('Setting ref:', el)
this.bulkCidInput = el
this.bulkCidInputt = el
}}
/>
<Button
onClick={() => {
console.log('clicked')
this.bulkCidInput.click()
}}
onClick={this.selectFile}
className='ma2 tc'
bg='bg-teal'
type='button'
Expand Down

0 comments on commit 481e7a9

Please sign in to comment.