disable Compile button on loading

pull/1/head
LianaHus 5 years ago committed by Liana Husikyan
parent 4ae1d147bf
commit d89cfefdc6
  1. 33
      src/app/tabs/compileTab/compilerContainer.js

@ -37,6 +37,7 @@ class CompilerContainer {
} }
if (!this._view.compilationButton) return if (!this._view.compilationButton) return
const button = this.compilationButton(name.split('/').pop()) const button = this.compilationButton(name.split('/').pop())
this._disableCompileBtn(!name || name === '')
yo.update(this._view.compilationButton, button) yo.update(this._view.compilationButton, button)
} }
@ -77,6 +78,7 @@ class CompilerContainer {
this.compileTabLogic.compiler.event.register('loadingCompiler', () => { this.compileTabLogic.compiler.event.register('loadingCompiler', () => {
if (!this._view.compileIcon) return if (!this._view.compileIcon) return
this._disableCompileBtn(true)
this._view.compileIcon.setAttribute('title', 'compiler is loading, please wait a few moments.') this._view.compileIcon.setAttribute('title', 'compiler is loading, please wait a few moments.')
this._view.compileIcon.classList.add(`${css.spinningIcon}`) this._view.compileIcon.classList.add(`${css.spinningIcon}`)
this._view.warnCompilationSlow.style.visibility = 'hidden' this._view.warnCompilationSlow.style.visibility = 'hidden'
@ -85,6 +87,7 @@ class CompilerContainer {
this.compileTabLogic.compiler.event.register('compilerLoaded', () => { this.compileTabLogic.compiler.event.register('compilerLoaded', () => {
if (!this._view.compileIcon) return if (!this._view.compileIcon) return
this._disableCompileBtn(false)
this._view.compileIcon.setAttribute('title', '') this._view.compileIcon.setAttribute('title', '')
this._view.compileIcon.classList.remove(`${css.spinningIcon}`) this._view.compileIcon.classList.remove(`${css.spinningIcon}`)
if (this.data.autoCompile) this.compileIfAutoCompileOn() if (this.data.autoCompile) this.compileIfAutoCompileOn()
@ -103,19 +106,31 @@ class CompilerContainer {
*/ */
compilationButton (name) { compilationButton (name) {
if (!name) name = '' if (!name) name = ''
var displayed = name === '' ? '<no file selected>' : name const displayed = name === '' ? '<no file selected>' : name
var el = yo` const disabled = name === '' ? 'disabled' : ''
<div class="px-2 mt-2 pb-0 d-flex"> const compileBtn = yo`
<button class="btn btn-primary btn-block ${name === '' ? 'disabled' : ''}" title="Compile" onclick="${this.compile.bind(this)}"> <button id="compileBtn" class="btn btn-primary btn-block ${disabled}" title="Compile" onclick="${this.compile.bind(this)}">
<span>${this._view.compileIcon} Compile ${displayed}</span> <span>${this._view.compileIcon} Compile ${displayed}</span>
</button> </button>
</div>` `
if (name === '') { let el = yo`
el.setAttribute('disabled', 'true') <div class="px-2 mt-2 pb-0 d-flex">
} ${compileBtn}
</div>
`
return el return el
} }
_disableCompileBtn (disable) {
let btn = document.querySelector("button[id='compileBtn']")
if (!btn) return
if (disable) {
btn.classList.add('disabled')
} else if (this.config.get('currentFile')) {
btn.classList.remove('disabled')
}
}
// Load solc compiler version according to pragma in contract file // Load solc compiler version according to pragma in contract file
_setCompilerVersionFromPragma (filename) { _setCompilerVersionFromPragma (filename) {
this.compileTabLogic.fileManager.getFile(filename).then(data => { this.compileTabLogic.fileManager.getFile(filename).then(data => {
@ -220,7 +235,7 @@ class CompilerContainer {
<div class="col-sm-4"> <div class="col-sm-4">
<div class="d-flex flex-row justify-content-end"> <div class="d-flex flex-row justify-content-end">
<label class="${css.compilerLabel} input-group-text pr-0 border-0 w-100" for="versionSelector"> <label class="${css.compilerLabel} input-group-text pr-0 border-0 w-100" for="versionSelector">
<button class="far fa-plus-square border-0 p-0 m-2 text-dark btn-sm" onclick="${(e) => this.promtCompiler(e)}" title="Add a custom compiler with URL"></button> <button class="far fa-plus-square border-0 p-0 mx-2 text-dark btn-sm" onclick="${(e) => this.promtCompiler(e)}" title="Add a custom compiler with URL"></button>
Compiler Compiler
</label> </label>
</div> </div>

Loading…
Cancel
Save