|
| 1 | +/* eslint-disable @nrwl/nx/enforce-module-boundaries */ |
| 2 | +import React from 'react' |
| 3 | +import { AppAction, AppState } from '@remix-ui/app' |
| 4 | +import { PluginViewWrapper } from '@remix-ui/helper' |
| 5 | +import { Plugin } from '@remixproject/engine' |
| 6 | +import { EventEmitter } from 'events' |
| 7 | +import { RemixUiGenericModal, RemixUiGenericModalProps } from 'libs/remix-ui/generic-modal/src/lib/remix-ui-generic-modal' |
| 8 | + |
| 9 | +const pluginProfile = { |
| 10 | + name: 'remix-generic-modal', |
| 11 | + displayName: 'Remix Generic Modal', |
| 12 | + description: 'Remix Generic Modal for every type of content meant for a modal', |
| 13 | + methods: ['openModal'] |
| 14 | +} |
| 15 | + |
| 16 | +export class TemplateExplorerModalPlugin extends Plugin { |
| 17 | + element: HTMLDivElement |
| 18 | + dispatch: React.Dispatch<any> = () => { } |
| 19 | + event: any |
| 20 | + appStateDispatch: any |
| 21 | + constructor() { |
| 22 | + super(pluginProfile) |
| 23 | + this.element = document.createElement('div') |
| 24 | + this.element.setAttribute('id', 'remix-generic-modal') |
| 25 | + this.dispatch = () => { } |
| 26 | + this.event = new EventEmitter() |
| 27 | + } |
| 28 | + |
| 29 | + async onActivation(): Promise<void> { |
| 30 | + |
| 31 | + } |
| 32 | + |
| 33 | + onDeactivation(): void { |
| 34 | + this.element.remove() |
| 35 | + } |
| 36 | + |
| 37 | + setDispatch(dispatch: React.Dispatch<any>) { |
| 38 | + this.dispatch = dispatch |
| 39 | + this.renderComponent() |
| 40 | + } |
| 41 | + |
| 42 | + setAppStateDispatch(appStateDispatch: React.Dispatch<AppAction>) { |
| 43 | + this.appStateDispatch = appStateDispatch |
| 44 | + } |
| 45 | + |
| 46 | + render() { |
| 47 | + return ( |
| 48 | + <div id="inner-remix-generic-modal"> |
| 49 | + <PluginViewWrapper plugin={this} useAppContext={true} /> |
| 50 | + </div> |
| 51 | + ) |
| 52 | + } |
| 53 | + |
| 54 | + renderComponent(): void { |
| 55 | + this.dispatch({ |
| 56 | + element: this.element, |
| 57 | + }) |
| 58 | + } |
| 59 | + |
| 60 | + updateComponent(state: RemixUiGenericModalProps, appState: AppState) { |
| 61 | + return ( |
| 62 | + <RemixUiGenericModal |
| 63 | + appState={appState} |
| 64 | + dispatch={this.dispatch} |
| 65 | + plugin={this} |
| 66 | + /> |
| 67 | + ) |
| 68 | + } |
| 69 | +} |
0 commit comments