remixDefault and template dropdown

pull/5370/head
Aniket-Engg 3 years ago
parent ad90f2e3ff
commit 63fd950f60
  1. 4
      apps/remix-ide/src/app/panels/file-panel.js
  2. 4
      libs/remix-ui/workspace/src/lib/actions/events.ts
  3. 4
      libs/remix-ui/workspace/src/lib/actions/index.ts
  4. 14
      libs/remix-ui/workspace/src/lib/actions/workspace.ts
  5. 2
      libs/remix-ui/workspace/src/lib/contexts/index.ts
  6. 4
      libs/remix-ui/workspace/src/lib/providers/FileSystemProvider.tsx
  7. 11
      libs/remix-ui/workspace/src/lib/remix-ui-workspace.tsx
  8. 2
      libs/remix-ui/workspace/src/lib/types/index.ts

@ -121,9 +121,9 @@ module.exports = class Filepanel extends ViewPlugin {
})
}
createWorkspace (workspaceName, isEmpty) {
createWorkspace (workspaceName, workspaceTemplateName, isEmpty) {
return new Promise((resolve, reject) => {
this.emit('createWorkspaceReducerEvent', workspaceName, isEmpty, (err, data) => {
this.emit('createWorkspaceReducerEvent', workspaceName, workspaceTemplateName, isEmpty, (err, data) => {
if (err) reject(err)
else resolve(data || true)
})

@ -10,8 +10,8 @@ let plugin, dispatch: React.Dispatch<any>
export const listenOnPluginEvents = (filePanelPlugin) => {
plugin = filePanelPlugin
plugin.on('filePanel', 'createWorkspaceReducerEvent', (name: string, isEmpty = false, cb: (err: Error, result?: string | number | boolean | Record<string, any>) => void) => {
createWorkspace(name, isEmpty, cb)
plugin.on('filePanel', 'createWorkspaceReducerEvent', (name: string, workspaceTemplateName, isEmpty = false, cb: (err: Error, result?: string | number | boolean | Record<string, any>) => void) => {
createWorkspace(name, workspaceTemplateName, isEmpty, cb)
})
plugin.on('filePanel', 'renameWorkspaceReducerEvent', (oldName: string, workspaceName: string, cb: (err: Error, result?: string | number | boolean | Record<string, any>) => void) => {

@ -46,10 +46,10 @@ export const initWorkspace = (filePanelPlugin) => async (reducerDispatch: React.
plugin.on('editor', 'editorMounted', async () => await plugin.fileManager.openFile(filePath))
} else {
if (workspaces.length === 0) {
await createWorkspaceTemplate('default_workspace', 'default-template')
await createWorkspaceTemplate('default_workspace', 'remixDefault')
plugin.setWorkspace({ name: 'default_workspace', isLocalhost: false })
dispatch(setCurrentWorkspace('default_workspace'))
await loadWorkspacePreset('default-template')
await loadWorkspacePreset('remixDefault')
} else {
if (workspaces.length > 0) {
workspaceProvider.setWorkspace(workspaces[workspaces.length - 1])

@ -41,9 +41,9 @@ export const addInputField = async (type: 'file' | 'folder', path: string, cb?:
return promise
}
export const createWorkspace = async (workspaceName: string, isEmpty = false, cb?: (err: Error, result?: string | number | boolean | Record<string, any>) => void) => {
export const createWorkspace = async (workspaceName: string, workspaceTemplateName, isEmpty = false, cb?: (err: Error, result?: string | number | boolean | Record<string, any>) => void) => {
await plugin.fileManager.closeAllFiles()
const promise = createWorkspaceTemplate(workspaceName, 'default-template')
const promise = createWorkspaceTemplate(workspaceName, workspaceTemplateName)
dispatch(createWorkspaceRequest(promise))
promise.then(async () => {
@ -51,7 +51,7 @@ export const createWorkspace = async (workspaceName: string, isEmpty = false, cb
await plugin.setWorkspace({ name: workspaceName, isLocalhost: false })
await plugin.setWorkspaces(await getWorkspaces())
await plugin.workspaceCreated(workspaceName)
if (!isEmpty) await loadWorkspacePreset('default-template')
if (!isEmpty) await loadWorkspacePreset(workspaceTemplateName)
cb && cb(null, workspaceName)
}).catch((error) => {
dispatch(createWorkspaceError({ error }))
@ -60,10 +60,10 @@ export const createWorkspace = async (workspaceName: string, isEmpty = false, cb
return promise
}
export const createWorkspaceTemplate = async (workspaceName: string, template: 'gist-template' | 'code-template' | 'default-template' = 'default-template') => {
export const createWorkspaceTemplate = async (workspaceName: string, template: 'gist-template' | 'code-template' | 'remixDefault' = 'remixDefault') => {
if (!workspaceName) throw new Error('workspace name cannot be empty')
if (checkSpecialChars(workspaceName) || checkSlash(workspaceName)) throw new Error('special characters are not allowed')
if (await workspaceExists(workspaceName) && template === 'default-template') throw new Error('workspace already exists')
if (await workspaceExists(workspaceName) && template === 'remixDefault') throw new Error('workspace already exists')
else {
const workspaceProvider = plugin.fileProviders.workspace
@ -77,7 +77,7 @@ export type UrlParametersType = {
url: string
}
export const loadWorkspacePreset = async (template: 'gist-template' | 'code-template' | 'default-template' = 'default-template') => {
export const loadWorkspacePreset = async (template: 'gist-template' | 'code-template' | 'remixDefault' = 'remixDefault') => {
const workspaceProvider = plugin.fileProviders.workspace
const params = queryParams.get() as UrlParametersType
@ -150,7 +150,7 @@ export const loadWorkspacePreset = async (template: 'gist-template' | 'code-temp
}
break
case 'default-template':
case 'remixDefault':
// creates a new workspace and populates it with default project template.
// insert example contracts
for (const file in examples) {

@ -9,7 +9,7 @@ export const FileSystemContext = createContext<{
dispatchFetchDirectory:(path: string) => Promise<void>,
dispatchAddInputField:(path: string, type: 'file' | 'folder') => Promise<void>,
dispatchRemoveInputField:(path: string) => Promise<void>,
dispatchCreateWorkspace: (workspaceName: string) => Promise<void>,
dispatchCreateWorkspace: (workspaceName: string, workspaceTemplateName: string) => Promise<void>,
toast: (toasterMsg: string) => void,
dispatchFetchWorkspaceDirectory: (path: string) => Promise<void>,
dispatchSwitchToWorkspace: (name: string) => Promise<void>,

@ -43,8 +43,8 @@ export const FileSystemProvider = (props: WorkspaceProps) => {
await removeInputField(path)
}
const dispatchCreateWorkspace = async (workspaceName: string) => {
await createWorkspace(workspaceName)
const dispatchCreateWorkspace = async (workspaceName: string, workspaceTemplateName: string) => {
await createWorkspace(workspaceName, workspaceTemplateName)
}
const dispatchFetchWorkspaceDirectory = async (path: string) => {

@ -12,6 +12,7 @@ export function Workspace () {
const global = useContext(FileSystemContext)
const workspaceRenameInput = useRef()
const workspaceCreateInput = useRef()
const workspaceCreateTemplateInput = useRef()
useEffect(() => {
resetFocus()
@ -83,9 +84,11 @@ export function Workspace () {
if (workspaceCreateInput.current === undefined) return
// @ts-ignore: Object is possibly 'null'.
const workspaceName = workspaceCreateInput.current.value
// @ts-ignore: Object is possibly 'null'.
const workspaceTemplateName = workspaceCreateTemplateInput.current.value || 'remixDefault'
try {
await global.dispatchCreateWorkspace(workspaceName)
await global.dispatchCreateWorkspace(workspaceName, workspaceTemplateName)
} catch (e) {
global.modal('Create Workspace', e.message, 'OK', () => {}, '')
console.error(e)
@ -119,7 +122,11 @@ export function Workspace () {
const createModalMessage = () => {
return (
<>
<input type="text" data-id="modalDialogCustomPromptTextCreate" defaultValue={`workspace_${Date.now()}`} ref={workspaceCreateInput} className="form-control" />
<input type="text" data-id="modalDialogCustomPromptTextCreate" defaultValue={`workspace_${Date.now()}`} ref={workspaceCreateInput} className="form-control" /><br/>
<select name="wstemplate" className="form-control" id="wstemplate" defaultValue='remixDefault' ref={workspaceCreateTemplateInput}>
<option value='remixDefault'>Default</option>
<option value='erc20' >ERC20</option>
</select>
</>
)
}

@ -16,7 +16,7 @@ export type MenuItems = action[]
export interface WorkspaceProps {
plugin: {
setWorkspace: ({ name: string, isLocalhost: boolean }, setEvent: boolean) => void,
createWorkspace: (name: string) => void,
createWorkspace: (name: string, workspaceTemplateName: string) => void,
renameWorkspace: (oldName: string, newName: string) => void
workspaceRenamed: ({ name: string }) => void,
workspaceCreated: ({ name: string }) => void,

Loading…
Cancel
Save