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

Loading…
Cancel
Save