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) { setWorkspaces (workspaces) {
this.worspaces = workspaces this.workspaces = workspaces
} }
createNewFile () { createNewFile () {
@ -146,6 +146,7 @@ module.exports = class Filepanel extends ViewPlugin {
const workspaceProvider = this.fileProviders.workspace const workspaceProvider = this.fileProviders.workspace
this.currentWorkspaceMetadata = { name: workspace.name, isLocalhost: workspace.isLocalhost, absolutePath: `${workspaceProvider.workspacesPath}/${workspace.name}` } this.currentWorkspaceMetadata = { name: workspace.name, isLocalhost: workspace.isLocalhost, absolutePath: `${workspaceProvider.workspacesPath}/${workspace.name}` }
this.emit('setWorkspace', workspace)
} }
workspaceDeleted (workspace) { workspaceDeleted (workspace) {

@ -28,20 +28,24 @@ export const initWorkspace = (filePanelPlugin) => async (reducerDispatch: React.
if (params.gist) { if (params.gist) {
await createWorkspaceTemplate('gist-sample', 'gist-template') await createWorkspaceTemplate('gist-sample', 'gist-template')
await loadWorkspacePreset('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) { } else if (params.code || params.url) {
await createWorkspaceTemplate('code-sample', 'code-template') await createWorkspaceTemplate('code-sample', 'code-template')
await loadWorkspacePreset('code-template') await loadWorkspacePreset('code-template')
dispatch(setCurrentWorkspace('code-sample', plugin)) plugin.setWorkspace({ name: 'code-sample', isLocalhost: false })
dispatch(setCurrentWorkspace('code-sample'))
} else { } else {
if (workspaces.length === 0) { if (workspaces.length === 0) {
await createWorkspaceTemplate('default_workspace', 'default-template') await createWorkspaceTemplate('default_workspace', 'default-template')
await loadWorkspacePreset('default-template') await loadWorkspacePreset('default-template')
dispatch(setCurrentWorkspace('default_workspace', plugin)) plugin.setWorkspace({ name: 'default_workspace', isLocalhost: false })
dispatch(setCurrentWorkspace('default_workspace'))
} else { } else {
if (workspaces.length > 0) { if (workspaces.length > 0) {
workspaceProvider.setWorkspace(workspaces[workspaces.length - 1]) 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' import { action } from '../types'
export const setCurrentWorkspace = (workspace: string, plugin?) => { export const setCurrentWorkspace = (workspace: string) => {
plugin && plugin.setWorkspace(workspace)
return { return {
type: 'SET_CURRENT_WORKSPACE', type: 'SET_CURRENT_WORKSPACE',
payload: workspace payload: workspace
@ -126,8 +125,7 @@ export const createWorkspaceRequest = (promise: Promise<any>) => {
} }
} }
export const createWorkspaceSuccess = (workspaceName: string, plugin?) => { export const createWorkspaceSuccess = (workspaceName: string) => {
plugin && plugin.setWorkspace(workspaceName)
return { return {
type: 'CREATE_WORKSPACE_SUCCESS', type: 'CREATE_WORKSPACE_SUCCESS',
payload: workspaceName payload: workspaceName
@ -155,8 +153,7 @@ export const fetchWorkspaceDirectorySuccess = (path: string, fileTree) => {
} }
} }
export const setRenameWorkspace = (oldName: string, workspaceName: string, plugin?) => { export const setRenameWorkspace = (oldName: string, workspaceName: string) => {
plugin && plugin.setWorkspace(workspaceName)
return { return {
type: 'RENAME_WORKSPACE', type: 'RENAME_WORKSPACE',
payload: { oldName, workspaceName } payload: { oldName, workspaceName }

@ -45,9 +45,9 @@ export const createWorkspace = async (workspaceName: string, isEmpty = false, cb
dispatch(createWorkspaceRequest(promise)) dispatch(createWorkspaceRequest(promise))
promise.then(async () => { promise.then(async () => {
dispatch(createWorkspaceSuccess(workspaceName, plugin)) dispatch(createWorkspaceSuccess(workspaceName))
if (!isEmpty) await loadWorkspacePreset('default-template') if (!isEmpty) await loadWorkspacePreset('default-template')
plugin.emit('setWorkspace', { name: workspaceName, isLocalhost: false }) plugin.setWorkspace({ name: workspaceName, isLocalhost: false })
plugin.setWorkspaces(await getWorkspaces()) plugin.setWorkspaces(await getWorkspaces())
cb && cb(null, workspaceName) cb && cb(null, workspaceName)
}).catch((error) => { }).catch((error) => {
@ -173,7 +173,8 @@ export const fetchWorkspaceDirectory = async (path: string) => {
export const renameWorkspace = async (oldName: string, workspaceName: string) => { export const renameWorkspace = async (oldName: string, workspaceName: string) => {
await renameWorkspaceFromProvider(oldName, workspaceName) 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) => { 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') if (!isActive) await plugin.call('manager', 'activatePlugin', 'remixd')
dispatch(setMode('localhost')) dispatch(setMode('localhost'))
plugin.emit('setWorkspace', { name: LOCALHOST, isLocalhost: true }) plugin.emit('setWorkspace', { name: null, isLocalhost: true })
} else if (name === NO_WORKSPACE) { } else if (name === NO_WORKSPACE) {
plugin.fileProviders.workspace.clearWorkspace() plugin.fileProviders.workspace.clearWorkspace()
dispatch(setCurrentWorkspace(null, plugin)) plugin.setWorkspace({ name: null, isLocalhost: false })
dispatch(setCurrentWorkspace(null))
} else { } else {
const isActive = await plugin.call('manager', 'isActive', 'remixd') const isActive = await plugin.call('manager', 'isActive', 'remixd')
if (isActive) plugin.call('manager', 'deactivatePlugin', 'remixd') if (isActive) plugin.call('manager', 'deactivatePlugin', 'remixd')
await plugin.fileProviders.workspace.setWorkspace(name) await plugin.fileProviders.workspace.setWorkspace(name)
plugin.setWorkspace({ name, isLocalhost: false })
dispatch(setMode('browser')) dispatch(setMode('browser'))
dispatch(setCurrentWorkspace(name, plugin)) dispatch(setCurrentWorkspace(name))
dispatch(setReadOnlyMode(false)) dispatch(setReadOnlyMode(false))
plugin.emit('setWorkspace', { name, isLocalhost: false })
} }
} }

Loading…
Cancel
Save