From 3c951a9cbfadef5d08dc531f6cb711c226e5ac84 Mon Sep 17 00:00:00 2001 From: joseph izang Date: Sat, 24 Jul 2021 00:54:22 +0100 Subject: [PATCH] create separate plugincards for active and inactive state. create custom hook for localstorage and method to handle pluginManager state --- .../components/plugin-manager-component.js | 71 +++-------------- .../src/lib/components/ActivateButton.tsx | 29 ------- .../src/lib/components/ActivePluginCard.tsx | 76 +++++++++++++++++++ .../src/lib/components/InactivePluginCard.tsx | 67 ++++++++++++++++ .../src/lib/components/deactivateButton.tsx | 28 ------- .../permissions/permissionsSettings.tsx | 20 ----- .../src/lib/components/pluginCard.tsx | 37 +++++---- .../src/lib/components/rootView.tsx | 20 +++-- .../src/lib/contexts/pluginmanagercontext.tsx | 14 ---- .../plugin-manager/src/lib/useLocalStorage.ts | 61 +++++++++++++++ .../src/pluginManagerStateMachine.ts | 75 ++++++++++++++++++ libs/remix-ui/plugin-manager/src/types.d.ts | 5 +- 12 files changed, 330 insertions(+), 173 deletions(-) delete mode 100644 libs/remix-ui/plugin-manager/src/lib/components/ActivateButton.tsx create mode 100644 libs/remix-ui/plugin-manager/src/lib/components/ActivePluginCard.tsx create mode 100644 libs/remix-ui/plugin-manager/src/lib/components/InactivePluginCard.tsx delete mode 100644 libs/remix-ui/plugin-manager/src/lib/components/deactivateButton.tsx delete mode 100644 libs/remix-ui/plugin-manager/src/lib/contexts/pluginmanagercontext.tsx create mode 100644 libs/remix-ui/plugin-manager/src/lib/useLocalStorage.ts create mode 100644 libs/remix-ui/plugin-manager/src/pluginManagerStateMachine.ts diff --git a/apps/remix-ide/src/app/components/plugin-manager-component.js b/apps/remix-ide/src/app/components/plugin-manager-component.js index 96c1f1ab85..781bc51516 100644 --- a/apps/remix-ide/src/app/components/plugin-manager-component.js +++ b/apps/remix-ide/src/app/components/plugin-manager-component.js @@ -1,3 +1,4 @@ +/* eslint-disable no-debugger */ /* eslint-disable no-unused-vars */ import { IframePlugin, @@ -16,66 +17,6 @@ const LocalPlugin = require('./local-plugin') // eslint-disable-line const addToolTip = require('../ui/tooltip') const _paq = window._paq = window._paq || [] -const css = csjs` - .pluginSearch { - display: flex; - flex-direction: column; - align-items: center; - background-color: var(--light); - padding: 10px; - position: sticky; - top: 0; - z-index: 2; - margin-bottom: 0px; - } - .pluginSearchInput { - height: 38px; - } - .pluginSearchButton { - font-size: 13px; - } - .displayName { - width: 100%; - display: flex; - align-items: center; - justify-content: space-between; - } - .pluginIcon { - height: 0.7rem; - width: 0.7rem; - filter: invert(0.5); - } - .description { - font-size: 13px; - line-height: 18px; - } - .descriptiontext { - display: block; - } - .descriptiontext:first-letter { - text-transform: uppercase; - } - .row { - display: flex; - flex-direction: row; - } - .isStuck { - background-color: var(--primary); - color: - } - .versionWarning { - padding: 4px; - margin: 0 8px; - font-weight: 700; - font-size: 9px; - line-height: 12px; - text-transform: uppercase; - cursor: default; - border: 1px solid; - border-radius: 2px; - } -` - const profile = { name: 'pluginManager', displayName: 'Plugin manager', @@ -107,6 +48,12 @@ class PluginManagerComponent extends ViewPlugin { this.pluginNames = this.appManager.actives this.activePlugins = [] this.inactivePlugins = [] + this.activeProfiles = this.appManager.actives + this._paq = _paq + } + + triggerEngineEventListener () { + this.engine.event.on('onRegistration', () => this.getAndFilterPlugins()) } /** @@ -128,6 +75,7 @@ class PluginManagerComponent extends ViewPlugin { this.appManager.activatePlugin(name) this.appManager.event.on('activate', () => { this.getAndFilterPlugins() + this.triggerEngineEventListener() }) _paq.push(['trackEvent', 'manager', 'activate', name]) } @@ -139,6 +87,7 @@ class PluginManagerComponent extends ViewPlugin { * @param {string} name name of Plugin */ deactivateP (name) { + debugger this.call('manager', 'deactivatePlugin', name) _paq.push(['trackEvent', 'manager', 'deactivate', name]) this.getAndFilterPlugins() @@ -214,7 +163,7 @@ class PluginManagerComponent extends ViewPlugin { }) this.activePlugins = activatedPlugins this.inactivePlugins = deactivatedPlugins - + console.log('The Length of appManager.actives is :', this.activeProfiles) this.renderComponent() } } diff --git a/libs/remix-ui/plugin-manager/src/lib/components/ActivateButton.tsx b/libs/remix-ui/plugin-manager/src/lib/components/ActivateButton.tsx deleted file mode 100644 index 586a89d8a8..0000000000 --- a/libs/remix-ui/plugin-manager/src/lib/components/ActivateButton.tsx +++ /dev/null @@ -1,29 +0,0 @@ -import React, { useState } from 'react' -import { PluginManagerComponent } from '../../types' - -interface ActivateButtonProps { - buttonText: string - pluginName: string - pluginComponent: PluginManagerComponent -} - -function ActivateButton ({ - buttonText, - pluginName, - pluginComponent -}: ActivateButtonProps) { - const [dataId] = useState(`pluginManagerComponent${buttonText}Button${pluginName}`) - - return ( - - ) -} -export default ActivateButton diff --git a/libs/remix-ui/plugin-manager/src/lib/components/ActivePluginCard.tsx b/libs/remix-ui/plugin-manager/src/lib/components/ActivePluginCard.tsx new file mode 100644 index 0000000000..e6e5205973 --- /dev/null +++ b/libs/remix-ui/plugin-manager/src/lib/components/ActivePluginCard.tsx @@ -0,0 +1,76 @@ +import { Profile } from '@remixproject/plugin-utils' +import React, { useState } from 'react' +import { RemoveActivatedPlugin } from '../../pluginManagerStateMachine' +// import { RemoveActivatedPlugin } from '../../pluginManagerStateMachine' +import { PluginManagerComponent } from '../../types' +import '../remix-ui-plugin-manager.css' +interface PluginCardProps { + profile: Profile & { + icon?: string + } + pluginComponent: PluginManagerComponent + buttonText: string + reRender: () => void +} + +// eslint-disable-next-line no-empty-pattern +function ActivePluginCard ({ + profile, + pluginComponent, + buttonText, + reRender +}: PluginCardProps) { + const [displayName] = useState((profile.displayName) ? profile.displayName : profile.name) + const [docLink] = useState((profile.documentation) ? ( + +