From fac93dc375ae5244d8e04edc16c49fed0f1414c8 Mon Sep 17 00:00:00 2001 From: bunsenstraat Date: Mon, 4 Nov 2024 13:36:36 +0100 Subject: [PATCH] fix state --- .../src/app/components/popup-panel.tsx | 2 +- .../src/app/plugins/remixAIPlugin.tsx | 17 ++++---------- .../src/lib/plugins/popuppanel-api.ts | 10 ++++++++ libs/remix-api/src/lib/plugins/remixai-api.ts | 1 - .../src/lib/plugins/remixaiDesktop-api.ts | 23 ------------------- libs/remix-api/src/lib/remix-api.ts | 7 ++---- .../remix-ai/src/lib/components/RemixAI.tsx | 6 +---- .../statusbar/src/lib/components/aiStatus.tsx | 13 ++++++----- 8 files changed, 25 insertions(+), 54 deletions(-) create mode 100644 libs/remix-api/src/lib/plugins/popuppanel-api.ts delete mode 100644 libs/remix-api/src/lib/plugins/remixaiDesktop-api.ts diff --git a/apps/remix-ide/src/app/components/popup-panel.tsx b/apps/remix-ide/src/app/components/popup-panel.tsx index 2712b0725d..3b9af9ff23 100644 --- a/apps/remix-ide/src/app/components/popup-panel.tsx +++ b/apps/remix-ide/src/app/components/popup-panel.tsx @@ -12,7 +12,7 @@ const profile = { displayName: 'Popup Panel', description: 'Remix IDE popup panel', version: packageJson.version, - events: ['popupPanelShown'], + events: [], methods: ['addView', 'removeView', 'showContent', 'showPopupPanel'] } type popupPanelState = { diff --git a/apps/remix-ide/src/app/plugins/remixAIPlugin.tsx b/apps/remix-ide/src/app/plugins/remixAIPlugin.tsx index eb5ef592a4..5bb7ac7e93 100644 --- a/apps/remix-ide/src/app/plugins/remixAIPlugin.tsx +++ b/apps/remix-ide/src/app/plugins/remixAIPlugin.tsx @@ -10,10 +10,6 @@ import { PluginViewWrapper } from '@remix-ui/helper' type chatRequestBufferT = { [key in keyof T]: T[key] } -enum AIChatViewState { - minimized = 0, - open = 1 -} const profile = { name: 'remixAI', @@ -53,7 +49,7 @@ export class RemixAIPlugin extends ViewPlugin { } onActivation(): void { - //this.renderComponent(AIChatViewState.open) + if (this.isOnDesktop) { console.log('Activating RemixAIPlugin on desktop') // this.on(this.remixDesktopPluginName, 'activated', () => { @@ -66,10 +62,6 @@ export class RemixAIPlugin extends ViewPlugin { this.initialize() } } - - toggle (open: AIChatViewState) { - this.renderComponent(open) - } async initialize(model1?:IModel, model2?:IModel, remoteModel?:IRemoteModel, useRemote?:boolean){ if (this.isOnDesktop && !this.useRemoteInferencer) { @@ -220,13 +212,12 @@ export class RemixAIPlugin extends ViewPlugin { setDispatch(dispatch) { this.dispatch = dispatch - this.renderComponent(AIChatViewState.open) + this.renderComponent() } - renderComponent (open: AIChatViewState) { + renderComponent () { this.dispatch({ plugin: this, - openState: open }) } @@ -247,7 +238,7 @@ export class RemixAIPlugin extends ViewPlugin { updateComponent(state) { return ( - + ) } } diff --git a/libs/remix-api/src/lib/plugins/popuppanel-api.ts b/libs/remix-api/src/lib/plugins/popuppanel-api.ts new file mode 100644 index 0000000000..040a70bc0a --- /dev/null +++ b/libs/remix-api/src/lib/plugins/popuppanel-api.ts @@ -0,0 +1,10 @@ +import { IFilePanel } from '@remixproject/plugin-api' +import { StatusEvents } from '@remixproject/plugin-utils' + +export interface IPopupPanelAPI { + events:{ + } & StatusEvents + methods: { + showPopupPanel(state: boolean): void + } +} diff --git a/libs/remix-api/src/lib/plugins/remixai-api.ts b/libs/remix-api/src/lib/plugins/remixai-api.ts index 799b180662..0ea1498151 100644 --- a/libs/remix-api/src/lib/plugins/remixai-api.ts +++ b/libs/remix-api/src/lib/plugins/remixai-api.ts @@ -19,6 +19,5 @@ export interface IRemixAI { chatPipe(pipeMessage: string): Promise, ProcessChatRequestBuffer(params:IParams): Promise, initialize(model1?:IModel, model2?:IModel, remoteModel?:IRemoteModel, useRemote?:boolean): Promise, - toggle(boolean) } } \ No newline at end of file diff --git a/libs/remix-api/src/lib/plugins/remixaiDesktop-api.ts b/libs/remix-api/src/lib/plugins/remixaiDesktop-api.ts deleted file mode 100644 index dc9deb7e82..0000000000 --- a/libs/remix-api/src/lib/plugins/remixaiDesktop-api.ts +++ /dev/null @@ -1,23 +0,0 @@ -import { IParams } from "@remix/remix-ai-core"; -import { StatusEvents } from "@remixproject/plugin-utils"; - -export interface IRemixAID { - events: { - activated():void, - onInference():void, - onInferenceDone():void, - onStreamResult(streamText: string):void, - - } & StatusEvents, - methods: { - code_completion(context: string): Promise - code_insertion(msg_pfx: string, msg_sfx: string): Promise, - code_generation(prompt: string): Promise, - code_explaining(code: string, context?: string): Promise, - error_explaining(prompt: string): Promise, - solidity_answer(prompt: string): Promise, - initializeModelBackend(local: boolean, generalModel?, completionModel?): Promise, - chatPipe(pipeMessage: string): Promise, - ProcessChatRequestBuffer(params:IParams): Promise, - } -} \ No newline at end of file diff --git a/libs/remix-api/src/lib/remix-api.ts b/libs/remix-api/src/lib/remix-api.ts index da580b7026..7df4dc7104 100644 --- a/libs/remix-api/src/lib/remix-api.ts +++ b/libs/remix-api/src/lib/remix-api.ts @@ -18,14 +18,11 @@ import { IRemixAID } from "./plugins/remixAIDesktop-api" import { IMenuIconsApi } from "./plugins/menuicons-api" import { IDgitPlugin } from "./plugins/dgitplugin-api" import { Api } from "@remixproject/plugin-utils"; +import { IPopupPanelAPI } from "./plugins/popuppanel-api" export interface ICustomRemixApi extends IRemixApi { - popupPanel: { - methods: ['showPopupPanel'] - events: ['popupPanelShown'] - showPopupPanel(): void - } & Api + popupPanel: IPopupPanelAPI dgitApi: IGitApi dgit: IDgitPlugin config: IConfigApi diff --git a/libs/remix-ui/remix-ai/src/lib/components/RemixAI.tsx b/libs/remix-ui/remix-ai/src/lib/components/RemixAI.tsx index 61b5910913..a5aaba4a7d 100644 --- a/libs/remix-ui/remix-ai/src/lib/components/RemixAI.tsx +++ b/libs/remix-ui/remix-ai/src/lib/components/RemixAI.tsx @@ -1,13 +1,9 @@ import React, { useContext } from 'react' import '../remix-ai.css' import { Default, ChatApi } from './Default' -enum AIChatViewState { - minimized = 0, - open = 1 -} + interface IRemixAITab { plugin: any, - openState: AIChatViewState } export const RemixAITab = (props: IRemixAITab) => { diff --git a/libs/remix-ui/statusbar/src/lib/components/aiStatus.tsx b/libs/remix-ui/statusbar/src/lib/components/aiStatus.tsx index 55b4fbf43d..48864811a2 100644 --- a/libs/remix-ui/statusbar/src/lib/components/aiStatus.tsx +++ b/libs/remix-ui/statusbar/src/lib/components/aiStatus.tsx @@ -1,7 +1,8 @@ // eslint-disable-next-line @nrwl/nx/enforce-module-boundaries import { StatusBar } from 'apps/remix-ide/src/app/components/status-bar' import { CustomTooltip } from '@remix-ui/helper' -import React, { useEffect, useState } from 'react' +import React, { useContext, useEffect, useState } from 'react' +import { appActionTypes, AppContext } from '@remix-ui/app' interface AIStatusProps { plugin: StatusBar @@ -12,7 +13,7 @@ interface AIStatusProps { export default function AIStatus(props: AIStatusProps) { const [copilotActive, setCopilotActive] = useState(false) - + const appContext = useContext(AppContext) useEffect(() => { const run = async () => { @@ -21,9 +22,6 @@ export default function AIStatus(props: AIStatusProps) { } run() - return () => { - props.plugin.off('popupPanel', 'popupPanelShown') - } }, []) useEffect(() => { @@ -65,7 +63,10 @@ export default function AIStatus(props: AIStatusProps) { }} className='p-1 alert alert-info border border-info fa-solid fa-message-bot' onClick={async () => { - await props.plugin.call('popupPanel', 'showPopupPanel', true) + appContext.appStateDispatch({ + type: appActionTypes.setShowPopupPanel, + payload: !appContext.appState.showPopupPanel + }) }} >