// modalDialogCustom.alert('Failed to create file ' + name)
}else{
props.addFile(props.title,name)
awaitprops.fileManager.open(name)
}
}
fileReader.readAsText(file)
}
constname=files.type+'/'+file.name
files.exists(name,(error,exist)=>{
if(error)console.log(error)
if(!exist){
loadFile(name)
}else{
// modalDialogCustom.confirm('Confirm overwrite', `The file ${name} already exists! Would you like to overwrite it?`, () => { loadFile() })
}
})
})
}
constpublishToGist=()=>{
// modalDialogCustom.confirm(
// 'Create a public gist',
// 'Are you sure you want to publish all your files in browser directory anonymously as a public gist on github.com? Note: this will not include directories.',
// () => { this.toGist() }
toGist()
// )
}
consttoGist=(id?: string)=>{
constproccedResult=function(error,data){
if(error){
// modalDialogCustom.alert('Failed to manage gist: ' + error)
console.log('Failed to manage gist: '+error)
}else{
if(data.html_url){
// modalDialogCustom.confirm('Gist is ready', `The gist is at ${data.html_url}. Would you like to open it in a new window?`, () => {
// modalDialogCustom.alert('Failed to create gist: ' + error.message)
}else{
// check for token
if(!props.accessToken){
// modalDialogCustom.alert(
// 'Remix requires an access token (which includes gists creation permission). Please go to the settings tab to create one.'
// )
}else{
constdescription='Created using remix-ide: Realtime Ethereum Contract Compiler and Runtime. \n Load this file by pasting this gists URL or ID at https://remix.ethereum.org/#version='+
modal('File Upload Failed','Failed to create file '+name,{
label:'Close',
fn: async()=>{}
},null)
}
}
fileReader.readAsText(file)
}
constname=files.type+'/'+file.name
files.exists(name,(error,exist)=>{
if(error)console.log(error)
if(!exist){
loadFile(name)
}else{
modal('Confirm overwrite',`The file ${name} already exists! Would you like to overwrite it?`,{
label:'Ok',
fn:()=>{
loadFile(name)
}
},{
label:'Cancel',
fn:()=>{}
})
}
})
})
}
constpublishToGist=()=>{
modal('Create a public gist','Are you sure you want to publish all your files in browser directory anonymously as a public gist on github.com? Note: this will not include directories.',{
label:'Ok',
fn: toGist
},{
label:'Cancel',
fn:()=>{}
})
}
consttoGist=(id?: string)=>{
constproccedResult=function(error,data){
if(error){
modal('Publish to gist Failed','Failed to manage gist: '+error,{
label:'Close',
fn: async()=>{}
},null)
}else{
if(data.html_url){
modal('Gist is ready',`The gist is at ${data.html_url}. Would you like to open it in a new window?`,{
label:'Ok',
fn:()=>{
window.open(data.html_url,'_blank')
}
},{
label:'Cancel',
fn:()=>{}
})
}else{
modal('Publish to gist Failed',data.message+' '+data.documentation_url+' '+JSON.stringify(data.errors,null,'\t'),{
label:'Close',
fn: async()=>{}
},null)
}
}
}
/**
*Thisfunctionistogettheoriginalcontentofgivengist
*@paramsidisthegistidtofetch
*/
constgetOriginalFiles=async(id)=>{
if(!id){
return[]
}
consturl=`https://api.github.com/gists/${id}`
constres=awaitfetch(url)
constdata=awaitres.json()
returndata.files||[]
}
// If 'id' is not defined, it is not a gist update but a creation so we have to take the files from the browser explorer.
modal('Publish to gist Failed','Failed to create gist: '+error.message,{
label:'Close',
fn: async()=>{}
},null)
}else{
// check for token
if(!state.accessToken){
modal('Authorize Token','Remix requires an access token (which includes gists creation permission). Please go to the settings tab to create one.',{
label:'Close',
fn: async()=>{}
},null)
}else{
constdescription='Created using remix-ide: Realtime Ethereum Contract Compiler and Runtime. \n Load this file by pasting this gists URL or ID at https://remix.ethereum.org/#version='+