refactor setworkspace event

mr console

rm constants

linting

lint

lint

close file before settting workspace to null
pull/5370/head
bunsenstraat 4 years ago committed by Liana Husikyan
parent eff041d134
commit e3c80d5d9a
  1. 5
      apps/remix-ide/src/app/files/remixd-handle.js
  2. 12
      apps/remix-ide/src/app/panels/file-panel.js
  3. 9
      libs/remix-ui/workspace/src/lib/remix-ui-workspace.tsx

@ -19,6 +19,7 @@ var css = csjs`
word-break: break-word; word-break: break-word;
} }
` `
const LOCALHOST = ' - connect to localhost - '
const profile = { const profile = {
name: 'remixd', name: 'remixd',
@ -83,7 +84,9 @@ export class RemixdHandle extends WebsocketPlugin {
this.canceled() this.canceled()
} }
}, 3000) }, 3000)
this.localhostProvider.init(() => {}) this.localhostProvider.init(() => {
this.call('filePanel', 'setWorkspace', { name: LOCALHOST, isLocalhost: true }, true)
})
this.call('manager', 'activatePlugin', 'hardhat') this.call('manager', 'activatePlugin', 'hardhat')
} }
} }

@ -34,7 +34,7 @@ const modalDialogCustom = require('../ui/modal-dialog-custom')
const profile = { const profile = {
name: 'filePanel', name: 'filePanel',
displayName: 'File explorers', displayName: 'File explorers',
methods: ['createNewFile', 'uploadFile', 'getCurrentWorkspace', 'getWorkspaces', 'createWorkspace'], methods: ['createNewFile', 'uploadFile', 'getCurrentWorkspace', 'getWorkspaces', 'createWorkspace', 'setWorkspace'],
events: ['setWorkspace', 'renameWorkspace', 'deleteWorkspace', 'createWorkspace'], events: ['setWorkspace', 'renameWorkspace', 'deleteWorkspace', 'createWorkspace'],
icon: 'assets/img/fileManager.webp', icon: 'assets/img/fileManager.webp',
description: ' - ', description: ' - ',
@ -43,7 +43,6 @@ const profile = {
documentation: 'https://remix-ide.readthedocs.io/en/latest/file_explorer.html', documentation: 'https://remix-ide.readthedocs.io/en/latest/file_explorer.html',
version: packageJson.version version: packageJson.version
} }
module.exports = class Filepanel extends ViewPlugin { module.exports = class Filepanel extends ViewPlugin {
constructor (appManager) { constructor (appManager) {
super(profile) super(profile)
@ -114,7 +113,6 @@ module.exports = class Filepanel extends ViewPlugin {
async getWorkspaces () { async getWorkspaces () {
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) { if (error) {
console.error(error) console.error(error)
@ -247,14 +245,16 @@ module.exports = class Filepanel extends ViewPlugin {
} }
/** these are called by the react component, action is already finished whent it's called */ /** these are called by the react component, action is already finished whent it's called */
async setWorkspace (workspace) { async setWorkspace (workspace, setEvent = true) {
this._deps.fileManager.closeAllFiles()
if (workspace.isLocalhost) { if (workspace.isLocalhost) {
this.call('manager', 'activatePlugin', 'remixd') this.call('manager', 'activatePlugin', 'remixd')
} else if (await this.call('manager', 'isActive', 'remixd')) { } else if (await this.call('manager', 'isActive', 'remixd')) {
this.call('manager', 'deactivatePlugin', 'remixd') this.call('manager', 'deactivatePlugin', 'remixd')
} }
this.emit('setWorkspace', workspace) if (setEvent) {
this._deps.fileManager.setMode(workspace.isLocalhost ? 'localhost' : 'browser')
this.emit('setWorkspace', workspace)
}
} }
workspaceRenamed (workspace) { workspaceRenamed (workspace) {

@ -6,7 +6,7 @@ import { Toaster } from '@remix-ui/toaster'// eslint-disable-line
/* eslint-disable-next-line */ /* eslint-disable-next-line */
export interface WorkspaceProps { export interface WorkspaceProps {
setWorkspace: ({ name: string, isLocalhost: boolean }) => void, setWorkspace: ({ name: string, isLocalhost: boolean }, setEvent: boolean) => void,
createWorkspace: (name: string) => void, createWorkspace: (name: string) => void,
renameWorkspace: (oldName: string, newName: string) => void renameWorkspace: (oldName: string, newName: string) => void
workspaceRenamed: ({ name: string }) => void, workspaceRenamed: ({ name: string }) => void,
@ -74,7 +74,7 @@ export const Workspace = (props: WorkspaceProps) => {
let getWorkspaces = async () => { let getWorkspaces = async () => {
if (props.workspaces && Array.isArray(props.workspaces)) { if (props.workspaces && Array.isArray(props.workspaces)) {
if (props.workspaces.length > 0 && state.currentWorkspace === NO_WORKSPACE) { if (props.workspaces.length > 0 && state.currentWorkspace === NO_WORKSPACE) {
props.workspace.setWorkspace(props.workspaces[0]) await props.workspace.setWorkspace(props.workspaces[0])
setState(prevState => { setState(prevState => {
return { ...prevState, workspaces: props.workspaces, currentWorkspace: props.workspaces[0] } return { ...prevState, workspaces: props.workspaces, currentWorkspace: props.workspaces[0] }
}) })
@ -240,14 +240,15 @@ export const Workspace = (props: WorkspaceProps) => {
} }
const setWorkspace = async (name) => { const setWorkspace = async (name) => {
await props.setWorkspace({ name, isLocalhost: name === LOCALHOST }) await props.fileManager.closeAllFiles()
if (name === LOCALHOST) { if (name === LOCALHOST) {
props.workspace.clearWorkspace() props.workspace.clearWorkspace()
} else if (name === NO_WORKSPACE) { } else if (name === NO_WORKSPACE) {
props.workspace.clearWorkspace() props.workspace.clearWorkspace()
} else { } else {
props.workspace.setWorkspace(name) await props.workspace.setWorkspace(name)
} }
await props.setWorkspace({ name, isLocalhost: name === LOCALHOST }, !(name === LOCALHOST || name === NO_WORKSPACE))
props.plugin.getWorkspaces() props.plugin.getWorkspaces()
setState(prevState => { setState(prevState => {
return { ...prevState, currentWorkspace: name } return { ...prevState, currentWorkspace: name }

Loading…
Cancel
Save