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 return this._deps.filesProviders.browser
} }
const provider = this._deps.filesProviders.workspace const provider = this._deps.filesProviders.workspace
if (!provider.isReady()) throw createError({ code: 'ECONNRESET', message: 'No workspace has been opened.' })
return this._deps.filesProviders.workspace return this._deps.filesProviders.workspace
} }

@ -1,5 +1,6 @@
'use strict' 'use strict'
const EventManager = require('../../lib/events')
const FileProvider = require('./fileProvider') const FileProvider = require('./fileProvider')
const pathModule = require('path') const pathModule = require('path')
@ -8,6 +9,7 @@ class WorkspaceFileProvider extends FileProvider {
super('') super('')
this.workspacesPath = '.workspaces' this.workspacesPath = '.workspaces'
this.workspace = null this.workspace = null
this.event = new EventManager()
} }
setWorkspace (workspace) { setWorkspace (workspace) {
@ -28,7 +30,7 @@ class WorkspaceFileProvider extends FileProvider {
} }
removePrefix (path) { 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 path = path.replace(/^\/|\/$/g, '') // remove first and last slash
if (path.startsWith(this.workspacesPath + '/' + this.workspace)) return path if (path.startsWith(this.workspacesPath + '/' + this.workspace)) return path
if (path.startsWith(this.workspace)) return this.workspacesPath + '/' + this.workspace if (path.startsWith(this.workspace)) return this.workspacesPath + '/' + this.workspace
@ -49,7 +51,7 @@ class WorkspaceFileProvider extends FileProvider {
} }
resolveDirectory (path, callback) { resolveDirectory (path, callback) {
if (!this.workspace) throw new Error('No workspace has been opened.') if (!this.workspace) this.createDefaultWorkspace()
super.resolveDirectory(path, (error, files) => { super.resolveDirectory(path, (error, files) => {
if (error) return callback(error) if (error) return callback(error)
const unscoped = {} const unscoped = {}
@ -74,9 +76,14 @@ class WorkspaceFileProvider extends FileProvider {
} }
_normalizePath (path) { _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 + '/', '') return path.replace(this.workspacesPath + '/' + this.workspace + '/', '')
} }
createDefaultWorkspace() {
this.workspace = 'workspace_default'
this.event.trigger('create_workspace_default', [this.workspace])
}
} }
module.exports = WorkspaceFileProvider 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 { FileExplorer } from '@remix-ui/file-explorer' // eslint-disable-line
import './remix-ui-workspace.css' import './remix-ui-workspace.css'
import { ModalDialog } from '@remix-ui/modal-dialog' // eslint-disable-line import { ModalDialog } from '@remix-ui/modal-dialog' // eslint-disable-line
import { Toaster } from '@remix-ui/toaster'
/* eslint-disable-next-line */ /* eslint-disable-next-line */
export interface WorkspaceProps { export interface WorkspaceProps {
@ -101,6 +102,17 @@ export const Workspace = (props: WorkspaceProps) => {
remixdExplorer.loading() 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) { if (props.initialWorkspace) {
props.workspace.setWorkspace(props.initialWorkspace) props.workspace.setWorkspace(props.initialWorkspace)
setState(prevState => { setState(prevState => {
@ -131,9 +143,16 @@ export const Workspace = (props: WorkspaceProps) => {
}, },
handleHide: null handleHide: null
}, },
loadingLocalhost: false loadingLocalhost: false,
toasterMsg: '',
}) })
const toast = (message: string) => {
setState(prevState => {
return { ...prevState, toasterMsg: message }
})
}
/* workspace creation, renaming and deletion */ /* workspace creation, renaming and deletion */
const renameCurrentWorkspace = () => { const renameCurrentWorkspace = () => {
@ -312,6 +331,7 @@ export const Workspace = (props: WorkspaceProps) => {
handleHide={ handleHideModal }> handleHide={ handleHideModal }>
{ (typeof state.modal.message !== 'string') && state.modal.message } { (typeof state.modal.message !== 'string') && state.modal.message }
</ModalDialog> </ModalDialog>
<Toaster message={state.toasterMsg} />
<div className='remixui_fileexplorer' onClick={() => resetFocus(true)}> <div className='remixui_fileexplorer' onClick={() => resetFocus(true)}>
<div> <div>
<header> <header>

Loading…
Cancel
Save