1
- import React , { lazy , Suspense } from 'react' ;
2
- import { BrowserRouter as Router , Route , Switch } from 'react-router-dom' ;
3
-
4
-
5
- function App ( ) {
6
- // const [flatData, setflatData] = useState(() => {
7
- // const list: (typeof example_data)[] = [];
8
- // for (const { node, skip, } of traverseTreeData(example_data, 'children')) {
9
- // node.id = Math.random()
10
- // // @ts -ignore
11
- // list.push(node);
12
- // }
13
- // return list
14
- // });
15
- const [ flatData , setflatData ] = useImmer ( ( ) => sortFlatData ( [
16
- { "id" : 1 , "pid" : null , "name" : "Root Category" } ,
17
- { "id" : 2 , "pid" : 1 , "name" : "Technology" } ,
18
- { "id" : 5 , "pid" : 2 , "name" : "Hardware" } ,
19
- { "id" : 10 , "pid" : 5 , "name" : "Computer Components" } ,
20
- { "id" : 3 , "pid" : 1 , "name" : "Science" } ,
21
- { "id" : 7 , "pid" : 3 , "name" : "Biology" } ,
22
- { "id" : 4 , "pid" : 2 , "name" : "Programming" } ,
23
- { "id" : 6 , "pid" : 3 , "name" : "Physics" } ,
24
- { "id" : 8 , "pid" : 4 , "name" : "Python" } ,
25
- { "id" : 9 , "pid" : 4 , "name" : "Java" } ,
26
- { "id" : 11 , "pid" : 5 , "name" : "Networking" } ,
27
- { "id" : 12 , "pid" : 6 , "name" : "Classical Mechanics" } ,
28
- { "id" : 13 , "pid" : 6 , "name" : "Quantum Mechanics" } ,
29
- { "id" : 14 , "pid" : 7 , "name" : "Genetics" } ,
30
- { "id" : 15 , "pid" : 7 , "name" : "Ecology" } ,
31
- { "id" : 16 , "pid" : 8 , "name" : "Django" } ,
32
- { "id" : 17 , "pid" : 8 , "name" : "JavaScript" } ,
33
- { "id" : 18 , "pid" : 9 , "name" : "Spring" } ,
34
- { "id" : 19 , "pid" : 9 , "name" : "C++" } ,
35
- { "id" : 20 , "pid" : 10 , "name" : "CPU" } ,
36
- { "id" : 21 , "pid" : 10 , "name" : "RAM" } ,
37
- { "id" : 22 , "pid" : 11 , "name" : "Wireless Networking" } ,
38
- { "id" : 23 , "pid" : 11 , "name" : "Routing" } ,
39
- { "id" : 24 , "pid" : 12 , "name" : "Newtonian Mechanics" } ,
40
- { "id" : 25 , "pid" : 12 , "name" : "Relativity" } ,
41
- { "id" : 26 , "pid" : 13 , "name" : "Quantum Field Theory" } ,
42
- { "id" : 27 , "pid" : 13 , "name" : "String Theory" } ,
43
- { "id" : 28 , "pid" : 14 , "name" : "DNA Structure" } ,
44
- { "id" : 29 , "pid" : 14 , "name" : "Gene Expression" } ,
45
- { "id" : 30 , "pid" : 15 , "name" : "Ecosystems" } ,
46
- { "id" : 31 , "pid" : 15 , "name" : "Biodiversity" } ,
47
- { "id" : 32 , "pid" : 16 , "name" : "Flask" } ,
48
- { "id" : 33 , "pid" : 16 , "name" : "React" } ,
49
- { "id" : 34 , "pid" : 17 , "name" : "Node.js" } ,
50
- { "id" : 35 , "pid" : 17 , "name" : "Angular" } ,
51
- { "id" : 36 , "pid" : 18 , "name" : "Maven" } ,
52
- { "id" : 37 , "pid" : 18 , "name" : "Hibernate" } ,
53
- { "id" : 38 , "pid" : 19 , "name" : "Object-Oriented Programming" } ,
54
- { "id" : 39 , "pid" : 19 , "name" : "Data Structures" } ,
55
- { "id" : 40 , "pid" : 20 , "name" : "GPU" } ,
56
- { "id" : 41 , "pid" : 20 , "name" : "Motherboard" } ,
57
- { "id" : 42 , "pid" : 21 , "name" : "DDR4" } ,
58
- { "id" : 43 , "pid" : 21 , "name" : "DDR5" } ,
59
- { "id" : 44 , "pid" : 22 , "name" : "Wi-Fi" } ,
60
- { "id" : 45 , "pid" : 22 , "name" : "Bluetooth" } ,
61
- { "id" : 46 , "pid" : 23 , "name" : "IP Addressing" } ,
62
- { "id" : 47 , "pid" : 23 , "name" : "Firewall" } ,
63
- { "id" : 48 , "pid" : 24 , "name" : "Gravitation" } ,
64
- { "id" : 49 , "pid" : 24 , "name" : "Orbital Mechanics" } ,
65
- { "id" : 50 , "pid" : 25 , "name" : "General Relativity" } ,
66
- { "id" : 51 , "pid" : 25 , "name" : "Special Relativity" } ,
67
- { "id" : 52 , "pid" : 26 , "name" : "Quantum Entanglement" } ,
68
- { "id" : 53 , "pid" : 26 , "name" : "Quantum Superposition" } ,
69
- { "id" : 54 , "pid" : 27 , "name" : "Quantum Strings" } ,
70
- { "id" : 55 , "pid" : 27 , "name" : "Superstring Theory" } ,
71
- { "id" : 56 , "pid" : 28 , "name" : "RNA Structure" } ,
72
- { "id" : 57 , "pid" : 28 , "name" : "Mutation" } ,
73
- { "id" : 58 , "pid" : 29 , "name" : "Genome Mapping" } ,
74
- { "id" : 59 , "pid" : 29 , "name" : "Genetic Engineering" } ,
75
- { "id" : 60 , "pid" : 30 , "name" : "Forest Ecosystems" } ,
76
- { "id" : 61 , "pid" : 30 , "name" : "Desert Ecosystems" } ,
77
- { "id" : 62 , "pid" : 31 , "name" : "Species Richness" } ,
78
- { "id" : 63 , "pid" : 31 , "name" : "Ecological Succession" } ,
79
- { "id" : 64 , "pid" : 32 , "name" : "API Development" } ,
80
- { "id" : 65 , "pid" : 32 , "name" : "Web Development" } ,
81
- { "id" : 66 , "pid" : 33 , "name" : "React Native" } ,
82
- { "id" : 67 , "pid" : 33 , "name" : "Vue.js" } ,
83
- { "id" : 68 , "pid" : 34 , "name" : "Express.js" } ,
84
- { "id" : 69 , "pid" : 34 , "name" : "Sails.js" } ,
85
- { "id" : 70 , "pid" : 35 , "name" : "RxJS" } ,
86
- { "id" : 71 , "pid" : 35 , "name" : "Dart" } ,
87
- { "id" : 72 , "pid" : 36 , "name" : "Ant" } ,
88
- { "id" : 73 , "pid" : 36 , "name" : "Gradle" } ,
89
- { "id" : 74 , "pid" : 37 , "name" : "JPA" } ,
90
- { "id" : 75 , "pid" : 37 , "name" : "MyBatis" } ,
91
- { "id" : 76 , "pid" : 38 , "name" : "Inheritance" } ,
92
- { "id" : 77 , "pid" : 38 , "name" : "Polymorphism" } ,
93
- { "id" : 78 , "pid" : 39 , "name" : "Arrays" } ,
94
- { "id" : 79 , "pid" : 39 , "name" : "Linked Lists" } ,
95
- { "id" : 80 , "pid" : 40 , "name" : "Graphics Card" } ,
96
- { "id" : 81 , "pid" : 40 , "name" : "CUDA" } ,
97
- { "id" : 82 , "pid" : 41 , "name" : "ATX" } ,
98
- { "id" : 83 , "pid" : 41 , "name" : "ITX" } ,
99
- { "id" : 84 , "pid" : 42 , "name" : "Latency" } ,
100
- { "id" : 85 , "pid" : 42 , "name" : "Bandwidth" } ,
101
- { "id" : 86 , "pid" : 43 , "name" : "DDR5X" } ,
102
- { "id" : 87 , "pid" : 43 , "name" : "GDDR6" } ,
103
- { "id" : 88 , "pid" : 44 , "name" : "5G" } ,
104
- { "id" : 89 , "pid" : 44 , "name" : "Mesh Networking" } ,
105
- { "id" : 90 , "pid" : 45 , "name" : "Wireless Mouse" } ,
106
- { "id" : 91 , "pid" : 45 , "name" : "Wireless Keyboard" } ,
107
- { "id" : 92 , "pid" : 46 , "name" : "IPv4" } ,
108
- { "id" : 93 , "pid" : 46 , "name" : "IPv6" } ,
109
- { "id" : 94 , "pid" : 47 , "name" : "Network Firewall" } ,
110
- { "id" : 95 , "pid" : 47 , "name" : "Application Firewall" } ,
111
- { "id" : 96 , "pid" : 48 , "name" : "Kepler's Laws" } ,
112
- { "id" : 97 , "pid" : 48 , "name" : "Newton's Law of Universal Gravitation" } ,
113
- { "id" : 98 , "pid" : 49 , "name" : "Hohmann Transfer Orbit" } ,
114
- { "id" : 99 , "pid" : 49 , "name" : "Geostationary Orbit" } ,
115
- { "id" : 100 , "pid" : 50 , "name" : "Black Holes" } ,
116
- { "id" : 101 , "pid" : 50 , "name" : "Wormholes" }
117
- ] , 'id' , 'pid' ) ) ;
118
- const updateOpen = ( id , open ) => {
119
- let ids = [ ...openIds ] ;
120
- if ( open ) {
121
- ids . push ( id )
122
- } else {
123
- ids . splice ( ids . indexOf ( id ) , 1 )
124
- }
125
- setopenIds ( ids )
126
- }
127
- const toggleCheck = ( id , checked ) => {
128
- let newIds = updateCheckedInFlatData ( flatData , checkedIds , id , checked , { parentIdKey : 'pid' } ) [ 0 ] ;
129
- setcheckedIds ( newIds )
130
- }
131
- const [ openIds , setopenIds ] = useState ( [ 1 , 2 , 4 ] ) ;
132
- const [ checkedIds , setcheckedIds ] = useState ( [ 4 ] ) ;
133
- const t = useHeTree ( {
134
- data : flatData ,
135
- dataType : 'flat' ,
136
- renderNode : ( { id, node, open, checked } ) => < div >
137
- < button onClick = { ( ) => { updateOpen ( id , ! open ) } } > { open ? '-' : '+' } </ button >
138
- < input type = "checkbox" checked = { Boolean ( checked ) } onChange = { ( ) => { toggleCheck ( id , ! checked ) } } />
139
- { node ?. name }
140
- </ div > ,
141
- onChange : setflatData ,
142
- parentIdKey : 'pid' ,
143
- openIds,
144
- checkedIds,
145
- } )
146
-
147
- // const renderNode = ({ node, dragOvering, setOpen, setChecked, draggable, onDragStart }) => <div>
148
- // <div>
149
- // <button draggable={draggable} onDragStart={onDragStart}>x</button>
150
- // <button onClick={() => setOpen(!node.open)}>{node.open ? '-' : '+'}</button>
151
- // <input type="checkbox" checked={node.checked || false} onChange={(e) => setChecked(e.target.checked)} />
152
- // {node.text}
153
- // </div>
154
- // </div>
155
- return (
156
- < >
157
- < div className = 'text-center' >
158
- < b > @he-tree/react</ b >
159
- < a className = 'ml-10' href = "https://github.com/phphe/he-tree-react" > Github</ a >
160
- </ div >
161
- < div className = 'grid grid-cols-3 gap-4' >
162
- < div >
163
- { t . renderHeTree ( ) }
164
- </ div >
165
- < div >
166
- </ div >
167
- < div >
168
- </ div >
169
- </ div >
170
- </ >
171
- )
172
- }
173
-
174
- export default App
1
+ // this file is not used
0 commit comments