Fixed getCurrentWorkspace and getWorkspaces api

pull/1575/head
ioedeveloper 3 years ago
parent b1e9fc98c5
commit 838f0caad0
  1. 3
      apps/remix-ide/src/app/panels/file-panel.js
  2. 12
      libs/remix-ui/workspace/src/lib/actions/index.ts
  3. 9
      libs/remix-ui/workspace/src/lib/actions/payload.ts
  4. 16
      libs/remix-ui/workspace/src/lib/actions/workspace.ts

@ -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) {

@ -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]))
}
}
}

@ -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<any>) => {
}
}
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 }

@ -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 })
}
}

Loading…
Cancel
Save