Skip to content

Commit 9ad62cd

Browse files
STetsingAniket-Engg
authored andcommitted
considered window already opened
1 parent 9ea24da commit 9ad62cd

File tree

2 files changed

+30
-28
lines changed

2 files changed

+30
-28
lines changed

Diff for: apps/remix-ide/src/app/components/popup-panel.tsx

+30-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { PluginRecord, RemixPluginPanel } from '@remix-ui/panel'
44
import packageJson from '../../../../../package.json'
55
import { PluginViewWrapper } from '@remix-ui/helper'
66
import { EventEmitter } from 'events'
7+
import DOMPurify from 'dompurify';
78

89
import { AppAction, appActionTypes, AppState } from '@remix-ui/app'
910

@@ -23,6 +24,7 @@ export class PopupPanel extends AbstractPanel {
2324
element: HTMLDivElement
2425
dispatch: React.Dispatch<any> = () => { }
2526
appStateDispatch: React.Dispatch<AppAction> = () => { }
27+
hooks: boolean = false
2628

2729
constructor(config = null) {
2830
super(profile)
@@ -64,7 +66,6 @@ export class PopupPanel extends AbstractPanel {
6466
}
6567

6668
async showPopupPanel(show) {
67-
6869
this.appStateDispatch({
6970
type: appActionTypes.setShowPopupPanel,
7071
payload: show
@@ -85,6 +86,34 @@ export class PopupPanel extends AbstractPanel {
8586
}
8687

8788
updateComponent(state: popupPanelState, appState: Partial<AppState>) {
89+
if (!this.hooks) {
90+
try {
91+
const markdown = document.getElementsByClassName('nlux-composer-container')
92+
const button = markdown[0].getElementsByTagName('button')[0]
93+
const textArea = markdown[0].getElementsByTagName('textarea')[0]
94+
// only add event listeners if they are not already added
95+
if (!textArea.dataset.listenerAdded) {
96+
textArea.addEventListener('input', (event) => {
97+
const sanitizedInput = DOMPurify.sanitize(textArea.value)
98+
if (sanitizedInput !== textArea.value) {
99+
textArea.value = sanitizedInput
100+
}
101+
})
102+
textArea.dataset.listenerAdded = 'true'
103+
}
104+
105+
if (!button.dataset.listenerAdded) {
106+
button.dataset.listenerAdded = 'true'
107+
button.addEventListener('click', (event) => {
108+
const sanitizedInput = DOMPurify.sanitize(textArea.value)
109+
if (sanitizedInput !== textArea.value) {
110+
textArea.value = sanitizedInput
111+
}
112+
})
113+
}
114+
this.hooks = true
115+
} catch (error) { this.hooks = false }
116+
}
88117
return (
89118
<div
90119
className={`px-0 bg-light border-info ${appState?.showPopupPanel ? 'd-flex' : 'd-none'}`}

Diff for: libs/remix-ui/statusbar/src/lib/components/aiStatus.tsx

-27
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import { StatusBar } from 'apps/remix-ide/src/app/components/status-bar'
33
import { CustomTooltip } from '@remix-ui/helper'
44
import React, { useContext, useEffect, useState } from 'react'
55
import { appActionTypes, AppContext } from '@remix-ui/app'
6-
import DOMPurify from 'dompurify';
76

87
interface AIStatusProps {
98
plugin: StatusBar
@@ -100,32 +99,6 @@ export default function AIStatus(props: AIStatusProps) {
10099
data-id="aiStatusButton"
101100
className='aiButton d-flex align-items-center h3 p-1'
102101
onClick={async () => {
103-
try {
104-
const markdown = document.getElementsByClassName('nlux-composer-container')
105-
const button = markdown[0].getElementsByTagName('button')[0]
106-
const textArea = markdown[0].getElementsByTagName('textarea')[0]
107-
108-
// only add event listeners if they are not already added
109-
if (!textArea.dataset.listenerAdded) {
110-
textArea.addEventListener('input', (event) => {
111-
const sanitizedInput = DOMPurify.sanitize(textArea.value)
112-
if (sanitizedInput !== textArea.value) {
113-
textArea.value = sanitizedInput
114-
}
115-
})
116-
textArea.dataset.listenerAdded = 'true'
117-
}
118-
119-
if (!button.dataset.listenerAdded) {
120-
button.dataset.listenerAdded = 'true'
121-
button.addEventListener('click', (event) => {
122-
const sanitizedInput = DOMPurify.sanitize(textArea.value)
123-
if (sanitizedInput !== textArea.value) {
124-
textArea.value = sanitizedInput
125-
}
126-
})
127-
}
128-
} catch (error) { }
129102
appContext.appStateDispatch({
130103
type: appActionTypes.setShowPopupPanel,
131104
payload: !appContext.appState.showPopupPanel

0 commit comments

Comments
 (0)