pull/1120/head
lianahus 4 years ago committed by Liana Husikyan
parent a9a96b7e70
commit c2c3f7871f
  1. 12
      apps/remix-ide/src/app/files/workspaceFileProvider.js
  2. 21
      apps/remix-ide/src/app/panels/file-panel.js
  3. 24
      libs/remix-ui/workspace/src/lib/remix-ui-workspace.tsx

@ -30,7 +30,7 @@ class WorkspaceFileProvider extends FileProvider {
}
removePrefix (path) {
if (!this.workspace) this.createDefaultWorkspace()
if (!this.workspace) this.createWorkspace()
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
@ -51,7 +51,7 @@ class WorkspaceFileProvider extends FileProvider {
}
resolveDirectory (path, callback) {
if (!this.workspace) this.createDefaultWorkspace()
if (!this.workspace) this.createWorkspace()
super.resolveDirectory(path, (error, files) => {
if (error) return callback(error)
const unscoped = {}
@ -76,13 +76,13 @@ class WorkspaceFileProvider extends FileProvider {
}
_normalizePath (path) {
if (!this.workspace) this.createDefaultWorkspace()
if (!this.workspace) this.createWorkspace()
return path.replace(this.workspacesPath + '/' + this.workspace + '/', '')
}
createDefaultWorkspace () {
this.workspace = 'generated_workspace'
this.event.trigger('create_workspace_default', [this.workspace])
createWorkspace (name) {
if (!name) name = 'default_workspace'
this.event.trigger('create_workspace', [name])
}
}

@ -175,12 +175,10 @@ module.exports = class Filepanel extends ViewPlugin {
}
async createNewFile () {
if (!this.workspaceExists()) this.createWorkspace('default_workspace')
return await this.request.createNewFile()
}
async uploadFile (event) {
if (!this.workspaceExists()) this.createWorkspace('default_workspace')
return await this.request.uploadFile(event)
}
@ -204,14 +202,17 @@ module.exports = class Filepanel extends ViewPlugin {
if (!workspaceName) throw new Error('name cannot be empty')
if (checkSpecialChars(workspaceName) || checkSlash(workspaceName)) throw new Error('special characters are not allowed')
if (await this.workspaceExists(workspaceName)) throw new Error('workspace already exists')
const browserProvider = this._deps.fileProviders.browser
const workspacesPath = this._deps.fileProviders.workspace.workspacesPath
await this.processCreateWorkspace(workspaceName)
for (const file in examples) {
try {
await browserProvider.set('browser/' + workspacesPath + '/' + workspaceName + '/' + examples[file].name, examples[file].content)
} catch (error) {
console.error(error)
else {
this._deps.fileProviders.workspace.setWorkspace(workspaceName)
const browserProvider = this._deps.fileProviders.browser
const workspacesPath = this._deps.fileProviders.workspace.workspacesPath
await this.processCreateWorkspace(workspaceName)
for (const file in examples) {
try {
await browserProvider.set('browser/' + workspacesPath + '/' + workspaceName + '/' + examples[file].name, examples[file].content)
} catch (error) {
console.error(error)
}
}
}
}

@ -50,10 +50,13 @@ export const Workspace = (props: WorkspaceProps) => {
}
props.request.createNewFile = () => {
if (!state.workspaces.length) createNewWorkspace('default_workspace')
props.plugin.resetNewFile()
}
props.request.uploadFile = (target) => {
if (!state.workspaces.length) createNewWorkspace('default_workspace')
setState(prevState => {
return { ...prevState, uploadFileEvent: target }
})
@ -102,15 +105,8 @@ 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)
}
props.workspace.event.register('create_workspace', (name) => {
createNewWorkspace(name)
})
if (props.initialWorkspace) {
@ -121,6 +117,16 @@ export const Workspace = (props: WorkspaceProps) => {
}
}, [])
const createNewWorkspace = 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)
}
}
const [state, setState] = useState({
workspaces: [],
reset: false,

Loading…
Cancel
Save