Skip to content

Commit

Permalink
feat: CAR Upload loader (#318)
Browse files Browse the repository at this point in the history
Co-authored-by: Marcin Rataj <lidel@lidel.org>
  • Loading branch information
alvin-reyes and lidel committed Apr 25, 2022
1 parent 85a3b45 commit cf30c14
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 6 deletions.
6 changes: 5 additions & 1 deletion src/bundles/explore.js
Expand Up @@ -105,12 +105,16 @@ const makeBundle = () => {
store.doUpdateHash(hash)
}

bundle.doUploadUserProvidedCar = (file) => (args) => {
bundle.doUploadUserProvidedCar = (file, uploadImage) => (args) => {
const { store, getIpfs } = args
importCar(file, getIpfs()).then(result => {
const cid = result.root.cid
const hash = cid.toString() ? `#/explore${ensureLeadingSlash(cid.toString())}` : '#/explore'
store.doUpdateHash(hash)

// Grab the car loader image so we can change it's state
const imageFileLoader = document.getElementById('car-loader-image')
imageFileLoader.src = uploadImage
})
}
return bundle
Expand Down
13 changes: 10 additions & 3 deletions src/components/explore/IpldCarExploreForm.js
Expand Up @@ -8,7 +8,6 @@ class IpldCarExploreForm extends React.Component {
this.state = {
file: { }
}

this.handleOnChange = this.handleOnChange.bind(this)
this.handleOnSubmit = this.handleOnSubmit.bind(this)
}
Expand All @@ -18,9 +17,16 @@ class IpldCarExploreForm extends React.Component {
}

handleOnChange () {
var spinnerImage = require('./spinner.svg').default
var uploadImage = require('./upload.svg').default

// Change the state.
const imageFileLoader = document.getElementById('car-loader-image')
imageFileLoader.src = spinnerImage

// Get the file, upload car.
const selectedFile = document.getElementById('car-file').files[0]
this.setState({ file: selectedFile })
this.props.doUploadUserProvidedCar(selectedFile)
this.props.doUploadUserProvidedCar(selectedFile, uploadImage)
}

render () {
Expand All @@ -31,6 +37,7 @@ class IpldCarExploreForm extends React.Component {
<div className='relative'>
<input id='car-file' type='file' accept='.car' className='input-reset bn pa2 mb2 db w-100 f6 br-0 placeholder-light focus-outline' style={{ borderRadius: '3px 0 0 3px', backgroundColor: 'white', padding: '5px 0px 5px 5px', width: '99%' }} aria-describedby='name-desc' onChange={this.handleOnChange} />
<small id='car-file-desc' className='o-0 absolute f6 black-60 db mb2'>{t('IpldCarExploreForm.uploadCarFile')}</small>
<img id='car-loader-image' alt='placeholder for upload and loader' src={require('./upload.svg').default} className='absolute' style={{ top: '0px', right: '0px', height: '30px', width: '30px', paddingRight: '10px' }} />
</div>
</div>
</form>
Expand Down
4 changes: 2 additions & 2 deletions src/components/explore/IpldExploreForm.js
Expand Up @@ -39,8 +39,8 @@ class IpldExploreForm extends React.Component {
className='button-reset dib lh-copy pv1 pl2 pr3 ba f7 fw4 focus-outline white bg-aqua bn'
style={{ borderRadius: '0 3px 3px 0' }}
>
<StrokeIpld style={{ height: 24 }} className='dib fill-current-color v-mid' />
<span className='ml2'>{t('IpldExploreForm.explore')}</span>
<StrokeIpld style={{ height: 24 }} className='dib fill-current-color v-mid navy 0-100' />
<span className='ml2 navy 0-100'>{t('IpldExploreForm.explore')}</span>
</button>
</div>
</form>
Expand Down
33 changes: 33 additions & 0 deletions src/components/explore/spinner.svg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
9 changes: 9 additions & 0 deletions src/components/explore/upload.svg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit cf30c14

Please sign in to comment.