@@ -12,129 +12,6 @@ export type DataNode = {
1212 children ?: DataNode [ ] ;
1313} ;
1414
15- const fileTreeNodes : DataNode [ ] = [
16- {
17- title : "index.jsx" ,
18- route : "/" ,
19- isLeaf : true ,
20- path : [ 0 ] ,
21- } ,
22- {
23- title : "test1.jsx" ,
24- route : "/test1" ,
25- isLeaf : true ,
26- path : [ 1 ] ,
27- } ,
28- {
29- title : "test2.jsx" ,
30- route : "/test2" ,
31- isLeaf : true ,
32- path : [ 2 ] ,
33- } ,
34- {
35- title : "countries" ,
36- route : "/countries" ,
37- isLeaf : false ,
38- path : [ 3 ] ,
39- isFolderOpen : false ,
40- children : [
41- {
42- title : "europe" ,
43- route : "/countries/europe" ,
44- isLeaf : false ,
45- path : [ 3 , 0 ] ,
46- isFolderOpen : false ,
47- children : [
48- {
49- title : "france.jsx" ,
50- route : "/countries/europe/france" ,
51- isLeaf : true ,
52- path : [ 3 , 0 , 0 ] ,
53- } ,
54- {
55- title : "switzerland.jsx" ,
56- route : "/countries/europe/switzerland" ,
57- isLeaf : true ,
58- path : [ 3 , 0 , 1 ] ,
59- } ,
60- ] ,
61- } ,
62- {
63- title : "asia" ,
64- route : "/countries/asia" ,
65- isLeaf : false ,
66- isFolderOpen : false ,
67- path : [ 3 , 1 ] ,
68- children : [
69- {
70- title : "india.jsx" ,
71- route : "/countries/asia/india" ,
72- isLeaf : true ,
73- path : [ 3 , 1 , 0 ] ,
74- } ,
75- {
76- title : "russia.jsx" ,
77- route : "/countries/asia/russia" ,
78- isLeaf : true ,
79- path : [ 3 , 1 , 1 ] ,
80- } ,
81- ] ,
82- } ,
83- ] ,
84- } ,
85- {
86- title : "countries" ,
87- route : "/countries" ,
88- isLeaf : false ,
89- path : [ 4 ] ,
90- isFolderOpen : false ,
91- children : [
92- {
93- title : "europe" ,
94- route : "/countries/europe" ,
95- isLeaf : false ,
96- path : [ 4 , 0 ] ,
97- isFolderOpen : false ,
98- children : [
99- {
100- title : "france.jsx" ,
101- route : "/countries/europe/france" ,
102- isLeaf : true ,
103- path : [ 4 , 0 , 0 ] ,
104- } ,
105- {
106- title : "switzerland.jsx" ,
107- route : "/countries/europe/switzerland" ,
108- isLeaf : true ,
109- path : [ 4 , 0 , 1 ] ,
110- } ,
111- ] ,
112- } ,
113- {
114- title : "asia" ,
115- route : "/countries/asia" ,
116- isLeaf : false ,
117- isFolderOpen : false ,
118- path : [ 4 , 1 ] ,
119- children : [
120- {
121- title : "india.jsx" ,
122- route : "/countries/asia/india" ,
123- isLeaf : true ,
124- path : [ 4 , 1 , 0 ] ,
125- } ,
126- {
127- title : "russia.jsx" ,
128- route : "/countries/asia/russia" ,
129- isLeaf : true ,
130- path : [ 4 , 1 , 1 ] ,
131- } ,
132- ] ,
133- } ,
134- ] ,
135- } ,
136- ] ;
137-
13815function toggleFile ( path : number [ ] , fileStructure : DataNode [ ] ) {
13916 let currentLevel = fileStructure ;
14017 for ( let i = 0 ; i < path . length ; i ++ ) {
@@ -199,17 +76,21 @@ export const PageTree: React.FC<{
19976 }
20077 }
20178
79+ // Get the location of the folder
80+ pathForTraversal = [ ...pathForTraversal , j ] ;
81+
20282 // Else create path
20383 if ( lenBeforeUpdate === j ) {
20484 tempTreeNode . push (
20585 createTreeNode ( path !== "" ? path : "index" , path , false )
20686 ) ;
87+ tempTreeNode [ tempTreeNode . length - 1 ] . path = pathForTraversal ;
20788 tempTreeNode = tempTreeNode [ tempTreeNode . length - 1 ] . children || [ ] ;
20889 }
209-
210- pathForTraversal = [ ...pathForTraversal , j ] ;
21190 }
21291
92+ // Get the location of the file
93+ pathForTraversal = [ ...pathForTraversal , tempTreeNode . length ] ;
21394 node . path = pathForTraversal ;
21495 tempTreeNode . push ( node ) ;
21596 } ,
0 commit comments