Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

style of ask gpt and infinit loop and other issues fix #4080

Merged
merged 5 commits into from
Sep 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion apps/remix-ide/src/remixAppManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,8 @@ const requiredModules = [
'codeFormatter',
'solidityumlgen',
'contractflattener',
'solidity-script'
'solidity-script',
'openaigpt'
]

// dependentModules shouldn't be manually activated (e.g hardhat is activated by remixd)
Expand Down
2 changes: 0 additions & 2 deletions libs/remix-ui/renderer/src/lib/renderer.css
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,6 @@
.remixui_sol.success a,
.remixui_sol.error a,
.remixui_sol.warning a {
position: absolute;
bottom: 0;
right: 0;
padding: 0.25rem;
}
11 changes: 9 additions & 2 deletions libs/remix-ui/renderer/src/lib/renderer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import React, {useEffect, useState} from 'react' //eslint-disable-line
import {CopyToClipboard} from '@remix-ui/clipboard'
import {helper} from '@remix-project/remix-solidity'
import './renderer.css'
const _paq = (window._paq = window._paq || [])

interface RendererProps {
message: any
opt?: any
Expand Down Expand Up @@ -76,6 +78,7 @@ export const Renderer = ({message, opt = {}, plugin}: RendererProps) => {
explain why the error occurred and how to fix it.
`
await plugin.call('openaigpt', 'message', message)
_paq.push(['trackEvent', 'GPTSupport', 'askGPT'])
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Most of the places, we use 4 fields for this

} catch (err) {
console.error('unable to askGtp')
console.error(err)
Expand All @@ -96,8 +99,12 @@ export const Renderer = ({message, opt = {}, plugin}: RendererProps) => {
<div className="close" data-id="renderer" onClick={handleClose}>
<i className="fas fa-times"></i>
</div>
<CopyToClipboard content={messageText} className={` p-0 m-0 far fa-copy ${classList}`} direction={'top'} />
<span onClick={() => { askGtp() }}>ASK GPT</span>
<div className="d-flex pt-1 flex-row-reverse">
<span className="ml-3 pt-1 py-1" >
<CopyToClipboard content={messageText} className={` p-0 m-0 far fa-copy ${classList}`} direction={'top'} />
</span>
<span className="border border-success text-success btn-sm" onClick={() => { askGtp() }}>ASK GPT</span>
</div>
</div>
)}
</>
Expand Down
22 changes: 16 additions & 6 deletions libs/remix-ui/terminal/src/lib/remix-ui-terminal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -734,9 +734,13 @@ export const RemixUiTerminal = (props: RemixUiTerminalProps) => {
if (x.typewriter && !typeWriterIndexes.current.includes(index)) {
typeWriterIndexes.current.push(index)
return (
<div className={classNameBlock} data-id="block" key={index}> <span ref={(element) => {
typewrite(element, msg ? msg.toString() : null)
}} className={x.style}></span></div>
<div className={classNameBlock} data-id="block" key={index}>
<span ref={(element) => {
typewrite(element, msg ? msg.toString() : null, () => scrollToBottom()
)
}} className={x.style}>
</span>
</div>
)
} else {
return (
Expand All @@ -751,7 +755,7 @@ export const RemixUiTerminal = (props: RemixUiTerminalProps) => {
typeWriterIndexes.current.push(index)
return (
<div className={classNameBlock} data-id="block" key={index}> <span ref={(element) => {
typewrite(element, x.message)
typewrite(element, x.message, () => scrollToBottom())
}} className={x.style}></span></div>
)
} else {
Expand Down Expand Up @@ -800,13 +804,19 @@ export const RemixUiTerminal = (props: RemixUiTerminalProps) => {
)
}

const typewrite = (elementsRef, message) => {
const typewrite = (elementsRef, message, callback) => {
(() => {
let count = 0
const id = setInterval(() => {
if (!elementsRef) return
count++
elementsRef.innerText = message.substr(0, count)
if (message === count) clearInterval(id)
// scroll when new line ` <br>
if (elementsRef.lastChild.tagName === `BR`) callback()
if (message.length === count) {
clearInterval(id)
callback()
}
}, 5)
})()
}
Expand Down
Loading