From 4b3dec02a93b8d46e9bc3a9eb785865739f9d447 Mon Sep 17 00:00:00 2001 From: ioedeveloper Date: Wed, 13 Oct 2021 20:45:59 +0100 Subject: [PATCH] Implemented requested changes in PR comments --- apps/remix-ide/src/app/files/fileManager.js | 38 ++++---- apps/remix-ide/src/app/panels/file-panel.js | 6 +- .../workspace/src/lib/actions/events.ts | 88 +++++++++---------- .../workspace/src/lib/actions/index.ts | 8 +- .../workspace/src/lib/actions/workspace.ts | 7 +- .../src/lib/components/file-explorer.tsx | 4 +- 6 files changed, 66 insertions(+), 85 deletions(-) diff --git a/apps/remix-ide/src/app/files/fileManager.js b/apps/remix-ide/src/app/files/fileManager.js index 494957c63e..07fe178c5e 100644 --- a/apps/remix-ide/src/app/files/fileManager.js +++ b/apps/remix-ide/src/app/files/fileManager.js @@ -456,32 +456,26 @@ class FileManager extends Plugin { return this._deps.config.get('currentFile') } - closeAllFiles () { + async closeAllFiles () { // TODO: Only keep `this.emit` (issue#2210) - return new Promise((resolve) => { - this.emit('filesAllClosed') - this.events.emit('filesAllClosed') - for (const file in this.openedFiles) { - this.closeFile(file) - } - resolve(true) - }) + this.emit('filesAllClosed') + this.events.emit('filesAllClosed') + for (const file in this.openedFiles) { + this.closeFile(file) + } } - closeFile (name) { - return new Promise((resolve) => { - delete this.openedFiles[name] - if (!Object.keys(this.openedFiles).length) { - this._deps.config.set('currentFile', '') - // TODO: Only keep `this.emit` (issue#2210) - this.emit('noFileSelected') - this.events.emit('noFileSelected') - } + async closeFile (name) { + delete this.openedFiles[name] + if (!Object.keys(this.openedFiles).length) { + this._deps.config.set('currentFile', '') // TODO: Only keep `this.emit` (issue#2210) - this.emit('fileClosed', name) - this.events.emit('fileClosed', name) - resolve(true) - }) + this.emit('noFileSelected') + this.events.emit('noFileSelected') + } + // TODO: Only keep `this.emit` (issue#2210) + this.emit('fileClosed', name) + this.events.emit('fileClosed', name) } currentPath () { diff --git a/apps/remix-ide/src/app/panels/file-panel.js b/apps/remix-ide/src/app/panels/file-panel.js index 0ab6c0dbc4..6cc57923dc 100644 --- a/apps/remix-ide/src/app/panels/file-panel.js +++ b/apps/remix-ide/src/app/panels/file-panel.js @@ -54,7 +54,7 @@ module.exports = class Filepanel extends ViewPlugin { this.slitherHandle = new SlitherHandle() this.workspaces = [] this.appManager = appManager - this.currentWorkspaceInfo = {} + this.currentWorkspaceMetadata = {} } onActivation () { @@ -84,7 +84,7 @@ module.exports = class Filepanel extends ViewPlugin { } getCurrentWorkspace () { - return this.currentWorkspaceInfo + return this.currentWorkspaceMetadata } getWorkspaces () { @@ -120,7 +120,7 @@ module.exports = class Filepanel extends ViewPlugin { setWorkspace (workspace) { const workspaceProvider = this.fileProviders.workspace - this.currentWorkspaceInfo = { name: workspace.name, isLocalhost: workspace.isLocalhost, absolutePath: `${workspaceProvider.workspacesPath}/${workspace.name}` } + this.currentWorkspaceMetadata = { name: workspace.name, isLocalhost: workspace.isLocalhost, absolutePath: `${workspaceProvider.workspacesPath}/${workspace.name}` } } workspaceDeleted (workspace) { diff --git a/libs/remix-ui/workspace/src/lib/actions/events.ts b/libs/remix-ui/workspace/src/lib/actions/events.ts index 13e8f4c636..5c0ab82cf4 100644 --- a/libs/remix-ui/workspace/src/lib/actions/events.ts +++ b/libs/remix-ui/workspace/src/lib/actions/events.ts @@ -11,31 +11,31 @@ export const listenOnPluginEvents = (filePanelPlugin) => { plugin = filePanelPlugin plugin.on('filePanel', 'createWorkspace', (name: string) => { - setTimeout(() => createWorkspace(name), 10) + createWorkspace(name) }) plugin.on('filePanel', 'renameWorkspace', (oldName: string, workspaceName: string) => { - setTimeout(() => renameWorkspace(oldName, workspaceName), 10) + renameWorkspace(oldName, workspaceName) }) plugin.on('filePanel', 'registerContextMenuItem', (item: action) => { - setTimeout(() => registerContextMenuItem(item), 10) + registerContextMenuItem(item) }) plugin.on('filePanel', 'removePluginActions', (plugin) => { - setTimeout(() => removePluginActions(plugin), 10) + removePluginActions(plugin) }) plugin.on('filePanel', 'displayNewFileInput', (path) => { - setTimeout(() => addInputField('file', path), 10) + addInputField('file', path) }) plugin.on('filePanel', 'uploadFileEvent', (dir: string, target) => { - setTimeout(() => uploadFile(target, dir), 10) + uploadFile(target, dir) }) plugin.on('remixd', 'rootFolderChanged', async (path: string) => { - setTimeout(() => rootFolderChanged(path), 10) + rootFolderChanged(path) }) } @@ -43,74 +43,66 @@ export const listenOnProviderEvents = (provider) => (reducerDispatch: React.Disp dispatch = reducerDispatch provider.event.on('fileAdded', (filePath: string) => { - setTimeout(() => fileAdded(filePath), 10) + fileAdded(filePath) }) provider.event.on('folderAdded', (folderPath: string) => { if (folderPath.indexOf('/.workspaces') === 0) return - setTimeout(() => folderAdded(folderPath), 10) + folderAdded(folderPath) }) provider.event.on('fileRemoved', (removePath: string) => { - setTimeout(() => fileRemoved(removePath), 10) + fileRemoved(removePath) }) provider.event.on('fileRenamed', (oldPath: string) => { - setTimeout(() => fileRenamed(oldPath), 10) + fileRenamed(oldPath) }) - provider.event.on('disconnected', () => { - setTimeout(async () => { - plugin.fileManager.setMode('browser') - dispatch(setMode('browser')) - dispatch(loadLocalhostError('Remixd disconnected!')) - const workspaceProvider = plugin.fileProviders.workspace + provider.event.on('disconnected', async () => { + plugin.fileManager.setMode('browser') + dispatch(setMode('browser')) + dispatch(loadLocalhostError('Remixd disconnected!')) + const workspaceProvider = plugin.fileProviders.workspace - await switchToWorkspace(workspaceProvider.workspace) - }, 10) + await switchToWorkspace(workspaceProvider.workspace) }) provider.event.on('connected', () => { - setTimeout(() => { - plugin.fileManager.setMode('localhost') - dispatch(setMode('localhost')) - fetchWorkspaceDirectory('/') - dispatch(loadLocalhostSuccess()) - }, 10) + plugin.fileManager.setMode('localhost') + dispatch(setMode('localhost')) + fetchWorkspaceDirectory('/') + dispatch(loadLocalhostSuccess()) }) - provider.event.on('loadingLocalhost', () => { - setTimeout(async () => { - await switchToWorkspace(LOCALHOST) - dispatch(loadLocalhostRequest()) - }, 10) + provider.event.on('loadingLocalhost', async () => { + await switchToWorkspace(LOCALHOST) + dispatch(loadLocalhostRequest()) }) provider.event.on('fileExternallyChanged', (path: string, content: string) => { - setTimeout(() => { - const config = plugin.registry.get('config').api - const editor = plugin.registry.get('editor').api - - if (config.get('currentFile') === path && editor.currentContent() !== content) { - if (provider.isReadOnly(path)) return editor.setText(content) - dispatch(displayNotification( - path + ' changed', - 'This file has been changed outside of Remix IDE.', - 'Replace by the new content', 'Keep the content displayed in Remix', - () => { - editor.setText(content) - } - )) - } - }, 10) + const config = plugin.registry.get('config').api + const editor = plugin.registry.get('editor').api + + if (config.get('currentFile') === path && editor.currentContent() !== content) { + if (provider.isReadOnly(path)) return editor.setText(content) + dispatch(displayNotification( + path + ' changed', + 'This file has been changed outside of Remix IDE.', + 'Replace by the new content', 'Keep the content displayed in Remix', + () => { + editor.setText(content) + } + )) + } }) provider.event.on('fileRenamedError', () => { - setTimeout(() => dispatch(displayNotification('File Renamed Failed', '', 'Ok', 'Cancel')), 10) + dispatch(displayNotification('File Renamed Failed', '', 'Ok', 'Cancel')) }) provider.event.on('readOnlyModeChanged', (mode: boolean) => { - setTimeout(() => dispatch(setReadOnlyMode(mode)), 10) + dispatch(setReadOnlyMode(mode)) }) } diff --git a/libs/remix-ui/workspace/src/lib/actions/index.ts b/libs/remix-ui/workspace/src/lib/actions/index.ts index 9e1ed6e07a..5b5e363da7 100644 --- a/libs/remix-ui/workspace/src/lib/actions/index.ts +++ b/libs/remix-ui/workspace/src/lib/actions/index.ts @@ -214,7 +214,6 @@ export const copyFile = async (src: string, dest: string) => { try { fileManager.copyFile(src, dest) } catch (error) { - console.log('Oops! An error ocurred while performing copyFile operation.' + error) dispatch(displayPopUp('Oops! An error ocurred while performing copyFile operation.' + error)) } } @@ -225,7 +224,6 @@ export const copyFolder = async (src: string, dest: string) => { try { fileManager.copyDir(src, dest) } catch (error) { - console.log('Oops! An error ocurred while performing copyDir operation.' + error) dispatch(displayPopUp('Oops! An error ocurred while performing copyDir operation.' + error)) } } @@ -235,8 +233,7 @@ export const runScript = async (path: string) => { provider.get(path, (error, content: string) => { if (error) { - dispatch(displayPopUp(error)) - return console.log(error) + return dispatch(displayPopUp(error)) } plugin.call('scriptRunner', 'execute', content) }) @@ -282,12 +279,11 @@ const getWorkspaces = async (): Promise | undefined => { plugin.setWorkspaces(workspaces) return workspaces } catch (e) { - // dispatch(displayNotification('Workspaces', 'Workspaces have not been created on your system. Please use "Migrate old filesystem to workspace" on the home page to transfer your files or start by creating a new workspace in the File Explorers.', 'OK', null, () => { dispatch(hideNotification()) }, null)) console.log(e) } } -const packageGistFiles = async (directory) => { +const packageGistFiles = (directory) => { return new Promise((resolve, reject) => { const workspaceProvider = plugin.fileProviders.workspace const isFile = workspaceProvider.isFile(directory) diff --git a/libs/remix-ui/workspace/src/lib/actions/workspace.ts b/libs/remix-ui/workspace/src/lib/actions/workspace.ts index 0e6c81273b..dca9c66c48 100644 --- a/libs/remix-ui/workspace/src/lib/actions/workspace.ts +++ b/libs/remix-ui/workspace/src/lib/actions/workspace.ts @@ -19,9 +19,9 @@ export const setPlugin = (filePanelPlugin, reducerDispatch) => { export const addInputField = async (type: 'file' | 'folder', path: string) => { const provider = plugin.fileManager.currentFileProvider() - const promise = new Promise((resolve) => { + const promise = new Promise((resolve, reject) => { provider.resolveDirectory(path, (error, fileTree) => { - if (error) console.error(error) + if (error) reject(error) resolve(fileTree) }) @@ -216,8 +216,7 @@ export const uploadFile = async (target, targetFolder: string) => { fileReader.onload = async function (event) { if (checkSpecialChars(file.name)) { - dispatch(displayNotification('File Upload Failed', 'Special characters are not allowed', 'Close', null, async () => {})) - return + return dispatch(displayNotification('File Upload Failed', 'Special characters are not allowed', 'Close', null, async () => {})) } const success = await workspaceProvider.set(name, event.target.result) diff --git a/libs/remix-ui/workspace/src/lib/components/file-explorer.tsx b/libs/remix-ui/workspace/src/lib/components/file-explorer.tsx index 4d844e1f09..5ec5ab9827 100644 --- a/libs/remix-ui/workspace/src/lib/components/file-explorer.tsx +++ b/libs/remix-ui/workspace/src/lib/components/file-explorer.tsx @@ -320,14 +320,14 @@ export const FileExplorer = (props: FileExplorerProps) => { if (state.focusEdit.isNew) { if (hasReservedKeyword(content)) { props.dispatchRemoveInputField(parentFolder) - props.modal('Reserved Keyword', `File name contains remix reserved keywords. '${content}'`, 'Close', () => {}) + props.modal('Reserved Keyword', `File name contains Remix reserved keywords. '${content}'`, 'Close', () => {}) } else { state.focusEdit.type === 'file' ? createNewFile(joinPath(parentFolder, content)) : createNewFolder(joinPath(parentFolder, content)) props.dispatchRemoveInputField(parentFolder) } } else { if (hasReservedKeyword(content)) { - props.modal('Reserved Keyword', `File name contains remix reserved keywords. '${content}'`, 'Close', () => {}) + props.modal('Reserved Keyword', `File name contains Remix reserved keywords. '${content}'`, 'Close', () => {}) } else { if (state.focusEdit.element) { const oldPath: string = state.focusEdit.element