1
1
import { useStore } from '@nanostores/react' ;
2
2
import { TutorialStore } from '@tutorialkit/runtime' ;
3
3
import type { I18n } from '@tutorialkit/types' ;
4
- import { useCallback , useEffect , useRef , useState } from 'react' ;
4
+ import { useCallback , useEffect , useRef , useState , type ComponentProps } from 'react' ;
5
5
import { Panel , PanelGroup , PanelResizeHandle , type ImperativePanelHandle } from 'react-resizable-panels' ;
6
6
import type { Theme } from '../core/types.js' ;
7
7
import resizePanelStyles from '../styles/resize-panel.module.css' ;
@@ -12,6 +12,8 @@ import { TerminalPanel } from './TerminalPanel.js';
12
12
13
13
const DEFAULT_TERMINAL_SIZE = 25 ;
14
14
15
+ type FileTreeChangeEvent = Parameters < NonNullable < ComponentProps < typeof EditorPanel > [ 'onFileTreeChange' ] > > [ 0 ] ;
16
+
15
17
interface Props {
16
18
tutorialStore : TutorialStore ;
17
19
theme : Theme ;
@@ -119,6 +121,16 @@ function EditorSection({ theme, tutorialStore, hasEditor }: PanelProps) {
119
121
}
120
122
}
121
123
124
+ function onFileTreeChange ( { method, type, value } : FileTreeChangeEvent ) {
125
+ if ( method == 'ADD' && type === 'FILE' ) {
126
+ return tutorialStore . addFile ( value ) ;
127
+ }
128
+
129
+ if ( method == 'ADD' && type === 'FOLDER' ) {
130
+ return tutorialStore . addFolder ( value ) ;
131
+ }
132
+ }
133
+
122
134
useEffect ( ( ) => {
123
135
if ( tutorialStore . hasSolution ( ) ) {
124
136
setHelpAction ( 'solve' ) ;
@@ -147,6 +159,7 @@ function EditorSection({ theme, tutorialStore, hasEditor }: PanelProps) {
147
159
helpAction = { helpAction }
148
160
onHelpClick = { lessonFullyLoaded ? onHelpClick : undefined }
149
161
onFileSelect = { ( filePath ) => tutorialStore . setSelectedFile ( filePath ) }
162
+ onFileTreeChange = { onFileTreeChange }
150
163
selectedFile = { selectedFile }
151
164
onEditorScroll = { ( position ) => tutorialStore . setCurrentDocumentScrollPosition ( position ) }
152
165
onEditorChange = { ( update ) => tutorialStore . setCurrentDocumentContent ( update . content ) }
0 commit comments