Skip to content

Commit 5a0adbc

Browse files
committed
feat: project view - fix files delete
1 parent 051d30e commit 5a0adbc

File tree

2 files changed

+41
-32
lines changed

2 files changed

+41
-32
lines changed

src/components/organisms/editorTabs.tsx

Lines changed: 40 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -88,36 +88,37 @@ export const EditorTabs = () => {
8888
const [isFirstContentLoad, setIsFirstContentLoad] = useState(true);
8989
const [editorMounted, setEditorMounted] = useState(false);
9090
const [grammarLoaded, setGrammarLoaded] = useState(false);
91+
const isInitialLoadRef = useRef(true);
92+
useEffect(() => {
93+
isInitialLoadRef.current = false;
94+
}, []);
9195
const [codeFixData, setCodeFixData] = useState<{
9296
changeType: OperationType;
9397
fileName: string;
9498
modifiedCode: string;
9599
originalCode: string;
96100
} | null>(null);
97-
const [contentLoaded, setContentLoaded] = useState(false);
98101

99102
useEffect(() => {
100103
if (content && isFirstContentLoad) {
101104
initialContentRef.current = content;
102105
setIsFirstContentLoad(false);
103106
}
104107

105-
if (currentProject && contentLoaded && editorRef.current && content && content.trim() !== "") {
108+
if (currentProject && editorRef.current && content && content.trim() !== "") {
106109
restoreCursorPosition(editorRef.current);
107110
}
108111
// eslint-disable-next-line react-hooks/exhaustive-deps
109-
}, [content, currentProject, contentLoaded]);
112+
}, [content, currentProject]);
110113

111114
const updateContentFromResource = (resource?: Uint8Array) => {
112115
if (!resource) {
113116
setContent("");
114-
setContentLoaded(false);
115117
return;
116118
}
117119
const decodedContent = new TextDecoder().decode(resource);
118120
setContent(decodedContent);
119121
initialContentRef.current = decodedContent;
120-
setContentLoaded(true);
121122
};
122123

123124
const location = useLocation();
@@ -443,7 +444,7 @@ export const EditorTabs = () => {
443444
const handleEditorFocus = (event: monaco.editor.ICursorPositionChangedEvent) => {
444445
if (!projectId || !activeEditorFileName) return;
445446

446-
if (!currentProject || !contentLoaded || !content || content.trim() === "") {
447+
if (!currentProject || !content || content.trim() === "") {
447448
return;
448449
}
449450

@@ -470,7 +471,7 @@ export const EditorTabs = () => {
470471
const codeEditor = editorRef.current;
471472
if (!codeEditor) return;
472473

473-
if (!currentProject || !contentLoaded || !content || content.trim() === "") {
474+
if (!currentProject || !content || content.trim() === "") {
474475
return;
475476
}
476477

@@ -480,7 +481,7 @@ export const EditorTabs = () => {
480481
cursorPositionChangeListener.dispose();
481482
};
482483
// eslint-disable-next-line react-hooks/exhaustive-deps
483-
}, [editorMounted, projectId, activeEditorFileName, currentProject, contentLoaded, content]);
484+
}, [editorMounted, projectId, activeEditorFileName, currentProject, content]);
484485

485486
const updateContent = async (newContent?: string) => {
486487
if (!activeEditorFileName) {
@@ -631,6 +632,10 @@ export const EditorTabs = () => {
631632
const handleEditorChange = (newContent?: string) => {
632633
if (!newContent) return;
633634
setContent(newContent);
635+
if (isInitialLoadRef.current) {
636+
isInitialLoadRef.current = false;
637+
return;
638+
}
634639
if (autoSaveMode && activeEditorFileName) {
635640
debouncedAutosave(newContent);
636641
}
@@ -863,29 +868,33 @@ export const EditorTabs = () => {
863868
</div>
864869
</div>
865870
) : null}
866-
<Editor
867-
aria-label={activeEditorFileName}
868-
beforeMount={handleEditorWillMount}
869-
className="absolute -ml-6 mt-2 h-full pb-5"
870-
key={projectId}
871-
language={languageEditor}
872-
loading={<Loader data-testid="monaco-loader" size="lg" />}
873-
onChange={handleEditorChange}
874-
onMount={handleEditorDidMount}
875-
options={{
876-
fontFamily: "monospace, sans-serif",
877-
fontSize: 14,
878-
minimap: {
879-
enabled: false,
880-
},
881-
renderLineHighlight: "none",
882-
scrollBeyondLastLine: false,
883-
wordWrap: "on",
884-
readOnly: !grammarLoaded,
885-
}}
886-
theme="transparent-dark"
887-
value={content}
888-
/>
871+
{isInitialLoadRef.current ? (
872+
<Loader className="absolute left-auto right-[70%]" isCenter size="lg" />
873+
) : (
874+
<Editor
875+
aria-label={activeEditorFileName}
876+
beforeMount={handleEditorWillMount}
877+
className="absolute -ml-6 mt-2 h-full pb-5"
878+
key={projectId}
879+
language={languageEditor}
880+
loading={<Loader data-testid="monaco-loader" size="lg" />}
881+
onChange={handleEditorChange}
882+
onMount={handleEditorDidMount}
883+
options={{
884+
fontFamily: "monospace, sans-serif",
885+
fontSize: 14,
886+
minimap: {
887+
enabled: false,
888+
},
889+
renderLineHighlight: "none",
890+
scrollBeyondLastLine: false,
891+
wordWrap: "on",
892+
readOnly: !grammarLoaded,
893+
}}
894+
theme="transparent-dark"
895+
value={content}
896+
/>
897+
)}
889898
</>
890899
)
891900
) : (

src/factories/fileOperations.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,8 @@ export const fileOperations = (projectId: string) => {
5353
const { setFileList, closeOpenedFile } = useFileStore.getState();
5454
const { checkState } = useCacheStore.getState();
5555
setFileList({ isLoading: true });
56-
await dbService.delete(projectId, name);
5756
closeOpenedFile(name);
57+
await dbService.delete(projectId, name);
5858
const resources = await dbService.getAll(projectId);
5959
if (!resources) return;
6060
const { error } = await ProjectsService.setResources(projectId, resources);

0 commit comments

Comments
 (0)