Changed Set & exists api to async

pull/5370/head
ioedeveloper 4 years ago
parent 4d8cce1202
commit 0af470fe3a
  1. 13
      apps/remix-ide/src/app/files/file-explorer.js
  2. 2
      apps/remix-ide/src/app/files/fileProvider.js
  3. 33
      apps/remix-ide/src/app/files/remixDProvider.js
  4. 1
      apps/remix-ide/src/app/ui/TreeView.js

@ -102,9 +102,9 @@ function fileExplorer (localRegistry, files, menuItems) {
function fileAdded (filepath) { function fileAdded (filepath) {
self.ensureRoot(() => { self.ensureRoot(() => {
var folderpath = filepath.split('/').slice(0, -1).join('/') const folderpath = filepath.split('/').slice(0, -1).join('/')
const currentTree = self.treeView.nodeAt(folderpath)
var currentTree = self.treeView.nodeAt(folderpath)
if (currentTree && self.treeView.isExpanded(folderpath)) { if (currentTree && self.treeView.isExpanded(folderpath)) {
self.files.resolveDirectory(folderpath, (error, fileTree) => { self.files.resolveDirectory(folderpath, (error, fileTree) => {
if (error) console.error(error) if (error) console.error(error)
@ -130,8 +130,11 @@ function fileExplorer (localRegistry, files, menuItems) {
function folderAdded (folderpath) { function folderAdded (folderpath) {
self.ensureRoot(() => { self.ensureRoot(() => {
console.log('called: ensureRoot')
folderpath = folderpath.split('/').slice(0, -1).join('/') folderpath = folderpath.split('/').slice(0, -1).join('/')
console.log('folderpath: ', folderpath)
self.files.resolveDirectory(folderpath, (error, fileTree) => { self.files.resolveDirectory(folderpath, (error, fileTree) => {
console.log('fileTree: ', fileTree)
if (error) console.error(error) if (error) console.error(error)
if (!fileTree) return if (!fileTree) return
fileTree = normalize(folderpath, fileTree) fileTree = normalize(folderpath, fileTree)
@ -435,12 +438,12 @@ fileExplorer.prototype.uploadFile = function (event) {
let files = this.files let files = this.files
function loadFile () { function loadFile () {
var fileReader = new FileReader() var fileReader = new FileReader()
fileReader.onload = function (event) { fileReader.onload = async function (event) {
if (helper.checkSpecialChars(file.name)) { if (helper.checkSpecialChars(file.name)) {
modalDialogCustom.alert('Special characters are not allowed') modalDialogCustom.alert('Special characters are not allowed')
return return
} }
var success = files.set(name, event.target.result) var success = await files.set(name, event.target.result)
if (!success) { if (!success) {
modalDialogCustom.alert('Failed to create file ' + name) modalDialogCustom.alert('Failed to create file ' + name)
} else { } else {

@ -221,6 +221,8 @@ class FileProvider {
window.remixFileSystem.readdir(path, (error, files) => { window.remixFileSystem.readdir(path, (error, files) => {
var ret = {} var ret = {}
console.log('files: ', files)
if (files) { if (files) {
files.forEach(element => { files.forEach(element => {
const absPath = (path === '/' ? '' : path) + '/' + element const absPath = (path === '/' ? '' : path) + '/' + element

@ -77,9 +77,11 @@ module.exports = class RemixDProvider {
return this._appManager.call('remixd', 'exists', { path: unprefixedpath }) return this._appManager.call('remixd', 'exists', { path: unprefixedpath })
.then((result) => { .then((result) => {
return cb(null, result) if(cb) return cb(null, result)
return result
}).catch((error) => { }).catch((error) => {
return cb(error) if(cb) return cb(error)
throw new Error(error)
}) })
} }
@ -106,15 +108,26 @@ module.exports = class RemixDProvider {
}) })
} }
set (path, content, cb) { async set (path, content, cb) {
const unprefixedpath = this.removePrefix(path) const unprefixedpath = this.removePrefix(path)
this._appManager.call('remixd', 'set', {path: unprefixedpath, content: content}).then((result) => { const exists = await this.exists(path)
if (cb) return cb(null, result)
return this._appManager.call('remixd', 'set', { path: unprefixedpath, content: content }).then(async (result) => {
const path = this.type + '/' + unprefixedpath const path = this.type + '/' + unprefixedpath
this.event.trigger('fileChanged', [path])
if (!exists) {
const isDirectory = await this.isDirectory(path)
if (isDirectory) this.event.trigger('folderAdded', [path])
else this.event.trigger('fileAdded', [path])
} else {
this.event.trigger('fileChanged', [path])
}
if (cb) return cb(null, result)
}).catch((error) => { }).catch((error) => {
if (cb) cb(error) if (cb) return cb(error)
throw new Error(error)
}) })
} }
@ -127,7 +140,6 @@ module.exports = class RemixDProvider {
const unprefixedpath = this.removePrefix(path) const unprefixedpath = this.removePrefix(path)
this._appManager.call('remixd', 'remove', { path: unprefixedpath }) this._appManager.call('remixd', 'remove', { path: unprefixedpath })
.then(result => { .then(result => {
console.log('result: ', result)
const path = this.type + '/' + unprefixedpath const path = this.type + '/' + unprefixedpath
delete this.filesContent[path] delete this.filesContent[path]
@ -179,7 +191,10 @@ module.exports = class RemixDProvider {
if (path[0] === '/') path = path.substring(1) if (path[0] === '/') path = path.substring(1)
if (!path) return callback(null, { [self.type]: { } }) if (!path) return callback(null, { [self.type]: { } })
const unprefixedpath = this.removePrefix(path) const unprefixedpath = this.removePrefix(path)
this._appManager.call('remixd', 'resolveDirectory', {path: unprefixedpath}).then((result) => callback(null, result)).catch(callback) this._appManager.call('remixd', 'resolveDirectory', { path: unprefixedpath }).then((result) => {
console.log('result: ', result)
callback(null, result)
}).catch(callback)
} }
async isDirectory (path) { async isDirectory (path) {

@ -152,6 +152,7 @@ class TreeView {
} }
nodeAt (path) { nodeAt (path) {
console.log('nodeAt path: ', path)
return this.view.querySelector(`ul[key="${path}"]`) return this.view.querySelector(`ul[key="${path}"]`)
} }

Loading…
Cancel
Save