1
0
mirror of https://github.com/sasjs/server.git synced 2025-12-11 19:44:35 +00:00

fix(web): when no file is selected save the editor content to local storage

This commit is contained in:
2022-07-26 23:30:41 +05:00
parent 3c987c61dd
commit 3b1fcb937d

View File

@@ -102,7 +102,7 @@ const SASjsEditor = ({
usePrompt( usePrompt(
'Changes you made may not be saved.', 'Changes you made may not be saved.',
prevFileContent !== fileContent prevFileContent !== fileContent && !!selectedFilePath
) )
useEffect(() => { useEffect(() => {
@@ -134,11 +134,18 @@ const SASjsEditor = ({
}) })
.finally(() => setIsLoading(false)) .finally(() => setIsLoading(false))
} else { } else {
setFileContent('') const content = localStorage.getItem('fileContent') ?? ''
setFileContent(content)
} }
// eslint-disable-next-line react-hooks/exhaustive-deps // eslint-disable-next-line react-hooks/exhaustive-deps
}, [selectedFilePath]) }, [selectedFilePath])
useEffect(() => {
if (fileContent.length && !selectedFilePath) {
localStorage.setItem('fileContent', fileContent)
}
}, [fileContent, selectedFilePath])
useEffect(() => { useEffect(() => {
if (runTimes.includes(selectedFileExtension)) if (runTimes.includes(selectedFileExtension))
setSelectedRunTime(selectedFileExtension) setSelectedRunTime(selectedFileExtension)