Save the current gist instead of creating a new one over and over

pull/1/head
yann300 7 years ago
parent 0ced992b3b
commit c953633b2a
  1. 7
      src/app.js
  2. 54
      src/app/panels/file-panel.js

@ -556,7 +556,7 @@ Please make a backup of your contracts and start using http://remix.ethereum.org
})
// Add files received from remote instance (i.e. another remix-ide)
function loadFiles (filesSet, fileProvider) {
function loadFiles (filesSet, fileProvider, callback) {
if (!fileProvider) fileProvider = 'browser'
async.each(Object.keys(filesSet), (file, callback) => {
@ -573,6 +573,7 @@ Please make a backup of your contracts and start using http://remix.ethereum.org
})
}, (error) => {
if (!error) fileManager.switchFile()
if (callback) callback(error)
})
}
@ -597,7 +598,9 @@ Please make a backup of your contracts and start using http://remix.ethereum.org
modalDialogCustom.alert(`Gist load error: ${error || data.message}`)
return
}
loadFiles(data.files, 'gist')
loadFiles(data.files, 'gist', (errorLoadingFile) => {
if (!errorLoadingFile) filesProviders['gist'].id = gistId
})
})
})
}

@ -8,6 +8,7 @@ var EventManager = remixLib.EventManager
var FileExplorer = require('../files/file-explorer')
var modalDialog = require('../ui/modaldialog')
var modalDialogCustom = require('../ui/modal-dialog-custom')
var tooltip = require('../ui/tooltip')
var QueryParams = require('../../lib/query-params')
var queryParams = new QueryParams()
var helper = require('../../lib/helper')
@ -80,10 +81,10 @@ function filepanel (appAPI, filesProvider) {
</label>
</span>
` : ''}
<span class="${css.gist}" title="Publish all [browser] explorer open files to an anonymous github gist" onclick=${() => publishToGist('browser')}>
<span class="${css.gist}" title="Publish all [browser] explorer files to a github gist" onclick=${() => publishToGist('browser')}>
<i class="fa fa-github"></i>
</span>
<span class="${css.gist}" title="Publish all [gist] explorer open files to an anonymous github gist" onclick=${() => publishToGist('gist')}>
<span class="${css.gist}" title="Update the current [gist] explorer" onclick=${() => updateGist()}>
<i class="fa fa-github"></i>
</span>
<span class="${css.copyFiles}" title="Copy all files to another instance of Remix IDE" onclick=${copyFiles}>
@ -273,22 +274,22 @@ function filepanel (appAPI, filesProvider) {
// ------------------ gist publish --------------
function publishToGist (fileProviderName) {
function cb (error, data) {
if (error) {
modalDialogCustom.alert('Failed to create gist: ' + error)
} else {
if (data.html_url) {
modalDialogCustom.confirm(null, `Created a gist at ${data.html_url}. Would you like to open it in a new window?`, () => {
window.open(data.html_url, '_blank')
})
function updateGist () {
var gistId = filesProvider['gist'].id
if (!gistId) {
tooltip('no gist content is currently loaded.')
} else {
modalDialogCustom.alert(data.message + ' ' + data.documentation_url + ' ' + JSON.stringify(data.errors, null, '\t'))
toGist('gist', gistId)
}
}
function publishToGist (fileProviderName) {
modalDialogCustom.confirm(null, 'Are you very sure you want to publish all your files anonymously as a public gist on github.com?', () => {
toGist(fileProviderName)
})
}
function toGist () {
function toGist (fileProviderName, id) {
packageFiles(filesProvider[fileProviderName], (error, packaged) => {
if (error) {
console.log(error)
@ -302,6 +303,18 @@ function filepanel (appAPI, filesProvider) {
var gists = new Gists({
token: tokenAccess
})
if (id) {
tooltip('Saving gist (' + id + ') ...')
gists.edit({
description: description,
public: true,
files: packaged,
id: id
}, (error, result) => {
cb(error, result)
})
} else {
tooltip('Creating a new gist ...')
gists.create({
description: description,
public: true,
@ -311,11 +324,22 @@ function filepanel (appAPI, filesProvider) {
})
}
}
}
})
}
modalDialogCustom.confirm(null, 'Are you very sure you want to publish all your files anonymously as a public gist on github.com?', () => {
toGist()
function cb (error, data) {
if (error) {
modalDialogCustom.alert('Failed to manage gist: ' + error)
} else {
if (data.html_url) {
modalDialogCustom.confirm(null, `The gist is at ${data.html_url}. Would you like to open it in a new window?`, () => {
window.open(data.html_url, '_blank')
})
} else {
modalDialogCustom.alert(data.message + ' ' + data.documentation_url + ' ' + JSON.stringify(data.errors, null, '\t'))
}
}
}
// ------------------ copy files --------------

Loading…
Cancel
Save