fix toaster

pull/3094/head
yann300 6 years ago
parent 34657f2ab0
commit 9d1adbf077
  1. 11
      src/app/files/fileManager.js
  2. 4
      src/app/ui/tooltip.js

@ -135,9 +135,9 @@ class FileManager extends FileSystemApi {
if (this.currentRequest) { if (this.currentRequest) {
let reject = false let reject = false
let savedAsAnotherFile = false let savedAsAnotherFile = false
let warnToaster let actions = (toaster) => {
const actions = yo`<div class="container ml-1"> return yo`<div class="container ml-1">
<button class="btn btn-primary btn-sm m-1" onclick=${(e) => { reject = true; e.target.innerHTML = 'Canceled'; warnToaster.hide() }}>Cancel</button> <button class="btn btn-primary btn-sm m-1" onclick=${(e) => { reject = true; e.target.innerHTML = 'Canceled'; toaster.hide() }}>Cancel</button>
<button class="btn btn-primary btn-sm m-1" onclick=${(e) => { <button class="btn btn-primary btn-sm m-1" onclick=${(e) => {
if (savedAsAnotherFile) return if (savedAsAnotherFile) return
savedAsAnotherFile = true savedAsAnotherFile = true
@ -145,10 +145,11 @@ class FileManager extends FileSystemApi {
this._setFileInternal(newPath, content) this._setFileInternal(newPath, content)
this.switchFile(newPath) this.switchFile(newPath)
e.target.innerHTML = 'Saved' e.target.innerHTML = 'Saved'
warnToaster.hide() toaster.hide()
}}>Save As Copy</button> }}>Save As Copy</button>
</div>` </div>`
warnToaster = await toaster(yo`<div><i class="fas fa-exclamation-triangle text-info mr-1"></i><span class="text-primary">${this.currentRequest.from}</span> is modyfing <span class="text-primary">${path}</span></div>`, actions, { time: 4000 }) }
await toaster(yo`<div><i class="fas fa-exclamation-triangle text-info mr-1"></i><span class="text-primary">${this.currentRequest.from}</span> is modyfing <span class="text-primary">${path}</span></div>`, actions, { time: 4000 })
if (reject) throw new Error(`set file operation on ${path} aborted by user.`) if (reject) throw new Error(`set file operation on ${path} aborted by user.`)
if (savedAsAnotherFile) return if (savedAsAnotherFile) return
} }

@ -5,11 +5,11 @@ var modal = require('./modal-dialog-custom')
/** /**
* Open a tooltip * Open a tooltip
* @param {string} tooltipText The text shown by the tooltip * @param {string} tooltipText The text shown by the tooltip
* @param {HTMLElement} [action] An HTMLElement to display for action * @param {function} [action] Returns An HTMLElement to display for action
*/ */
module.exports = function addTooltip (tooltipText, action, opts) { module.exports = function addTooltip (tooltipText, action, opts) {
let t = new Toaster() let t = new Toaster()
return t.render(tooltipText, action, opts) return t.render(tooltipText, action(t), opts)
} }
class Toaster { class Toaster {

Loading…
Cancel
Save