From a584dd6961bc21be4f0b3617d99e56222a82c281 Mon Sep 17 00:00:00 2001 From: bunsenstraat Date: Sat, 30 Oct 2021 12:24:31 +0200 Subject: [PATCH] gist fix --- apps/remix-ide/src/app/files/fileManager.js | 61 +++++++++---------- apps/remix-ide/src/lib/gist-handler.js | 4 +- .../workspace/src/lib/actions/index.ts | 6 +- .../workspace/src/lib/actions/workspace.ts | 2 +- 4 files changed, 34 insertions(+), 39 deletions(-) diff --git a/apps/remix-ide/src/app/files/fileManager.js b/apps/remix-ide/src/app/files/fileManager.js index 15af51c52d..eb44ac2517 100644 --- a/apps/remix-ide/src/app/files/fileManager.js +++ b/apps/remix-ide/src/app/files/fileManager.js @@ -725,12 +725,12 @@ class FileManager extends Plugin { } } - syncEditor (path) { + async syncEditor (path) { var currentFile = this._deps.config.get('currentFile') if (path !== currentFile) return var provider = this.fileProviderOf(currentFile) if (provider) { - provider.get(currentFile, (error, content) => { + await provider.get(currentFile, (error, content) => { if (error) console.log(error) this.editor.setText(content) }) @@ -739,42 +739,37 @@ class FileManager extends Plugin { } } - setBatchFiles (filesSet, fileProvider, override, callback) { + async setBatchFiles (filesSet, fileProvider, override, callback) { const self = this - if (!fileProvider) fileProvider = 'browser' + if (!fileProvider) fileProvider = 'workspace' if (override === undefined) override = false - async.each(Object.keys(filesSet), async (file, callback) => { + for (const file of Object.keys(filesSet)) { if (override) { - try { - await self._deps.filesProviders[fileProvider].set(file, filesSet[file].content) - } catch (e) { - return callback(e.message || e) - } - self.syncEditor(fileProvider + file) - return callback() - } - - helper.createNonClashingName(file, self._deps.filesProviders[fileProvider], - async (error, name) => { - if (error) { - modalDialogCustom.alert('Unexpected error loading the file ' + error) - } else if (helper.checkSpecialChars(name)) { - modalDialogCustom.alert('Special characters are not allowed') - } else { - try { - console.log('set ', fileProvider, name, filesSet[file].content) - await self._deps.filesProviders[fileProvider].set(name, filesSet[file].content) - } catch (e) { - return callback(e.message || e) - } - self.syncEditor(fileProvider + name) - } - callback() + await self._deps.filesProviders[fileProvider].set(file, filesSet[file].content, (e) => { + if (e) callback(e.message || e) }) - }, (error) => { - if (callback) callback(error) - }) + await self.syncEditor(fileProvider + file) + } else { + helper.createNonClashingName(file, self._deps.filesProviders[fileProvider], + async (error, name) => { + if (error) { + modalDialogCustom.alert('Unexpected error loading the file ' + error) + } else if (helper.checkSpecialChars(name)) { + modalDialogCustom.alert('Special characters are not allowed') + } else { + try { + console.log('set ', fileProvider, name, filesSet[file].content) + await self._deps.filesProviders[fileProvider].set(name, filesSet[file].content) + } catch (e) { + return callback(e.message || e) + } + await self.syncEditor(fileProvider + name) + } + callback() + }) + } + }x } currentWorkspace () { diff --git a/apps/remix-ide/src/lib/gist-handler.js b/apps/remix-ide/src/lib/gist-handler.js index 6772cdc2ca..386b779b48 100644 --- a/apps/remix-ide/src/lib/gist-handler.js +++ b/apps/remix-ide/src/lib/gist-handler.js @@ -58,8 +58,8 @@ function GistHandler (_window) { obj['/' + 'gist-' + gistId + '/' + path] = data.files[element] }) - console.log('loading gist', obj) - fileManager.setBatchFiles(obj, 'workspace', true, (errorLoadingFile) => { + + await fileManager.setBatchFiles(obj, 'workspace', true, (errorLoadingFile) => { if (!errorLoadingFile) { console.log('gist loaded') const provider = fileManager.getProvider('workspace') diff --git a/libs/remix-ui/workspace/src/lib/actions/index.ts b/libs/remix-ui/workspace/src/lib/actions/index.ts index 390a1ff44d..01e211edcb 100644 --- a/libs/remix-ui/workspace/src/lib/actions/index.ts +++ b/libs/remix-ui/workspace/src/lib/actions/index.ts @@ -255,10 +255,10 @@ export const handleExpandPath = (paths: string[]) => { dispatch(setExpandPath(paths)) } -const packageGistFiles = (directory) => { +const packageGistFiles = async (directory) => { + const workspaceProvider = plugin.fileProviders.workspace + const isFile = await workspaceProvider.isFile(directory) return new Promise((resolve, reject) => { - const workspaceProvider = plugin.fileProviders.workspace - const isFile = workspaceProvider.isFile(directory) const ret = {} if (isFile) { diff --git a/libs/remix-ui/workspace/src/lib/actions/workspace.ts b/libs/remix-ui/workspace/src/lib/actions/workspace.ts index 497a40b286..ba2afaa8ff 100644 --- a/libs/remix-ui/workspace/src/lib/actions/workspace.ts +++ b/libs/remix-ui/workspace/src/lib/actions/workspace.ts @@ -116,7 +116,7 @@ export const loadWorkspacePreset = async (template: 'gist-template' | 'code-temp obj['/' + 'gist-' + gistId + '/' + path] = data.files[element] }) - plugin.fileManager.setBatchFiles(obj, 'workspace', true, (errorLoadingFile) => { + await plugin.fileManager.setBatchFiles(obj, 'workspace', true, (errorLoadingFile) => { if (!errorLoadingFile) { const provider = plugin.fileManager.getProvider('workspace')