import Plugin from './Plugin' import yo from 'yo-yo' /** * Progress drawer * */ export default class ProgressDrawer extends Plugin { constructor (core, opts) { super(core, opts) this.name = 'Progress Drawer' this.type = 'progressindicator' // set default options const defaultOptions = {} // merge default options with the ones set by user this.opts = Object.assign({}, defaultOptions, opts) this.el = this.render(this.core.state) } update (state) { const newEl = this.render(state) yo.update(this.el, newEl) } render (state) { const selectedFiles = state.selectedFiles const uploadedFiles = state.uploadedFiles const selectedFileCount = Object.keys(selectedFiles).length const uploadedFileCount = Object.keys(uploadedFiles).length const isSomethingSelected = selectedFileCount > 0 const isSomethingUploaded = uploadedFileCount > 0 const isSomethingSelectedOrUploaded = isSomethingSelected || isSomethingUploaded const autoProceed = this.core.opts.autoProceed const drawerItem = (file) => { const isUploaded = file.progress === 100 const remove = (ev) => { this.core.emitter.emit('file-remove', file.id) } const checkIcon = yo` ` return yo`
  • ${file.type.general === 'image' ? yo`${file.name}` : yo`${file.type.specific}` }

    ${file.name} (${file.progress})

    ${isUploaded ? checkIcon : ''} ${isUploaded ? '' : yo`` }
  • ` } const next = (ev) => { this.core.emitter.emit('next') } return yo`
    ${isSomethingSelected ? this.core.i18n('filesChosen', {'smart_count': selectedFileCount}) : ''} ${isSomethingSelected && isSomethingUploaded ? ', ' : ''} ${isSomethingUploaded ? this.core.i18n('filesUploaded', {'smart_count': uploadedFileCount}) : ''}
    ${autoProceed ? '' : yo`` }
    ` } install () { const caller = this this.target = this.getTarget(this.opts.target, caller, this.el) // document.querySelector(this.target).appendChild(this.el) return } }