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

@ -21,7 +21,6 @@ export interface WorkspaceProps {
plugin: any // plugin call and resetFocus
request: any // api request,
workspaces: any,
setWorkspaceName: string,
registeredMenuItems: [] // menu items
}
@ -48,10 +47,6 @@ export const Workspace = (props: WorkspaceProps) => {
return createWorkspace()
}
// props.request.getWorkspaces = () => {
// return getWorkspaces()
// }
props.request.createNewFile = () => {
props.plugin.resetNewFile()
}
@ -75,9 +70,8 @@ export const Workspace = (props: WorkspaceProps) => {
return { ...prevState, workspaces: props.workspaces, currentWorkspace: props.workspaces[0] }
})
} else {
props.workspace.clearWorkspace()
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()
}, [props.workspaces])
useEffect(() => {
if (props.setWorkspaceName && (props.setWorkspaceName !== state.currentWorkspace)) {
setWorkspace(props.setWorkspaceName)
}
}, [props.setWorkspaceName])
const [state, setState] = useState({
workspaces: [],
reset: false,
@ -162,16 +150,20 @@ export const Workspace = (props: WorkspaceProps) => {
}
const onFinishCreateWorkspace = async () => {
if (!workspaceCreateInput.current) return
if (workspaceCreateInput.current === undefined) return
// @ts-ignore: Object is possibly 'null'.
const workspaceName = workspaceCreateInput.current.value
const workspacesPath = props.workspace.workspacesPath
props.browser.createDir(workspacesPath + '/' + workspaceName, async () => {
setWorkspace(workspaceName)
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 = () => {
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 (
<div className='remixui_container'>
<ModalDialog

Loading…
Cancel
Save