From 838f0caad0b2f5cbea97332a1624b25abd0d55b0 Mon Sep 17 00:00:00 2001 From: ioedeveloper Date: Tue, 26 Oct 2021 03:52:48 +0100 Subject: [PATCH] Fixed getCurrentWorkspace and getWorkspaces api --- apps/remix-ide/src/app/panels/file-panel.js | 3 ++- libs/remix-ui/workspace/src/lib/actions/index.ts | 12 ++++++++---- .../workspace/src/lib/actions/payload.ts | 9 +++------ .../workspace/src/lib/actions/workspace.ts | 16 +++++++++------- 4 files changed, 22 insertions(+), 18 deletions(-) diff --git a/apps/remix-ide/src/app/panels/file-panel.js b/apps/remix-ide/src/app/panels/file-panel.js index 6e88ef9ebe..7e782703ae 100644 --- a/apps/remix-ide/src/app/panels/file-panel.js +++ b/apps/remix-ide/src/app/panels/file-panel.js @@ -102,7 +102,7 @@ module.exports = class Filepanel extends ViewPlugin { } setWorkspaces (workspaces) { - this.worspaces = workspaces + this.workspaces = workspaces } createNewFile () { @@ -146,6 +146,7 @@ module.exports = class Filepanel extends ViewPlugin { const workspaceProvider = this.fileProviders.workspace this.currentWorkspaceMetadata = { name: workspace.name, isLocalhost: workspace.isLocalhost, absolutePath: `${workspaceProvider.workspacesPath}/${workspace.name}` } + this.emit('setWorkspace', workspace) } workspaceDeleted (workspace) { diff --git a/libs/remix-ui/workspace/src/lib/actions/index.ts b/libs/remix-ui/workspace/src/lib/actions/index.ts index 0fe53acb28..e84e4d641a 100644 --- a/libs/remix-ui/workspace/src/lib/actions/index.ts +++ b/libs/remix-ui/workspace/src/lib/actions/index.ts @@ -28,20 +28,24 @@ export const initWorkspace = (filePanelPlugin) => async (reducerDispatch: React. if (params.gist) { await createWorkspaceTemplate('gist-sample', 'gist-template') await loadWorkspacePreset('gist-template') - dispatch(setCurrentWorkspace('gist-sample', plugin)) + plugin.setWorkspace({ name: 'gist-sample', isLocalhost: false }) + dispatch(setCurrentWorkspace('gist-sample')) } else if (params.code || params.url) { await createWorkspaceTemplate('code-sample', 'code-template') await loadWorkspacePreset('code-template') - dispatch(setCurrentWorkspace('code-sample', plugin)) + plugin.setWorkspace({ name: 'code-sample', isLocalhost: false }) + dispatch(setCurrentWorkspace('code-sample')) } else { if (workspaces.length === 0) { await createWorkspaceTemplate('default_workspace', 'default-template') await loadWorkspacePreset('default-template') - dispatch(setCurrentWorkspace('default_workspace', plugin)) + plugin.setWorkspace({ name: 'default_workspace', isLocalhost: false }) + dispatch(setCurrentWorkspace('default_workspace')) } else { if (workspaces.length > 0) { workspaceProvider.setWorkspace(workspaces[workspaces.length - 1]) - dispatch(setCurrentWorkspace(workspaces[workspaces.length - 1], plugin)) + plugin.setWorkspace({ name: workspaces[workspaces.length - 1], isLocalhost: false }) + dispatch(setCurrentWorkspace(workspaces[workspaces.length - 1])) } } } diff --git a/libs/remix-ui/workspace/src/lib/actions/payload.ts b/libs/remix-ui/workspace/src/lib/actions/payload.ts index c7145849c1..2a949e399d 100644 --- a/libs/remix-ui/workspace/src/lib/actions/payload.ts +++ b/libs/remix-ui/workspace/src/lib/actions/payload.ts @@ -1,7 +1,6 @@ import { action } from '../types' -export const setCurrentWorkspace = (workspace: string, plugin?) => { - plugin && plugin.setWorkspace(workspace) +export const setCurrentWorkspace = (workspace: string) => { return { type: 'SET_CURRENT_WORKSPACE', payload: workspace @@ -126,8 +125,7 @@ export const createWorkspaceRequest = (promise: Promise) => { } } -export const createWorkspaceSuccess = (workspaceName: string, plugin?) => { - plugin && plugin.setWorkspace(workspaceName) +export const createWorkspaceSuccess = (workspaceName: string) => { return { type: 'CREATE_WORKSPACE_SUCCESS', payload: workspaceName @@ -155,8 +153,7 @@ export const fetchWorkspaceDirectorySuccess = (path: string, fileTree) => { } } -export const setRenameWorkspace = (oldName: string, workspaceName: string, plugin?) => { - plugin && plugin.setWorkspace(workspaceName) +export const setRenameWorkspace = (oldName: string, workspaceName: string) => { return { type: 'RENAME_WORKSPACE', payload: { oldName, workspaceName } diff --git a/libs/remix-ui/workspace/src/lib/actions/workspace.ts b/libs/remix-ui/workspace/src/lib/actions/workspace.ts index c99ea9f601..a26fc65835 100644 --- a/libs/remix-ui/workspace/src/lib/actions/workspace.ts +++ b/libs/remix-ui/workspace/src/lib/actions/workspace.ts @@ -45,9 +45,9 @@ export const createWorkspace = async (workspaceName: string, isEmpty = false, cb dispatch(createWorkspaceRequest(promise)) promise.then(async () => { - dispatch(createWorkspaceSuccess(workspaceName, plugin)) + dispatch(createWorkspaceSuccess(workspaceName)) if (!isEmpty) await loadWorkspacePreset('default-template') - plugin.emit('setWorkspace', { name: workspaceName, isLocalhost: false }) + plugin.setWorkspace({ name: workspaceName, isLocalhost: false }) plugin.setWorkspaces(await getWorkspaces()) cb && cb(null, workspaceName) }).catch((error) => { @@ -173,7 +173,8 @@ export const fetchWorkspaceDirectory = async (path: string) => { export const renameWorkspace = async (oldName: string, workspaceName: string) => { await renameWorkspaceFromProvider(oldName, workspaceName) - await dispatch(setRenameWorkspace(oldName, workspaceName, plugin)) + await dispatch(setRenameWorkspace(oldName, workspaceName)) + plugin.setWorkspace({ name: workspaceName, isLocalhost: false }) } export const renameWorkspaceFromProvider = async (oldName: string, workspaceName: string) => { @@ -195,19 +196,20 @@ export const switchToWorkspace = async (name: string) => { if (!isActive) await plugin.call('manager', 'activatePlugin', 'remixd') dispatch(setMode('localhost')) - plugin.emit('setWorkspace', { name: LOCALHOST, isLocalhost: true }) + plugin.emit('setWorkspace', { name: null, isLocalhost: true }) } else if (name === NO_WORKSPACE) { plugin.fileProviders.workspace.clearWorkspace() - dispatch(setCurrentWorkspace(null, plugin)) + plugin.setWorkspace({ name: null, isLocalhost: false }) + dispatch(setCurrentWorkspace(null)) } else { const isActive = await plugin.call('manager', 'isActive', 'remixd') if (isActive) plugin.call('manager', 'deactivatePlugin', 'remixd') await plugin.fileProviders.workspace.setWorkspace(name) + plugin.setWorkspace({ name, isLocalhost: false }) dispatch(setMode('browser')) - dispatch(setCurrentWorkspace(name, plugin)) + dispatch(setCurrentWorkspace(name)) dispatch(setReadOnlyMode(false)) - plugin.emit('setWorkspace', { name, isLocalhost: false }) } }