diff --git a/apps/remix-ide/src/app/panels/file-panel.js b/apps/remix-ide/src/app/panels/file-panel.js index 03a7283dd3..cb0b5ebd10 100644 --- a/apps/remix-ide/src/app/panels/file-panel.js +++ b/apps/remix-ide/src/app/panels/file-panel.js @@ -139,12 +139,12 @@ module.exports = class Filepanel extends ViewPlugin { if (loadedFromGist) return if (params.code) { try { - await this._deps.fileManager.createWorkspace('code-sample') + await this.processCreateWorkspace('code-sample') this._deps.fileProviders.workspace.setWorkspace('code-sample') var hash = ethutil.bufferToHex(ethutil.keccak(params.code)) const fileName = 'contract-' + hash.replace('0x', '').substring(0, 10) + '.sol' - const path = 'browser/' + workspacesPath + '/code-sample/' + fileName - await this._deps.fileManager.writeFile(path, atob(params.code)) + const path = fileName + await this._deps.fileProviders.workspace.set(path, atob(params.code)) this.initialWorkspace = 'code-sample' await this._deps.fileManager.openFile(fileName) } catch (e) { diff --git a/libs/remix-ui/workspace/src/lib/remix-ui-workspace.tsx b/libs/remix-ui/workspace/src/lib/remix-ui-workspace.tsx index a23e143a0a..d21f42a64a 100644 --- a/libs/remix-ui/workspace/src/lib/remix-ui-workspace.tsx +++ b/libs/remix-ui/workspace/src/lib/remix-ui-workspace.tsx @@ -62,12 +62,7 @@ export const Workspace = (props: WorkspaceProps) => { useEffect(() => { const getWorkspaces = async () => { if (props.workspaces && Array.isArray(props.workspaces)) { - if (props.initialWorkspace) { - props.workspace.setWorkspace(props.initialWorkspace) - setState(prevState => { - return { ...prevState, workspaces: props.workspaces, currentWorkspace: props.initialWorkspace } - }) - } else if (props.workspaces.length > 0 && state.currentWorkspace === NO_WORKSPACE) { + 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] } @@ -91,6 +86,13 @@ export const Workspace = (props: WorkspaceProps) => { props.localhost.event.register('disconnected', (event) => { remixdExplorer.hide() }) + + if (props.initialWorkspace) { + props.workspace.setWorkspace(props.initialWorkspace) + setState(prevState => { + return { ...prevState, currentWorkspace: props.initialWorkspace } + }) + } }, []) const [state, setState] = useState({