From ed03204f25e8e426d2da23899a9a29a151be57cf Mon Sep 17 00:00:00 2001 From: ioedeveloper Date: Sat, 24 Apr 2021 17:50:26 +0100 Subject: [PATCH] Init plugin --- .../src/lib/actions/fileSystem.ts | 10 +++++++++- .../file-explorer/src/lib/file-explorer.tsx | 8 ++++++-- .../src/lib/reducers/fileSystem.ts | 18 ++++++++++++++++++ 3 files changed, 33 insertions(+), 3 deletions(-) diff --git a/libs/remix-ui/file-explorer/src/lib/actions/fileSystem.ts b/libs/remix-ui/file-explorer/src/lib/actions/fileSystem.ts index 92beacb84a..e3dc559a4b 100644 --- a/libs/remix-ui/file-explorer/src/lib/actions/fileSystem.ts +++ b/libs/remix-ui/file-explorer/src/lib/actions/fileSystem.ts @@ -172,7 +172,7 @@ export const fileRemovedSuccess = (path: string, removePath: string) => { } } -export const setProvider = (provider, workspaceName) => (dispatch: React.Dispatch) => { +export const init = (provider, workspaceName: string, plugin) => (dispatch: React.Dispatch) => { if (provider) { provider.event.register('fileAdded', async (filePath) => { const path = extractParentFromKey(filePath) || workspaceName @@ -196,6 +196,7 @@ export const setProvider = (provider, workspaceName) => (dispatch: React.Dispatc }) dispatch(fetchProviderSuccess(provider)) dispatch(setCurrentWorkspace(workspaceName)) + dispatch(setPlugin(plugin)) } else { 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[]) => { return { type: 'ADD_INPUT_FIELD', diff --git a/libs/remix-ui/file-explorer/src/lib/file-explorer.tsx b/libs/remix-ui/file-explorer/src/lib/file-explorer.tsx index 35cf6149cc..2430b8e0f6 100644 --- a/libs/remix-ui/file-explorer/src/lib/file-explorer.tsx +++ b/libs/remix-ui/file-explorer/src/lib/file-explorer.tsx @@ -8,7 +8,7 @@ import { FileExplorerMenu } from './file-explorer-menu' // eslint-disable-line import { FileExplorerContextMenu } from './file-explorer-context-menu' // eslint-disable-line import { FileExplorerProps, File } from './types' 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 QueryParams from '../../../../../apps/remix-ide/src/lib/query-params' @@ -108,7 +108,7 @@ export const FileExplorer = (props: FileExplorerProps) => { useEffect(() => { if (props.filesProvider) { - setProvider(props.filesProvider, props.name)(dispatch) + init(props.filesProvider, props.name, props.plugin)(dispatch) } }, [props.filesProvider]) @@ -361,6 +361,7 @@ export const FileExplorer = (props: FileExplorerProps) => { } const uploadFile = (target) => { + const filesProvider = fileSystem.provider.provider // 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 // 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 filesProvider = fileSystem.provider.provider const proccedResult = function (error, data) { if (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 filesProvider = fileSystem.provider.provider + filesProvider.get(path, (error, content: string) => { if (error) return console.log(error) plugin.call('scriptRunner', 'execute', content) diff --git a/libs/remix-ui/file-explorer/src/lib/reducers/fileSystem.ts b/libs/remix-ui/file-explorer/src/lib/reducers/fileSystem.ts index ba05a57d9b..4f25db4eb7 100644 --- a/libs/remix-ui/file-explorer/src/lib/reducers/fileSystem.ts +++ b/libs/remix-ui/file-explorer/src/lib/reducers/fileSystem.ts @@ -19,6 +19,12 @@ export const fileSystemInitialState = { isRequesting: false, isSuccessful: false, 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': { return { ...state,