Get workspaces after creation

pull/924/head
ioedeveloper 4 years ago committed by yann300
parent c70a5a74a7
commit 0dddd45312
  1. 8
      apps/remix-ide/src/app/panels/file-panel.js
  2. 21
      libs/remix-ui/workspace/src/lib/remix-ui-workspace.tsx

@ -60,7 +60,8 @@ module.exports = class Filepanel extends ViewPlugin {
this.gitHandle = new GitHandle()
this.registeredMenuItems = []
this.request = {}
this.getWorkspaces()
this.workspaces = []
this.renderComponent()
}
render () {
@ -111,7 +112,10 @@ module.exports = class Filepanel extends ViewPlugin {
const result = new Promise((resolve, reject) => {
const workspacesPath = this._deps.fileProviders.workspace.workspacesPath
this._deps.fileProviders.browser.resolveDirectory('/' + workspacesPath, (error, items) => {
if (error) return reject(error)
if (error) {
console.error(error)
return reject(error)
}
resolve(Object.keys(items)
.filter((item) => items[item].isDirectory)
.map((folder) => folder.replace(workspacesPath + '/', '')))

@ -73,9 +73,17 @@ export const Workspace = (props: WorkspaceProps) => {
useEffect(() => {
const getWorkspaces = async () => {
if (props.workspaces && Array.isArray(props.workspaces)) {
setState(prevState => {
return { ...prevState, workspaces: props.workspaces }
})
if (props.workspaces.length > 0 && state.currentWorkspace === NO_WORKSPACE) {
props.workspace.setWorkspace(props.workspaces[0])
setState(prevState => {
return { ...prevState, workspaces: props.workspaces, currentWorkspace: props.workspaces[0] }
})
} else {
props.workspace.clearWorkspace()
setState(prevState => {
return { ...prevState, workspaces: props.workspaces, currentWorkspace: NO_WORKSPACE }
})
}
}
}
@ -302,10 +310,7 @@ export const Workspace = (props: WorkspaceProps) => {
console.error(error)
}
}
setWorkspace('default_workspace')
} else {
// we've already got some workspaces
setWorkspace(NO_WORKSPACE)
props.plugin.getWorkspaces()
}
})
}
@ -420,7 +425,7 @@ export const Workspace = (props: WorkspaceProps) => {
})
}
<option selected={state.currentWorkspace === LOCALHOST} value={LOCALHOST}>{LOCALHOST}</option>
<option selected={state.currentWorkspace === NO_WORKSPACE} value={NO_WORKSPACE}>{NO_WORKSPACE}</option>
{ state.workspaces.length <= 0 && <option selected={state.currentWorkspace === NO_WORKSPACE} value={NO_WORKSPACE}>{NO_WORKSPACE}</option> }
</select>
</div>
</header>

Loading…
Cancel
Save