Fix workspace creation and switching

pull/5370/head
ioedeveloper 4 years ago committed by yann300
parent 532a96334d
commit 5c0a1b200e
  1. 3
      apps/remix-ide/src/app/panels/file-panel.js
  2. 34
      libs/remix-ui/workspace/src/lib/remix-ui-workspace.tsx

@ -85,7 +85,6 @@ module.exports = class Filepanel extends ViewPlugin {
request={this.request} request={this.request}
examples={examples} examples={examples}
workspaces={this.workspaces} workspaces={this.workspaces}
setWorkspaceName={this.setWorkspaceName}
registeredMenuItems={this.registeredMenuItems} registeredMenuItems={this.registeredMenuItems}
/> />
, this.el) , this.el)
@ -111,6 +110,7 @@ module.exports = class Filepanel extends ViewPlugin {
async getWorkspaces () { async getWorkspaces () {
const result = new Promise((resolve, reject) => { const result = new Promise((resolve, reject) => {
const workspacesPath = this._deps.fileProviders.workspace.workspacesPath const workspacesPath = this._deps.fileProviders.workspace.workspacesPath
this._deps.fileProviders.browser.resolveDirectory('/' + workspacesPath, (error, items) => { this._deps.fileProviders.browser.resolveDirectory('/' + workspacesPath, (error, items) => {
if (error) { if (error) {
console.error(error) console.error(error)
@ -185,7 +185,6 @@ module.exports = class Filepanel extends ViewPlugin {
} else if (await this.call('manager', 'isActive', 'remixd')) { } else if (await this.call('manager', 'isActive', 'remixd')) {
this.call('manager', 'deactivatePlugin', 'remixd') this.call('manager', 'deactivatePlugin', 'remixd')
} }
this.setWorkspaceName = workspace.name
this.emit('setWorkspace', workspace) this.emit('setWorkspace', workspace)
} }

@ -21,7 +21,6 @@ export interface WorkspaceProps {
plugin: any // plugin call and resetFocus plugin: any // plugin call and resetFocus
request: any // api request, request: any // api request,
workspaces: any, workspaces: any,
setWorkspaceName: string,
registeredMenuItems: [] // menu items registeredMenuItems: [] // menu items
} }
@ -48,10 +47,6 @@ export const Workspace = (props: WorkspaceProps) => {
return createWorkspace() return createWorkspace()
} }
// props.request.getWorkspaces = () => {
// return getWorkspaces()
// }
props.request.createNewFile = () => { props.request.createNewFile = () => {
props.plugin.resetNewFile() props.plugin.resetNewFile()
} }
@ -75,9 +70,8 @@ export const Workspace = (props: WorkspaceProps) => {
return { ...prevState, workspaces: props.workspaces, currentWorkspace: props.workspaces[0] } return { ...prevState, workspaces: props.workspaces, currentWorkspace: props.workspaces[0] }
}) })
} else { } else {
props.workspace.clearWorkspace()
setState(prevState => { setState(prevState => {
return { ...prevState, workspaces: props.workspaces, currentWorkspace: NO_WORKSPACE } return { ...prevState, workspaces: props.workspaces }
}) })
} }
} }
@ -86,12 +80,6 @@ export const Workspace = (props: WorkspaceProps) => {
getWorkspaces() getWorkspaces()
}, [props.workspaces]) }, [props.workspaces])
useEffect(() => {
if (props.setWorkspaceName && (props.setWorkspaceName !== state.currentWorkspace)) {
setWorkspace(props.setWorkspaceName)
}
}, [props.setWorkspaceName])
const [state, setState] = useState({ const [state, setState] = useState({
workspaces: [], workspaces: [],
reset: false, reset: false,
@ -162,16 +150,20 @@ export const Workspace = (props: WorkspaceProps) => {
} }
const onFinishCreateWorkspace = async () => { const onFinishCreateWorkspace = async () => {
if (!workspaceCreateInput.current) return if (workspaceCreateInput.current === undefined) return
// @ts-ignore: Object is possibly 'null'. // @ts-ignore: Object is possibly 'null'.
const workspaceName = workspaceCreateInput.current.value const workspaceName = workspaceCreateInput.current.value
const workspacesPath = props.workspace.workspacesPath const workspacesPath = props.workspace.workspacesPath
props.browser.createDir(workspacesPath + '/' + workspaceName, async () => { props.browser.createDir(workspacesPath + '/' + workspaceName, async () => {
setWorkspace(workspaceName)
for (const file in props.examples) { for (const file in props.examples) {
await props.fileManager.writeFile(`${props.examples[file].name}`, props.examples[file].content) try {
await props.fileManager.writeFile('browser/' + workspacesPath + '/' + workspaceName + '/' + props.examples[file].name, props.examples[file].content)
} catch (error) {
console.error(error)
}
} }
props.workspaceCreated({ name: state.currentWorkspace }) props.plugin.getWorkspaces()
}) })
} }
@ -237,7 +229,7 @@ export const Workspace = (props: WorkspaceProps) => {
const handleHideModal = () => { const handleHideModal = () => {
setState(prevState => { setState(prevState => {
return { ...prevState, modal: { ...state.modal, hide: true } } return { ...prevState, modal: { ...state.modal, hide: true, message: null } }
}) })
} }
@ -276,6 +268,12 @@ export const Workspace = (props: WorkspaceProps) => {
) )
} }
// const handleWorkspaceSelect = (e) => {
// const value = e.target.value
// setWorkspace(value)
// }
return ( return (
<div className='remixui_container'> <div className='remixui_container'>
<ModalDialog <ModalDialog

Loading…
Cancel
Save