import * as React from "react"; import { JoinAndQuit as Entity, IJoinAndQuitState as Data, } from "@daostack/arc.js"; import { CreateContextFeed } from "../../../runtime/ContextFeed"; import { Arc as Protocol, ArcConfig as ProtocolConfig, Component, ComponentLogs, ComponentProps, Plugin, } from "../../../"; interface RequiredProps extends ComponentProps { // Plugin ID id?: string | Entity; } interface InferredProps extends RequiredProps { config: ProtocolConfig; id: string | Entity; } class InferredJoinAndQuitPlugin extends Component { protected createEntity(): Entity { const { config, id } = this.props; if (!config) { throw Error( "Arc Config Missing: Please provide this field as a prop, or use the inference component." ); } const pluginId = typeof id === "string" ? id : id.id; return new Entity(config.connection, pluginId); } public static get Entity() { return CreateContextFeed( this.EntityContext.Consumer, this.LogsContext.Consumer, "JoinAndQuitPlugin" ); } public static get Data() { return CreateContextFeed( this.DataContext.Consumer, this.LogsContext.Consumer, "JoinAndQuitPlugin" ); } public static get Logs() { return CreateContextFeed( this.LogsContext.Consumer, this.LogsContext.Consumer, "JoinAndQuitPlugin" ); } public static EntityContext = React.createContext( undefined ); public static DataContext = React.createContext(undefined); public static LogsContext = React.createContext( undefined ); } function useJoinAndQuitPlugin(): [Data | undefined, Entity | undefined] { const data = React.useContext( InferredJoinAndQuitPlugin.DataContext ); const entity = React.useContext( InferredJoinAndQuitPlugin.EntityContext ); return [data, entity]; } class JoinAndQuitPlugin extends React.Component { public render() { const { id, children } = this.props; const renderInferred = (id: string | Entity) => ( {(config: ProtocolConfig) => ( {children} )} ); if (!id) { return ( {(plugin: Entity) => renderInferred(plugin.id)} ); } else { return renderInferred(id); } } public static get Entity() { return InferredJoinAndQuitPlugin.Entity; } public static get Data() { return InferredJoinAndQuitPlugin.Data; } public static get Logs() { return InferredJoinAndQuitPlugin.Logs; } } export default JoinAndQuitPlugin; export { JoinAndQuitPlugin, InferredJoinAndQuitPlugin, Entity as JoinAndQuitPluginEntity, Data as JoinAndQuitPluginData, useJoinAndQuitPlugin, };