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.gitHandle = new GitHandle()
this.registeredMenuItems = [] this.registeredMenuItems = []
this.request = {} this.request = {}
this.getWorkspaces() this.workspaces = []
this.renderComponent()
} }
render () { render () {
@ -111,7 +112,10 @@ module.exports = class Filepanel extends ViewPlugin {
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) return reject(error) if (error) {
console.error(error)
return reject(error)
}
resolve(Object.keys(items) resolve(Object.keys(items)
.filter((item) => items[item].isDirectory) .filter((item) => items[item].isDirectory)
.map((folder) => folder.replace(workspacesPath + '/', ''))) .map((folder) => folder.replace(workspacesPath + '/', '')))

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

Loading…
Cancel
Save