pull/5371/head
bunsenstraat 2 weeks ago committed by bunsenstraat
parent 9734f542d6
commit d244c909be
  1. 6
      apps/remix-ide/src/app/components/popup-panel.tsx
  2. 37
      libs/remix-ui/helper/src/lib/components/PluginViewWrapper.tsx

@ -80,14 +80,14 @@ export class PopupPanel extends AbstractPanel {
render() { render() {
return ( return (
<PluginViewWrapper plugin={this} /> <PluginViewWrapper useAppContext={true} plugin={this} />
) )
} }
updateComponent(state: popupPanelState & Partial<AppState>) { updateComponent(state: popupPanelState, appState: Partial<AppState>) {
return ( return (
<div <div
className={'px-0 bg-light border-info ' + (!state.showPopupPanel ? 'd-none' : 'd-flex')} className={`px-0 bg-light border-info ${appState?.showPopupPanel ? 'd-flex' : 'd-none'}`}
style={{ style={{
maxHeight: '40rem', maxHeight: '40rem',
maxWidth: '25rem', maxWidth: '25rem',

@ -1,28 +1,35 @@
import { AppContext } from '@remix-ui/app' import { AppContext } from '@remix-ui/app'
import React, { useContext } from 'react' import React, { useContext, useEffect, useState } from 'react'
import { useEffect, useState } from 'react'
interface IPluginViewWrapperProps { interface IPluginViewWrapperProps {
plugin: any plugin: any
useAppContext?: boolean // Optional flag to decide whether to use AppContext
} }
export const PluginViewWrapper = (props: IPluginViewWrapperProps) => { export const PluginViewWrapper = ({ plugin, useAppContext = false }: IPluginViewWrapperProps) => {
const [state, setState] = useState<any>(null) const [state, setState] = useState<any>(null)
const appContext = useContext(AppContext) const appContext = useAppContext ? useContext(AppContext) : null
useEffect(() => { useEffect(() => {
if (props.plugin.setDispatch) { if (plugin.setDispatch) {
props.plugin.setDispatch(setState) plugin.setDispatch(setState)
} }
if (props.plugin.setAppStateDispatch) { if (useAppContext && appContext.appStateDispatch && plugin.setAppStateDispatch) {
props.plugin.setAppStateDispatch(appContext.appStateDispatch) plugin.setAppStateDispatch(appContext.appStateDispatch)
} }
}, []) }, [plugin])
return <>{state ? <>{props.plugin.updateComponent( if (useAppContext && appContext && appContext.appState) {
{ return (
...state, <>
...appContext['appState'] {state ? <>{plugin.updateComponent(state, appContext.appState)}</> : <></>}
})} </>
</> : <></>}</> )
}
return (
<>
{state ? <>{plugin.updateComponent(state)}</> : <></>}
</>
)
} }

Loading…
Cancel
Save