add initialWorkspace property to react component

pull/924/head
yann300 4 years ago
parent 75987af173
commit 19668a4456
  1. 10
      apps/remix-ide/src/app/panels/file-panel.js
  2. 12
      libs/remix-ui/workspace/src/lib/remix-ui-workspace.tsx

@ -62,10 +62,11 @@ module.exports = class Filepanel extends ViewPlugin {
this.registeredMenuItems = []
this.request = {}
this.workspaces = []
this.initWorkspace()
this.initialWorkspace = null
}
render () {
this.initWorkspace().then(() => this.getWorkspaces()).catch(console.error)
return this.el
}
@ -84,9 +85,9 @@ module.exports = class Filepanel extends ViewPlugin {
registry={this._components.registry}
plugin={this}
request={this.request}
examples={examples}
workspaces={this.workspaces}
registeredMenuItems={this.registeredMenuItems}
initialWorkspace={this.initialWorkspace}
/>
, this.el)
}
@ -139,12 +140,13 @@ module.exports = class Filepanel extends ViewPlugin {
if (params.code) {
try {
await this._deps.fileManager.createWorkspace('code-sample')
this._deps.fileProviders.workspace.setWorkspace('code-sample')
var hash = ethutil.bufferToHex(ethutil.keccak(params.code))
const fileName = 'contract-' + hash.replace('0x', '').substring(0, 10) + '.sol'
const path = 'browser/' + workspacesPath + '/code-sample/' + fileName
await this._deps.fileManager.writeFile(path, atob(params.code))
this.setWorkspace({ name: 'code-sample', isLocalhost: false })
await this._deps.fileManager.openFile(path)
this.initialWorkspace = 'code-sample'
await this._deps.fileManager.openFile(fileName)
} catch (e) {
console.error(e)
}

@ -3,9 +3,6 @@ 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
type CodeExamples = {
[key: string]: { name: string, content: string }
};
/* eslint-disable-next-line */
export interface WorkspaceProps {
setWorkspace: ({ name: string, isLocalhost: boolean }) => void,
@ -17,12 +14,12 @@ export interface WorkspaceProps {
browser: any // browser provider
localhost: any // localhost provider
fileManager : any
examples: CodeExamples,
registry: any // registry
plugin: any // plugin call and resetFocus
request: any // api request,
workspaces: any,
registeredMenuItems: [] // menu items
initialWorkspace: string
}
var canUpload = window.File || window.FileReader || window.FileList || window.Blob
@ -65,7 +62,12 @@ export const Workspace = (props: WorkspaceProps) => {
useEffect(() => {
const getWorkspaces = async () => {
if (props.workspaces && Array.isArray(props.workspaces)) {
if (props.workspaces.length > 0 && state.currentWorkspace === NO_WORKSPACE) {
if (props.initialWorkspace) {
props.workspace.setWorkspace(props.initialWorkspace)
setState(prevState => {
return { ...prevState, workspaces: props.workspaces, currentWorkspace: props.initialWorkspace }
})
} else if (props.workspaces.length > 0 && state.currentWorkspace === NO_WORKSPACE) {
props.workspace.setWorkspace(props.workspaces[0])
setState(prevState => {
return { ...prevState, workspaces: props.workspaces, currentWorkspace: props.workspaces[0] }

Loading…
Cancel
Save