Optimize CodeEditor

This commit is contained in:
2024-01-09 11:42:11 +08:00
parent 3ec95ee8a4
commit 087b632610
3 changed files with 26 additions and 57 deletions

View File

@@ -120,14 +120,15 @@ const FileSelector: React.FC<FileSelectorProps> = ({
}
useEffect(() => {
Object.keys(files).length &&
setTabs(
Object.keys(files).filter(
(item) =>
![IMPORT_MAP_FILE_NAME, ENTRY_FILE_NAME].includes(item) &&
!files[item].hidden
)
)
Object.keys(files).length
? setTabs(
Object.keys(files).filter(
(item) =>
![IMPORT_MAP_FILE_NAME, ENTRY_FILE_NAME].includes(item) &&
!files[item].hidden
)
)
: setTabs([])
}, [files])
return (
@@ -166,14 +167,16 @@ const FileSelector: React.FC<FileSelectorProps> = ({
</FlexBox>
</HideScrollbar>
</div>
<div className={'sticky'}>
<Item
value={'Import Map'}
active={selectedFileName === IMPORT_MAP_FILE_NAME}
onClick={editImportMap}
readonly
/>
</div>
{files[IMPORT_MAP_FILE_NAME] && (
<div className={'sticky'}>
<Item
value={'Import Map'}
active={selectedFileName === IMPORT_MAP_FILE_NAME}
onClick={editImportMap}
readonly
/>
</div>
)}
</div>
</>
)

View File

@@ -83,6 +83,9 @@ const CodeEditor: React.FC<CodeEditorProps> = ({
}
const handleOnChangeFileContent = (code = '') => {
if (!files[onSelectedFileChange ? props.selectedFileName : selectedFileName]) {
return
}
const clone = _.cloneDeep(files)
clone[onSelectedFileChange ? props.selectedFileName : selectedFileName].value = code ?? ''
onChangeFileContent?.(
@@ -119,7 +122,8 @@ const CodeEditor: React.FC<CodeEditorProps> = ({
readonly ||
readonlyFiles?.includes(
onSelectedFileChange ? props.selectedFileName : selectedFileName
)
) ||
!files[onSelectedFileChange ? props.selectedFileName : selectedFileName]
}
onChange={handleOnChangeFileContent}
/>