createing default workspace

pull/1120/head
lianahus 4 years ago committed by Liana Husikyan
parent d0b7b58de3
commit c34ce4b4b5
  1. 1
      apps/remix-ide/src/app/files/fileManager.js
  2. 13
      apps/remix-ide/src/app/files/workspaceFileProvider.js
  3. 22
      libs/remix-ui/workspace/src/lib/remix-ui-workspace.tsx

@ -564,7 +564,6 @@ class FileManager extends Plugin {
return this._deps.filesProviders.browser
}
const provider = this._deps.filesProviders.workspace
if (!provider.isReady()) throw createError({ code: 'ECONNRESET', message: 'No workspace has been opened.' })
return this._deps.filesProviders.workspace
}

@ -1,5 +1,6 @@
'use strict'
const EventManager = require('../../lib/events')
const FileProvider = require('./fileProvider')
const pathModule = require('path')
@ -8,6 +9,7 @@ class WorkspaceFileProvider extends FileProvider {
super('')
this.workspacesPath = '.workspaces'
this.workspace = null
this.event = new EventManager()
}
setWorkspace (workspace) {
@ -28,7 +30,7 @@ class WorkspaceFileProvider extends FileProvider {
}
removePrefix (path) {
if (!this.workspace) throw new Error('No workspace has been opened.')
if (!this.workspace) this.createDefaultWorkspace()
path = path.replace(/^\/|\/$/g, '') // remove first and last slash
if (path.startsWith(this.workspacesPath + '/' + this.workspace)) return path
if (path.startsWith(this.workspace)) return this.workspacesPath + '/' + this.workspace
@ -49,7 +51,7 @@ class WorkspaceFileProvider extends FileProvider {
}
resolveDirectory (path, callback) {
if (!this.workspace) throw new Error('No workspace has been opened.')
if (!this.workspace) this.createDefaultWorkspace()
super.resolveDirectory(path, (error, files) => {
if (error) return callback(error)
const unscoped = {}
@ -74,9 +76,14 @@ class WorkspaceFileProvider extends FileProvider {
}
_normalizePath (path) {
if (!this.workspace) throw new Error('No workspace has been opened.')
if (!this.workspace) this.createDefaultWorkspace()
return path.replace(this.workspacesPath + '/' + this.workspace + '/', '')
}
createDefaultWorkspace() {
this.workspace = 'workspace_default'
this.event.trigger('create_workspace_default', [this.workspace])
}
}
module.exports = WorkspaceFileProvider

@ -2,6 +2,7 @@ import React, { useState, useEffect, useRef } from 'react' // eslint-disable-lin
import { FileExplorer } from '@remix-ui/file-explorer' // eslint-disable-line
import './remix-ui-workspace.css'
import { ModalDialog } from '@remix-ui/modal-dialog' // eslint-disable-line
import { Toaster } from '@remix-ui/toaster'
/* eslint-disable-next-line */
export interface WorkspaceProps {
@ -101,6 +102,17 @@ export const Workspace = (props: WorkspaceProps) => {
remixdExplorer.loading()
})
props.workspace.event.register('create_workspace_default', async (workspaceName) => {
try {
await props.createWorkspace(workspaceName)
await setWorkspace(workspaceName)
toast("New default workspace has been created.")
} catch (e) {
modalMessage('Create Default Workspace', e.message)
console.error(e)
}
})
if (props.initialWorkspace) {
props.workspace.setWorkspace(props.initialWorkspace)
setState(prevState => {
@ -131,8 +143,15 @@ export const Workspace = (props: WorkspaceProps) => {
},
handleHide: null
},
loadingLocalhost: false
loadingLocalhost: false,
toasterMsg: '',
})
const toast = (message: string) => {
setState(prevState => {
return { ...prevState, toasterMsg: message }
})
}
/* workspace creation, renaming and deletion */
@ -312,6 +331,7 @@ export const Workspace = (props: WorkspaceProps) => {
handleHide={ handleHideModal }>
{ (typeof state.modal.message !== 'string') && state.modal.message }
</ModalDialog>
<Toaster message={state.toasterMsg} />
<div className='remixui_fileexplorer' onClick={() => resetFocus(true)}>
<div>
<header>

Loading…
Cancel
Save