Skip to content

Commit 92ce598

Browse files
bunsenstraatLianaHus
authored andcommitted
refactor setworkspace event
mr console rm constants linting lint lint close file before settting workspace to null
1 parent d17cb0a commit 92ce598

File tree

3 files changed

+15
-11
lines changed

3 files changed

+15
-11
lines changed

apps/remix-ide/src/app/files/remixd-handle.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ var css = csjs`
1919
word-break: break-word;
2020
}
2121
`
22+
const LOCALHOST = ' - connect to localhost - '
2223

2324
const profile = {
2425
name: 'remixd',
@@ -83,7 +84,9 @@ export class RemixdHandle extends WebsocketPlugin {
8384
this.canceled()
8485
}
8586
}, 3000)
86-
this.localhostProvider.init(() => {})
87+
this.localhostProvider.init(() => {
88+
this.call('filePanel', 'setWorkspace', { name: LOCALHOST, isLocalhost: true }, true)
89+
})
8790
this.call('manager', 'activatePlugin', 'hardhat')
8891
}
8992
}

apps/remix-ide/src/app/panels/file-panel.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ const modalDialogCustom = require('../ui/modal-dialog-custom')
3434
const profile = {
3535
name: 'filePanel',
3636
displayName: 'File explorers',
37-
methods: ['createNewFile', 'uploadFile', 'getCurrentWorkspace', 'getWorkspaces', 'createWorkspace'],
37+
methods: ['createNewFile', 'uploadFile', 'getCurrentWorkspace', 'getWorkspaces', 'createWorkspace', 'setWorkspace'],
3838
events: ['setWorkspace', 'renameWorkspace', 'deleteWorkspace', 'createWorkspace'],
3939
icon: 'assets/img/fileManager.webp',
4040
description: ' - ',
@@ -43,7 +43,6 @@ const profile = {
4343
documentation: 'https://remix-ide.readthedocs.io/en/latest/file_explorer.html',
4444
version: packageJson.version
4545
}
46-
4746
module.exports = class Filepanel extends ViewPlugin {
4847
constructor (appManager) {
4948
super(profile)
@@ -114,7 +113,6 @@ module.exports = class Filepanel extends ViewPlugin {
114113
async getWorkspaces () {
115114
const result = new Promise((resolve, reject) => {
116115
const workspacesPath = this._deps.fileProviders.workspace.workspacesPath
117-
118116
this._deps.fileProviders.browser.resolveDirectory('/' + workspacesPath, (error, items) => {
119117
if (error) {
120118
console.error(error)
@@ -247,14 +245,16 @@ module.exports = class Filepanel extends ViewPlugin {
247245
}
248246

249247
/** these are called by the react component, action is already finished whent it's called */
250-
async setWorkspace (workspace) {
251-
this._deps.fileManager.closeAllFiles()
248+
async setWorkspace (workspace, setEvent = true) {
252249
if (workspace.isLocalhost) {
253250
this.call('manager', 'activatePlugin', 'remixd')
254251
} else if (await this.call('manager', 'isActive', 'remixd')) {
255252
this.call('manager', 'deactivatePlugin', 'remixd')
256253
}
257-
this.emit('setWorkspace', workspace)
254+
if (setEvent) {
255+
this._deps.fileManager.setMode(workspace.isLocalhost ? 'localhost' : 'browser')
256+
this.emit('setWorkspace', workspace)
257+
}
258258
}
259259

260260
workspaceRenamed (workspace) {

libs/remix-ui/workspace/src/lib/remix-ui-workspace.tsx

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { Toaster } from '@remix-ui/toaster'// eslint-disable-line
66

77
/* eslint-disable-next-line */
88
export interface WorkspaceProps {
9-
setWorkspace: ({ name: string, isLocalhost: boolean }) => void,
9+
setWorkspace: ({ name: string, isLocalhost: boolean }, setEvent: boolean) => void,
1010
createWorkspace: (name: string) => void,
1111
renameWorkspace: (oldName: string, newName: string) => void
1212
workspaceRenamed: ({ name: string }) => void,
@@ -74,7 +74,7 @@ export const Workspace = (props: WorkspaceProps) => {
7474
let getWorkspaces = async () => {
7575
if (props.workspaces && Array.isArray(props.workspaces)) {
7676
if (props.workspaces.length > 0 && state.currentWorkspace === NO_WORKSPACE) {
77-
props.workspace.setWorkspace(props.workspaces[0])
77+
await props.workspace.setWorkspace(props.workspaces[0])
7878
setState(prevState => {
7979
return { ...prevState, workspaces: props.workspaces, currentWorkspace: props.workspaces[0] }
8080
})
@@ -240,14 +240,15 @@ export const Workspace = (props: WorkspaceProps) => {
240240
}
241241

242242
const setWorkspace = async (name) => {
243-
await props.setWorkspace({ name, isLocalhost: name === LOCALHOST })
243+
await props.fileManager.closeAllFiles()
244244
if (name === LOCALHOST) {
245245
props.workspace.clearWorkspace()
246246
} else if (name === NO_WORKSPACE) {
247247
props.workspace.clearWorkspace()
248248
} else {
249-
props.workspace.setWorkspace(name)
249+
await props.workspace.setWorkspace(name)
250250
}
251+
await props.setWorkspace({ name, isLocalhost: name === LOCALHOST }, !(name === LOCALHOST || name === NO_WORKSPACE))
251252
props.plugin.getWorkspaces()
252253
setState(prevState => {
253254
return { ...prevState, currentWorkspace: name }

0 commit comments

Comments
 (0)