@@ -9,6 +9,7 @@ class MainContainer extends Component {
99 super ( ) ;
1010 this . state = {
1111 snapshots : [ ] ,
12+ snapshotsTree : null ,
1213 snapshotIndex : 0 ,
1314 currentIndex : null ,
1415 port : null ,
@@ -20,13 +21,12 @@ class MainContainer extends Component {
2021 }
2122
2223 componentDidMount ( ) {
24+ console . log ( 'componentDidMount' ) ;
2325 // open connection with background script
2426 const port = chrome . runtime . connect ( ) ;
2527
2628 // listen for a message containing snapshots from the background script
2729 port . onMessage . addListener ( ( snapshots ) => {
28- console . log ( 'message from background script' , snapshots ) ;
29- console . log ( 'snapshots' , this . state . snapshots ) ;
3030 const snapshotIndex = snapshots . length - 1 ;
3131
3232 // set state with the information received from the background script
@@ -49,9 +49,11 @@ class MainContainer extends Component {
4949 }
5050
5151 // change the snapshot index
52- // --> 1. affects the action that is highlighted
53- // --> 2. moves the slider
52+ // this will change the state shown in the state container but won't change the DOM
5453 handleChangeSnapshot ( snapshotIndex ) {
54+ // snapshotIndex
55+ // --> 1. affects the action that is highlighted
56+ // --> 2. moves the slider
5557 this . setState ( { snapshotIndex } ) ;
5658 }
5759
@@ -61,23 +63,27 @@ class MainContainer extends Component {
6163 let { currentIndex } = this . state ;
6264 const payload = [ ] ;
6365
66+ // currentIndex is initialized to null
67+ // currentIndex = null means that the user hasn't jumped yet
6468 currentIndex = currentIndex === null ? snapshots . length - 1 : currentIndex ;
6569
70+ // if the user wants to jump backward
6671 if ( currentIndex > snapshotIndex ) {
6772 for ( let i = currentIndex - 1 ; i >= snapshotIndex ; i -= 1 ) {
6873 payload . push ( snapshots [ i ] ) ;
6974 }
7075 } else {
76+ // if the user wants to jump forward
7177 for ( let i = currentIndex + 1 ; i <= snapshotIndex ; i += 1 ) {
7278 payload . push ( snapshots [ i ] ) ;
7379 }
7480 }
7581
82+ // currentIndex should be changed to index the user jumped to
7683 this . setState ( { currentIndex : snapshotIndex } ) ;
7784
78- console . log ( 'payload' , payload ) ;
85+ // send the arrays of snapshots to background script
7986 port . postMessage ( { action : 'stepToSnap' , payload } ) ;
80- // port.postMessage({ action: 'jumpToSnap', payload: snapshots[snapshotIndex] });
8187 }
8288
8389 render ( ) {
0 commit comments