1
- import { useList } from "million/react"
1
+ import { useList , useState } from "million/react"
2
2
3
3
const random = ( max ) => Math . round ( Math . random ( ) * 1000 ) % max ;
4
4
5
- const A = [ "pretty" , "large" , "big" , "small" , "tall" , "short" , "long" , "handsome" , "plain" , "quaint" , "clean" ,
6
- "elegant" , "easy" , "angry" , "crazy" , "helpful" , "mushy" , "odd" , "unsightly" , "adorable" , "important" , "inexpensive" ,
7
- "cheap" , "expensive" , "fancy" ] ;
5
+ const A = [ "pretty" , "large" , "big" , "small" , "tall" , "short" , "long" , "handsome" , "plain" , "quaint" , "clean" , "elegant" , "easy" , "angry" , "crazy" , "helpful" , "mushy" , "odd" , "unsightly" , "adorable" , "important" , "inexpensive" , "cheap" , "expensive" , "fancy" ] ;
8
6
const C = [ "red" , "yellow" , "blue" , "green" , "pink" , "brown" , "purple" , "brown" , "white" , "black" , "orange" ] ;
9
7
const N = [ "table" , "chair" , "house" , "bbq" , "desk" , "car" , "pony" , "cookie" , "sandwich" , "burger" , "pizza" , "mouse" ,
10
8
"keyboard" ] ;
@@ -20,7 +18,10 @@ const generate = () => {
20
18
21
19
export default function App ( ) {
22
20
const [ list , delta ] = useList ( [ ] )
21
+ const [ selected , setSelected ] = useState ( 0 )
22
+
23
23
const clear = ( ) => {
24
+ setSelected ( 0 )
24
25
list . splice ( 0 , list . length )
25
26
}
26
27
@@ -58,43 +59,43 @@ export default function App() {
58
59
return (
59
60
< div className = "container" >
60
61
< div className = "jumbotron" >
61
- < div class = "col-md-6" > < h1 > Million delta</ h1 > </ div >
62
- < div class = "col-md-6" >
63
- < div class = "row" >
64
- < div class = "col-sm-6 smallpad" >
65
- < button type = "button" class = "btn btn-primary btn-block" id = "run" onClick = { create1k } > Create 1,000 rows</ button >
66
- </ div >
67
- < div class = "col-sm-6 smallpad" >
68
- < button type = "button" class = "btn btn-primary btn-block" id = "runlots" onClick = { create10k } > Create 10,000 rows</ button >
69
- </ div >
70
- < div class = "col-sm-6 smallpad" >
71
- < button type = "button" class = "btn btn-primary btn-block" id = "add" onClick = { append1k } > Append 1,000 rows</ button > </ div >
72
- < div class = "col-sm-6 smallpad" >
73
- < button type = "button" class = "btn btn-primary btn-block" id = "update" onClick = { updateEvery10 } > Update every 10th row</ button >
74
- </ div >
75
- < div class = "col-sm-6 smallpad" >
76
- < button type = "button" class = "btn btn-primary btn-block" id = "clear" onClick = { clear } > Clear</ button >
77
- </ div >
78
- < div class = "col-sm-6 smallpad" >
79
- < button type = "button" class = "btn btn-primary btn-block" id = "swaprows" onClick = { swapRows } > Swap Rows</ button >
62
+ < div className = "row" >
63
+ < div class = "col-md-6" > < h1 > Million delta</ h1 > </ div >
64
+ < div class = "col-md-6" >
65
+ < div class = "row" >
66
+ < div class = "col-sm-6 smallpad" >
67
+ < button type = "button" class = "btn btn-primary btn-block" id = "run" onClick = { create1k } > Create 1,000 rows</ button >
68
+ </ div >
69
+ < div class = "col-sm-6 smallpad" >
70
+ < button type = "button" class = "btn btn-primary btn-block" id = "runlots" onClick = { create10k } > Create 10,000 rows</ button >
71
+ </ div >
72
+ < div class = "col-sm-6 smallpad" >
73
+ < button type = "button" class = "btn btn-primary btn-block" id = "add" onClick = { append1k } > Append 1,000 rows</ button > </ div >
74
+ < div class = "col-sm-6 smallpad" >
75
+ < button type = "button" class = "btn btn-primary btn-block" id = "update" onClick = { updateEvery10 } > Update every 10th row</ button >
76
+ </ div >
77
+ < div class = "col-sm-6 smallpad" >
78
+ < button type = "button" class = "btn btn-primary btn-block" id = "clear" onClick = { clear } > Clear</ button >
79
+ </ div >
80
+ < div class = "col-sm-6 smallpad" >
81
+ < button type = "button" class = "btn btn-primary btn-block" id = "swaprows" onClick = { swapRows } > Swap Rows</ button >
82
+ </ div >
80
83
</ div >
81
84
</ div >
82
85
</ div >
83
86
</ div >
84
87
< table className = "table table-hover table-striped test-data" >
85
88
< tbody delta = { delta } >
86
89
{ list . map ( ( item ) => (
87
- < tr class = "" >
90
+ < tr className = { selected === item . id ? "danger" : "" } >
88
91
< td class = "col-md-1" > { item . id } </ td >
89
92
< td class = "col-md-4" >
90
- < a > { item . label } </ a >
93
+ < a onClick = { ( ) => setSelected ( item . id ) } > { item . label } </ a >
91
94
</ td >
92
95
< td class = "col-md-1" >
93
- < a > < span class = "glyphicon glyphicon-remove" aria-hidden = "true" > </ span > </ a >
94
- </ td >
95
- < td class = "col-md-6" >
96
-
96
+ < a onClick = { ( ) => list . splice ( list . findIndex ( ( z ) => z . id === item . id ) , 1 ) } > < span class = "glyphicon glyphicon-remove" aria-hidden = "true" > </ span > </ a >
97
97
</ td >
98
+ < td class = "col-md-6" />
98
99
</ tr >
99
100
) ) }
100
101
</ tbody >
0 commit comments