@@ -4,7 +4,7 @@ import React from 'react';
4
4
import { diff } from 'jsondiffpatch' ;
5
5
import Action from '../components/Action' ;
6
6
7
- import { emptySnapshots } from '../actions/actions' ;
7
+ import { emptySnapshots , changeView , changeSlider } from '../actions/actions' ;
8
8
import { useStoreContext } from '../store' ;
9
9
10
10
const resetSlider = ( ) => {
@@ -20,39 +20,64 @@ function ActionContainer() {
20
20
let actionsArr = [ ] ;
21
21
let hierarchyArr = [ ] ;
22
22
23
- // gabi and nate :: delete function to traverse state from snapshots, now we are tranversing state from hiararchy and alsog getting infromation on display name and component name
24
- const displayArray = ( obj ) => {
25
- const newObj = {
26
- index : obj . index ,
27
- displayName : `${ obj . name } .${ obj . branch } ` ,
28
- state : obj . stateSnapshot . children [ 0 ] . state ,
29
- componentName : obj . stateSnapshot . children [ 0 ] . name ,
30
- }
31
- hierarchyArr . push ( newObj )
32
- if ( obj . children ) {
33
- obj . children . forEach ( ( element ) => {
34
- displayArray ( element )
35
- } )
36
- }
37
- }
38
- displayArray ( hierarchy )
39
- console . log ( 'this is hierarchyArr' , hierarchyArr )
40
-
41
- actionsArr = hierarchyArr . map ( ( snapshot , index ) => {
42
- const selected = index === viewIndex ;
43
- return (
44
- < Action
45
- key = { `action${ index } ` }
46
- index = { index }
47
- state = { snapshot . state }
48
- displayName = { snapshot . displayName }
49
- componentName = { snapshot . componentName }
50
- selected = { selected }
51
- dispatch = { dispatch }
52
- sliderIndex = { sliderIndex }
53
- />
54
- ) ;
55
- } ) ;
23
+ // gabi and nate :: delete function to traverse state from snapshots, now we are tranversing state from hiararchy and alsog getting infromation on display name and component name
24
+ const displayArray = ( obj ) => {
25
+ const newObj = {
26
+ index : obj . index ,
27
+ displayName : `${ obj . name } .${ obj . branch } ` ,
28
+ state : obj . stateSnapshot . children [ 0 ] . state ,
29
+ componentName : obj . stateSnapshot . children [ 0 ] . name ,
30
+ }
31
+ hierarchyArr . push ( newObj )
32
+ if ( obj . children ) {
33
+ obj . children . forEach ( ( element ) => {
34
+ displayArray ( element ) ;
35
+ } ) ;
36
+ }
37
+ }
38
+ displayArray ( hierarchy )
39
+ console . log ( 'this is hierarchyArr' , hierarchyArr )
40
+
41
+ // Edwin: handles keyboard presses, function passes an event and index of each action-component
42
+ function handleOnKeyDown ( e , i ) {
43
+ let currIndex = i ;
44
+ // up array key pressed
45
+ if ( e . keyCode === 38 ) {
46
+ currIndex -= 1 ;
47
+ if ( currIndex < 0 ) return ;
48
+ dispatch ( changeView ( currIndex ) ) ;
49
+ }
50
+ // down arrow key pressed
51
+ else if ( e . keyCode === 40 ) {
52
+ currIndex += 1 ;
53
+ if ( currIndex > hierarchyArr . length - 1 ) return ;
54
+ dispatch ( changeView ( currIndex ) ) ;
55
+ }
56
+ // enter key pressed
57
+ else if ( e . keyCode === 13 ) {
58
+ e . stopPropagation ( ) ;
59
+ dispatch ( changeSlider ( currIndex ) ) ;
60
+ }
61
+ }
62
+
63
+ actionsArr = hierarchyArr . map ( ( snapshot , index ) => {
64
+ const selected = index === viewIndex ;
65
+ return (
66
+ < Action
67
+ key = { `action${ index } ` }
68
+ index = { index }
69
+ state = { snapshot . state }
70
+ displayName = { snapshot . displayName }
71
+ componentName = { snapshot . componentName }
72
+ selected = { selected }
73
+ dispatch = { dispatch }
74
+ sliderIndex = { sliderIndex }
75
+ handleOnkeyDown = { handleOnKeyDown }
76
+ viewIndex = { viewIndex }
77
+ />
78
+ ) ;
79
+ } ) ;
80
+
56
81
57
82
return (
58
83
< div className = "action-container" >
0 commit comments