11import { useStore } from '@nanostores/react' ;
22import { TutorialStore } from '@tutorialkit/runtime' ;
33import type { I18n } from '@tutorialkit/types' ;
4- import { useCallback , useEffect , useRef , useState } from 'react' ;
4+ import { useCallback , useEffect , useRef , useState , type ComponentProps } from 'react' ;
55import { Panel , PanelGroup , PanelResizeHandle , type ImperativePanelHandle } from 'react-resizable-panels' ;
66import type { Theme } from '../core/types.js' ;
77import resizePanelStyles from '../styles/resize-panel.module.css' ;
@@ -12,6 +12,8 @@ import { TerminalPanel } from './TerminalPanel.js';
1212
1313const DEFAULT_TERMINAL_SIZE = 25 ;
1414
15+ type FileTreeChangeEvent = Parameters < NonNullable < ComponentProps < typeof EditorPanel > [ 'onFileTreeChange' ] > > [ 0 ] ;
16+
1517interface Props {
1618 tutorialStore : TutorialStore ;
1719 theme : Theme ;
@@ -119,6 +121,16 @@ function EditorSection({ theme, tutorialStore, hasEditor }: PanelProps) {
119121 }
120122 }
121123
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+
122134 useEffect ( ( ) => {
123135 if ( tutorialStore . hasSolution ( ) ) {
124136 setHelpAction ( 'solve' ) ;
@@ -147,6 +159,7 @@ function EditorSection({ theme, tutorialStore, hasEditor }: PanelProps) {
147159 helpAction = { helpAction }
148160 onHelpClick = { lessonFullyLoaded ? onHelpClick : undefined }
149161 onFileSelect = { ( filePath ) => tutorialStore . setSelectedFile ( filePath ) }
162+ onFileTreeChange = { onFileTreeChange }
150163 selectedFile = { selectedFile }
151164 onEditorScroll = { ( position ) => tutorialStore . setCurrentDocumentScrollPosition ( position ) }
152165 onEditorChange = { ( update ) => tutorialStore . setCurrentDocumentContent ( update . content ) }
0 commit comments