Skip to content

Commit 88e4815

Browse files
committed
feat(runtime): store to support file creation
1 parent 81eac67 commit 88e4815

File tree

5 files changed

+19
-0
lines changed

5 files changed

+19
-0
lines changed

packages/react/src/Panels/EditorPanel.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ interface Props {
2929
onEditorScroll?: OnEditorScroll;
3030
onHelpClick?: () => void;
3131
onFileSelect?: (value?: string) => void;
32+
onFileCreate?: (value: string) => void;
3233
}
3334

3435
export function EditorPanel({
@@ -46,6 +47,7 @@ export function EditorPanel({
4647
onEditorScroll,
4748
onHelpClick,
4849
onFileSelect,
50+
onFileCreate,
4951
}: Props) {
5052
const fileTreePanelRef = useRef<ImperativePanelHandle>(null);
5153

@@ -81,6 +83,7 @@ export function EditorPanel({
8183
files={files}
8284
scope={fileTreeScope}
8385
onFileSelect={onFileSelect}
86+
onFileCreate={onFileCreate}
8487
/>
8588
</Panel>
8689
<PanelResizeHandle

packages/react/src/Panels/WorkspacePanel.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,7 @@ function EditorSection({ theme, tutorialStore, hasEditor }: PanelProps) {
139139
helpAction={helpAction}
140140
onHelpClick={lessonFullyLoaded ? onHelpClick : undefined}
141141
onFileSelect={(filePath) => tutorialStore.setSelectedFile(filePath)}
142+
onFileCreate={(filePath) => tutorialStore.addFile(filePath)}
142143
selectedFile={selectedFile}
143144
onEditorScroll={(position) => tutorialStore.setCurrentDocumentScrollPosition(position)}
144145
onEditorChange={(update) => tutorialStore.setCurrentDocumentContent(update.content)}

packages/react/src/core/FileTree.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ interface Props {
88
files: string[];
99
selectedFile?: string;
1010
onFileSelect?: (filePath: string) => void;
11+
onFileCreate?: (filePath: string) => void;
1112
hideRoot: boolean;
1213
scope?: string;
1314
hiddenFiles?: Array<string | RegExp>;

packages/runtime/src/store/editor.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,15 @@ export class EditorStore {
8383
});
8484
}
8585

86+
addFile(filePath: string) {
87+
this.documents.setKey(filePath, {
88+
filePath,
89+
value: '',
90+
loading: false,
91+
});
92+
this.setSelectedFile(filePath);
93+
}
94+
8695
updateFile(filePath: string, content: string): boolean {
8796
const documentState = this.documents.get()[filePath];
8897

packages/runtime/src/store/index.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -308,6 +308,11 @@ export class TutorialStore {
308308
this._editorStore.setSelectedFile(filePath);
309309
}
310310

311+
addFile(filePath: string) {
312+
this._editorStore.addFile(filePath);
313+
this._runner.updateFile(filePath, '');
314+
}
315+
311316
updateFile(filePath: string, content: string) {
312317
const hasChanged = this._editorStore.updateFile(filePath, content);
313318

0 commit comments

Comments
 (0)