pull/1856/head
lianahus 3 years ago committed by yann300
parent 14636a7815
commit 5adf07072a
  1. 48
      libs/remix-ui/editor-context-view/src/lib/remix-ui-editor-context-view.tsx

@ -1,11 +1,27 @@
import React, { useEffect, useState, useRef } from 'react' // eslint-disable-line
import { sourceMappingDecoder } from '@remix-project/remix-debug'
import './remix-ui-editor-context-view.css';
import './remix-ui-editor-context-view.css'
/* eslint-disable-next-line */
export type astNode = {
name: string,
id: number,
children: Array<any>,
typeDescriptions: any,
nodeType: String,
src: any,
nodeId: any,
position: any
}
export type onContextListenerChangedListener = (nodes: Array<astNode>) => void
/* eslint-disable-next-line */
export type gasEstimationType = {
executionCost: string,
codeDepositCost: string
}
export interface RemixUiEditorContextViewProps {
hide: boolean,
gotoLine: (line: number, column: number) => void,
@ -29,25 +45,11 @@ function isDefinition (node: any) {
node.nodeType === 'EventDefinition'
}
export type gasEstimationType = {
executionCost: string,
codeDepositCost: string
}
export type astNode = {
name: string,
id: number,
children: Array<any>,
typeDescriptions: any,
nodeType: String,
src: any,
nodeId: any,
position: any
}
type nullableAstNode = astNode | null
export function RemixUiEditorContextView(props: RemixUiEditorContextViewProps) {
export function RemixUiEditorContextView (props: RemixUiEditorContextViewProps) {
const nodesRef = useRef<Array<astNode>>([])
/*
gotoLineDisableRef is used to temporarily disable the update of the view.
@ -58,7 +60,7 @@ export function RemixUiEditorContextView(props: RemixUiEditorContextViewProps) {
const currentNodeRef = useRef(null as nullableAstNode)
const gasEstimationRef = useRef({} as gasEstimationType)
const gotoLineDisableRef = useRef(false)
const [nodesState, setNode] = useState<Array<astNode>>([])
const [, setNode] = useState<Array<astNode>>([])
useEffect(() => {
props.onContextListenerChanged(async (nodes: Array<astNode>) => {
@ -75,7 +77,7 @@ export function RemixUiEditorContextView(props: RemixUiEditorContextViewProps) {
}
if (currentNodeRef.current) {
referencesRef.current = await props.referencesOf(currentNodeRef.current)
gasEstimationRef.current = await props.gasEstimation(currentNodeRef.current)
gasEstimationRef.current = await props.gasEstimation(currentNodeRef.current)
}
activeHighlightsRef.current = await props.getActiveHighlights()
setNode(nodes)
@ -84,14 +86,14 @@ export function RemixUiEditorContextView(props: RemixUiEditorContextViewProps) {
const _render = (node: nullableAstNode) => {
if (!node) return (<div></div>)
let references = referencesRef.current
const references = referencesRef.current
const type = node.typeDescriptions && node.typeDescriptions.typeString ? node.typeDescriptions.typeString : node.nodeType
let referencesCount = `${references ? references.length : '0'} reference(s)`
const referencesCount = `${references ? references.length : '0'} reference(s)`
let ref = 0
const nodes: Array<astNode> = activeHighlightsRef.current
/*
/*
* show gas estimation
*/
const gasEstimation = () => {
@ -170,7 +172,7 @@ export function RemixUiEditorContextView(props: RemixUiEditorContextViewProps) {
!props.hide && <div className="container-context-view contextviewcontainer bg-light text-dark border-0 py-1">
{_render(currentNodeRef.current)}
</div>
);
)
}
export default RemixUiEditorContextView

Loading…
Cancel
Save