Init plugin

pull/1140/head
ioedeveloper 4 years ago
parent 7033c20013
commit ed03204f25
  1. 10
      libs/remix-ui/file-explorer/src/lib/actions/fileSystem.ts
  2. 8
      libs/remix-ui/file-explorer/src/lib/file-explorer.tsx
  3. 18
      libs/remix-ui/file-explorer/src/lib/reducers/fileSystem.ts

@ -172,7 +172,7 @@ export const fileRemovedSuccess = (path: string, removePath: string) => {
} }
} }
export const setProvider = (provider, workspaceName) => (dispatch: React.Dispatch<any>) => { export const init = (provider, workspaceName: string, plugin) => (dispatch: React.Dispatch<any>) => {
if (provider) { if (provider) {
provider.event.register('fileAdded', async (filePath) => { provider.event.register('fileAdded', async (filePath) => {
const path = extractParentFromKey(filePath) || workspaceName const path = extractParentFromKey(filePath) || workspaceName
@ -196,6 +196,7 @@ export const setProvider = (provider, workspaceName) => (dispatch: React.Dispatc
}) })
dispatch(fetchProviderSuccess(provider)) dispatch(fetchProviderSuccess(provider))
dispatch(setCurrentWorkspace(workspaceName)) dispatch(setCurrentWorkspace(workspaceName))
dispatch(setPlugin(plugin))
} else { } else {
dispatch(fetchProviderError('No provider available')) dispatch(fetchProviderError('No provider available'))
} }
@ -208,6 +209,13 @@ export const setCurrentWorkspace = (name: string) => {
} }
} }
export const setPlugin = (plugin) => {
return {
type: 'SET_PLUGIN',
payload: plugin
}
}
export const addInputFieldSuccess = (path: string, files: File[]) => { export const addInputFieldSuccess = (path: string, files: File[]) => {
return { return {
type: 'ADD_INPUT_FIELD', type: 'ADD_INPUT_FIELD',

@ -8,7 +8,7 @@ import { FileExplorerMenu } from './file-explorer-menu' // eslint-disable-line
import { FileExplorerContextMenu } from './file-explorer-context-menu' // eslint-disable-line import { FileExplorerContextMenu } from './file-explorer-context-menu' // eslint-disable-line
import { FileExplorerProps, File } from './types' import { FileExplorerProps, File } from './types'
import { fileSystemReducer, fileSystemInitialState } from './reducers/fileSystem' import { fileSystemReducer, fileSystemInitialState } from './reducers/fileSystem'
import { fetchDirectory, setProvider, resolveDirectory, addInputField, removeInputField } from './actions/fileSystem' import { fetchDirectory, init, resolveDirectory, addInputField, removeInputField } from './actions/fileSystem'
import * as helper from '../../../../../apps/remix-ide/src/lib/helper' import * as helper from '../../../../../apps/remix-ide/src/lib/helper'
import QueryParams from '../../../../../apps/remix-ide/src/lib/query-params' import QueryParams from '../../../../../apps/remix-ide/src/lib/query-params'
@ -108,7 +108,7 @@ export const FileExplorer = (props: FileExplorerProps) => {
useEffect(() => { useEffect(() => {
if (props.filesProvider) { if (props.filesProvider) {
setProvider(props.filesProvider, props.name)(dispatch) init(props.filesProvider, props.name, props.plugin)(dispatch)
} }
}, [props.filesProvider]) }, [props.filesProvider])
@ -361,6 +361,7 @@ export const FileExplorer = (props: FileExplorerProps) => {
} }
const uploadFile = (target) => { const uploadFile = (target) => {
const filesProvider = fileSystem.provider.provider
// TODO The file explorer is merely a view on the current state of // TODO The file explorer is merely a view on the current state of
// the files module. Please ask the user here if they want to overwrite // the files module. Please ask the user here if they want to overwrite
// a file and then just use `files.add`. The file explorer will // a file and then just use `files.add`. The file explorer will
@ -433,6 +434,7 @@ export const FileExplorer = (props: FileExplorerProps) => {
} }
const toGist = (id?: string) => { const toGist = (id?: string) => {
const filesProvider = fileSystem.provider.provider
const proccedResult = function (error, data) { const proccedResult = function (error, data) {
if (error) { if (error) {
modal('Publish to gist Failed', 'Failed to manage gist: ' + error, { modal('Publish to gist Failed', 'Failed to manage gist: ' + error, {
@ -549,6 +551,8 @@ export const FileExplorer = (props: FileExplorerProps) => {
} }
const runScript = async (path: string) => { const runScript = async (path: string) => {
const filesProvider = fileSystem.provider.provider
filesProvider.get(path, (error, content: string) => { filesProvider.get(path, (error, content: string) => {
if (error) return console.log(error) if (error) return console.log(error)
plugin.call('scriptRunner', 'execute', content) plugin.call('scriptRunner', 'execute', content)

@ -19,6 +19,12 @@ export const fileSystemInitialState = {
isRequesting: false, isRequesting: false,
isSuccessful: false, isSuccessful: false,
error: null error: null
},
plugin: {
plugin: null,
isRequesting: false,
isSuccessful: false,
error: null
} }
} }
@ -135,6 +141,18 @@ export const fileSystemReducer = (state = fileSystemInitialState, action: Action
} }
} }
} }
case 'SET_PLUGIN': {
return {
...state,
plugin: {
...state.plugin,
plugin: action.payload,
isRequesting: false,
isSuccessful: true,
error: null
}
}
}
case 'ADD_INPUT_FIELD': { case 'ADD_INPUT_FIELD': {
return { return {
...state, ...state,

Loading…
Cancel
Save