Clear error message when switching tabs

pull/2093/head
David Disu 3 years ago
parent 6cc3af041a
commit e4c6b1496e
  1. 4
      apps/remix-ide/src/app/tabs/compile-tab.js
  2. 7
      apps/solidity-compiler/src/app/compiler-api.ts
  3. 1
      libs/remix-lib/src/types/ICompilerApi.ts
  4. 12
      libs/remix-ui/solidity-compiler/src/lib/solidity-compiler.tsx
  5. 11
      libs/remix-ui/solidity-compiler/src/lib/types/index.ts

@ -63,6 +63,10 @@ class CompileTab extends CompilerApiMixin(ViewPlugin) { // implements ICompilerA
this.renderComponent()
}
onFileClosed () {
this.renderComponent()
}
onCompilationFinished () {
this.renderComponent()
}

@ -21,6 +21,7 @@ export const CompilerApiMixin = (Base) => class extends Base {
onCompilationFinished: (contractsDetails: any, contractMap: any) => void
onSessionSwitched: () => void
onContentChanged: () => void
onFileClosed: (name: string) => void
initCompilerApi () {
this.configurationSettings = null
@ -249,6 +250,12 @@ export const CompilerApiMixin = (Base) => class extends Base {
}
this.on('fileManager', 'noFileSelected', this.data.eventHandlers.onNoFileSelected)
this.data.eventHandlers.onFileClosed = (name: string) => {
this.onFileClosed(name)
}
this.on('fileManager', 'fileClosed', this.data.eventHandlers.onFileClosed)
this.data.eventHandlers.onCompilationFinished = (success, data, source) => {
this.compileErrors = data
if (success) {

@ -26,6 +26,7 @@ export interface ICompilerApi {
onCompilationFinished: (contractsDetails: any, contractMap: any) => void
onSessionSwitched: () => void
onContentChanged: () => void
onFileClosed: (name: string) => void
resolveContentAndSave: (url: string) => Promise<string>
fileExists: (file: string) => Promise<boolean>

@ -1,5 +1,5 @@
import React, { useEffect, useState } from 'react' // eslint-disable-line
import { SolidityCompilerProps } from './types'
import { CompileErrors, SolidityCompilerProps } from './types'
import { CompilerContainer } from './compiler-container' // eslint-disable-line
import { ContractSelection } from './contract-selection' // eslint-disable-line
import { Toaster } from '@remix-ui/toaster' // eslint-disable-line
@ -9,7 +9,7 @@ import { Renderer } from '@remix-ui/renderer' // eslint-disable-line
import './css/style.css'
export const SolidityCompiler = (props: SolidityCompilerProps) => {
const { api, api: { currentFile, compileTabLogic, contractsDetails, contractMap, compileErrors, configurationSettings } } = props
const { api, api: { currentFile, compileTabLogic, contractsDetails, contractMap, configurationSettings } } = props
const [state, setState] = useState({
isHardhatProject: false,
currentFile,
@ -32,6 +32,7 @@ export const SolidityCompiler = (props: SolidityCompilerProps) => {
})
const [currentVersion, setCurrentVersion] = useState('')
const [hideWarnings, setHideWarnings] = useState<boolean>(false)
const [compileErrors, setCompileErrors] = useState<CompileErrors>(api.compileErrors)
useEffect(() => {
(async () => {
@ -63,12 +64,19 @@ export const SolidityCompiler = (props: SolidityCompilerProps) => {
setState(prevState => {
return { ...prevState, currentFile: '' }
})
setCompileErrors({} as CompileErrors)
}
api.onCompilationFinished = (contractsDetails: any, contractMap: any) => {
setState(prevState => {
return { ...prevState, contractsDetails, contractMap }
})
setCompileErrors(api.compileErrors)
}
api.onFileClosed = (name) => {
console.log('path/name: ', name, currentFile)
if (name === currentFile) setCompileErrors({} as CompileErrors)
}
const toast = (message: string) => {

@ -24,3 +24,14 @@ export interface ContractSelectionProps {
modal: (title: string, message: string | JSX.Element, okLabel: string, okFn: () => void, cancelLabel?: string, cancelFn?: () => void) => void,
contractsDetails: Record<string, any>
}
interface CompileError {
mode?: string,
severity?: string,
formattedMessage?: string,
type?: string
}
export interface CompileErrors {
error: CompileError,
errors: CompileError[]
}

Loading…
Cancel
Save