fixed workspace change issue

pull/2470/head
lianahus 3 years ago committed by yann300
parent 649693fc3b
commit 3d123440b7
  1. 14
      libs/remix-ui/solidity-compiler/src/lib/compiler-container.tsx

@ -12,6 +12,7 @@ import { CopyToClipboard } from '@remix-ui/clipboard'
import { configFileContent } from './compilerConfiguration'
import './css/style.css'
const defaultPath = "compiler_config.json"
declare global {
interface Window {
@ -66,22 +67,22 @@ export const CompilerContainer = (props: CompilerContainerProps) => {
const [compilerContainer, dispatch] = useReducer(compilerReducer, compilerInitialState)
useEffect(() => {
api.setAppParameter('configFilePath', "compiler_config.json")
api.setAppParameter('configFilePath', defaultPath)
if (state.useFileConfiguration) {
api.fileExists("compiler_config.json").then((exists) => {
api.fileExists(defaultPath).then((exists) => {
if (!exists || state.useFileConfiguration ) createNewConfigFile()
})
}
api.setAppParameter('configFilePath', "compiler_config.json")
api.setAppParameter('configFilePath', defaultPath)
setShowFilePathInput(false)
}, [workspaceName])
useEffect(() => {
if (state.useFileConfiguration)
api.fileExists("compiler_config.json").then((exists) => {
api.fileExists(defaultPath).then((exists) => {
if (!exists || state.useFileConfiguration ) createNewConfigFile()
})
}, [state.useFileConfiguration])
@ -130,7 +131,7 @@ export const CompilerContainer = (props: CompilerContainerProps) => {
const includeNightlies = await api.getAppParameter('includeNightlies') as boolean || false
const useFileConfiguration = await api.getAppParameter('useFileConfiguration') as boolean || false
let configFilePathSaved = await api.getAppParameter('configFilePath')
if (!configFilePathSaved || configFilePathSaved == '') configFilePathSaved = "compiler_config.json"
if (!configFilePathSaved || configFilePathSaved == '') configFilePathSaved = defaultPath
setConfigFilePath(configFilePathSaved)
@ -217,7 +218,7 @@ export const CompilerContainer = (props: CompilerContainerProps) => {
const toggleConfigType = () => {
if (state.useFileConfiguration)
if (state.createFileOnce) {
api.fileExists("compiler_config.json").then((exists) => {
api.fileExists(defaultPath).then((exists) => {
if (!exists || state.useFileConfiguration ) createNewConfigFile()
})
setState(prevState => {
@ -237,6 +238,7 @@ export const CompilerContainer = (props: CompilerContainerProps) => {
const createNewConfigFile = async () => {
let filePath = configFilePathInput.current && configFilePathInput.current.value !== '' ? configFilePathInput.current.value : configFilePath
if (filePath === '') filePath = defaultPath
if (!filePath.endsWith('.json')) filePath = filePath + '.json'
await api.writeFile(filePath, configFileContent)

Loading…
Cancel
Save