@@ -11,6 +11,7 @@ import {
1111 GripVertical ,
1212} from 'lucide-react' ;
1313import type { NotebookTreeNode } from '../../../preload/index' ;
14+ import { useNotebookExpandStore } from '../../stores/notebookExpandStore' ;
1415import { CommitHistory } from '../git/CommitHistory' ;
1516import { sc } from './sc' ;
1617
@@ -62,7 +63,9 @@ export const NotebookItem = memo(function NotebookItem({
6263 onReorder,
6364 siblingIds,
6465} : NotebookItemProps ) {
65- const [ isExpanded , setIsExpanded ] = useState ( true ) ;
66+ const isExpanded = useNotebookExpandStore ( s => ! s . collapsedIds . includes ( node . notebook . id ) ) ;
67+ const toggleExpanded = useNotebookExpandStore ( s => s . toggle ) ;
68+ const expandNotebook = useNotebookExpandStore ( s => s . expand ) ;
6669 const [ isEditing , setIsEditing ] = useState ( false ) ;
6770 const [ editName , setEditName ] = useState ( node . notebook . name ) ;
6871 const [ isGitEnabled , setIsGitEnabled ] = useState ( false ) ;
@@ -103,10 +106,13 @@ export const NotebookItem = memo(function NotebookItem({
103106 [ node . notebook . id , onSelect ]
104107 ) ;
105108
106- const handleToggle = useCallback ( ( e : React . MouseEvent ) => {
107- e . stopPropagation ( ) ;
108- setIsExpanded ( prev => ! prev ) ;
109- } , [ ] ) ;
109+ const handleToggle = useCallback (
110+ ( e : React . MouseEvent ) => {
111+ e . stopPropagation ( ) ;
112+ toggleExpanded ( node . notebook . id ) ;
113+ } ,
114+ [ node . notebook . id , toggleExpanded ]
115+ ) ;
110116
111117 const handleDoubleClick = useCallback (
112118 ( e : React . MouseEvent ) => {
@@ -287,7 +293,7 @@ export const NotebookItem = memo(function NotebookItem({
287293 if ( pos === 'inside' ) {
288294 // Move dragged notebook into this one as a child
289295 onMove ?.( draggedId , node . notebook . id ) ;
290- setIsExpanded ( true ) ;
296+ expandNotebook ( node . notebook . id ) ;
291297 } else if ( pos === 'above' || pos === 'below' ) {
292298 const fromSameParent =
293299 ( draggedParentId === 'root' ? null : draggedParentId ) === thisParentId ;
@@ -313,6 +319,7 @@ export const NotebookItem = memo(function NotebookItem({
313319 onMove ,
314320 onReorder ,
315321 siblingIds ,
322+ expandNotebook ,
316323 ]
317324 ) ;
318325
0 commit comments