Skip to content

Commit 30fb240

Browse files
committed
connected backend with frontend using linkFiber
1 parent b941750 commit 30fb240

File tree

8 files changed

+93
-74
lines changed

8 files changed

+93
-74
lines changed

src/app/components/Action.jsx

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,33 @@
1-
import React, { Component } from 'react';
1+
import React from 'react';
22
import PropTypes from 'prop-types';
33

44
const Action = (props) => {
55
const {
6-
selected, handleChangeSnapshot, handleSendSnapshot, index,
6+
selected, handleChangeSnapshot, handleJumpSnapshot, index,
77
} = props;
88
return (
99
<div
1010
className={selected ? 'action-component selected' : 'action-component'}
11-
onClick={() => {
12-
handleChangeSnapshot(index);
13-
}}
11+
onClick={() => handleChangeSnapshot(index)}
12+
role="presentation"
1413
>
1514
<div className="action-component-text">{index}</div>
16-
<div className="jump-button" onClick={() => handleSendSnapshot(index)}>
15+
<div
16+
className="jump-button"
17+
onClick={() => handleJumpSnapshot(index)}
18+
onKeyPress={() => console.log('key pressed')}
19+
tabIndex={index}
20+
role="button"
21+
>
1722
Jump
1823
</div>
1924
</div>
2025
);
2126
};
2227

23-
Action.propTypes = {
24-
selected: PropTypes.bool,
25-
index: PropTypes.number,
26-
};
28+
// Action.propTypes = {
29+
// selected: PropTypes.bool,
30+
// index: PropTypes.number,
31+
// };
2732

2833
export default Action;

src/app/components/Slider.jsx

Lines changed: 36 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -5,49 +5,48 @@ import Tooltip from 'rc-tooltip';
55
import 'rc-slider/assets/index.css';
66
import 'rc-tooltip/assets/bootstrap.css';
77

8-
const Handle = Slider.Handle;
9-
8+
const { Handle } = Slider;
109

1110
const handle = (props) => {
12-
const { value, dragging, index, ...restProps } = props;
13-
14-
return (
15-
<Tooltip
16-
prefixCls="rc-slider-tooltip"
17-
overlay={value}
18-
visible={dragging}
19-
placement="top"
20-
key={index}
21-
>
22-
<Handle value={value} {...restProps} />
23-
</Tooltip>
24-
);
11+
const {
12+
value, dragging, index, ...restProps
13+
} = props;
14+
15+
return (
16+
<Tooltip
17+
prefixCls="rc-slider-tooltip"
18+
overlay={value}
19+
visible={dragging}
20+
placement="top"
21+
key={index}
22+
>
23+
<Handle value={value} {...restProps} />
24+
</Tooltip>
25+
);
2526
};
2627

2728
class mainSlider extends Component {
28-
constructor(props){
29-
super(props)
30-
}
29+
constructor(props) {
30+
super(props);
31+
}
3132

32-
33-
render(){
34-
return(
35-
<div>
36-
<Slider
37-
min={0}
38-
max={this.props.snapshotLength-1}
39-
value = {this.props.snapshotIndex}
40-
onChange={(index) => {
41-
index = index === -1 ? 0 : index;
42-
this.props.handleChangeSnapshot(index)
43-
}}
44-
handle={handle}
45-
>
46-
</Slider>
47-
</div>
48-
)
49-
}
33+
render() {
34+
return (
35+
<div>
36+
<Slider
37+
min={0}
38+
max={this.props.snapshotLength - 1}
39+
value={this.props.snapshotIndex}
40+
onChange={(index) => {
41+
index = index === -1 ? 0 : index;
42+
this.props.handleChangeSnapshot(index);
43+
this.props.handleJumpSnapshot(index);
44+
}}
45+
handle={handle}
46+
/>
47+
</div>
48+
);
49+
}
5050
}
5151

5252
export default mainSlider;
53-

src/app/containers/ActionContainer.jsx

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,11 @@ class ActionContainer extends Component {
88

99
render() {
1010
const {
11-
snapshots, snapshotIndex, handleChangeSnapshot, handleSendSnapshot,
11+
snapshots,
12+
snapshotIndex,
13+
handleChangeSnapshot,
14+
handleJumpSnapshot,
15+
emptySnapshot,
1216
} = this.props;
1317
let actionsArr = [];
1418
if (snapshots.length > 0) {
@@ -21,15 +25,15 @@ class ActionContainer extends Component {
2125
snapshot={snapshot}
2226
selected={selected}
2327
handleChangeSnapshot={handleChangeSnapshot}
24-
handleSendSnapshot={handleSendSnapshot}
28+
handleJumpSnapshot={handleJumpSnapshot}
2529
/>
2630
);
2731
});
2832
}
2933
return (
3034
<div className="action-container">
3135
<div className="action-component">
32-
<div className="empty-button" onClick={this.props.emptySnapshot}>
36+
<div className="empty-button" onClick={emptySnapshot}>
3337
emptySnapshot
3438
</div>
3539
</div>

src/app/containers/MainContainer.jsx

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,17 @@ import StateContainer from './StateContainer';
55
import TravelContainer from './TravelContainer';
66

77
class MainContainer extends Component {
8-
constructor() {
9-
super();
8+
constructor(props) {
9+
super(props);
1010
this.state = {
1111
snapshots: [],
12-
snapshotsTree: null,
1312
snapshotIndex: 0,
1413
currentIndex: null,
1514
port: null,
1615
};
17-
1816
this.handleChangeSnapshot = this.handleChangeSnapshot.bind(this);
1917
this.handleSendSnapshot = this.handleSendSnapshot.bind(this);
18+
this.handleJumpSnapshot = this.handleJumpSnapshot.bind(this);
2019
this.emptySnapshot = this.emptySnapshot.bind(this);
2120
}
2221

@@ -57,6 +56,12 @@ class MainContainer extends Component {
5756
this.setState({ snapshotIndex });
5857
}
5958

59+
handleJumpSnapshot(snapshotIndex) {
60+
const { snapshots, port } = this.state;
61+
this.setState({ currentIndex: snapshotIndex });
62+
port.postMessage({ action: 'jumpToSnap', payload: snapshots[snapshotIndex] });
63+
}
64+
6065
// when the jump button is clicked, send a message to npm package with the selected snapshot
6166
handleSendSnapshot(snapshotIndex) {
6267
const { snapshots, port } = this.state;
@@ -88,7 +93,6 @@ class MainContainer extends Component {
8893

8994
render() {
9095
const { snapshots, snapshotIndex } = this.state;
91-
9296
return (
9397
<div className="main-container">
9498
<HeadContainer />
@@ -97,14 +101,15 @@ class MainContainer extends Component {
97101
snapshots={snapshots}
98102
snapshotIndex={snapshotIndex}
99103
handleChangeSnapshot={this.handleChangeSnapshot}
100-
handleSendSnapshot={this.handleSendSnapshot}
104+
handleJumpSnapshot={this.handleJumpSnapshot}
101105
emptySnapshot={this.emptySnapshot}
102106
/>
103107
<StateContainer snapshot={snapshots[snapshotIndex]} />
104108
</div>
105109
<TravelContainer
106110
snapshotsLength={snapshots.length}
107111
handleChangeSnapshot={this.handleChangeSnapshot}
112+
handleJumpSnapshot={this.handleJumpSnapshot}
108113
snapshotIndex={snapshotIndex}
109114
/>
110115
</div>
Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
import React, { Component } from 'react';
2-
import Slider from '../components/Slider'
3-
4-
5-
2+
import Slider from '../components/Slider';
63

74
class TravelContainer extends Component {
85
constructor(props) {
@@ -12,17 +9,17 @@ class TravelContainer extends Component {
129
render() {
1310
return (
1411
<div>
15-
<div className="travel-container">TravelContainer</div>
16-
<Slider
17-
className="travel-slider"
18-
snapshotLength = {this.props.snapshotsLength}
19-
handleChangeSnapshot = {this.props.handleChangeSnapshot}
20-
snapshotIndex = {this.props.snapshotIndex}
21-
/>
22-
{`travelContainer snapshotIndex ${this.props.snapshotIndex}`}
12+
<div className="travel-container">TravelContainer</div>
13+
<Slider
14+
className="travel-slider"
15+
snapshotLength={this.props.snapshotsLength}
16+
handleChangeSnapshot={this.props.handleChangeSnapshot}
17+
handleJumpSnapshot={this.props.handleJumpSnapshot}
18+
snapshotIndex={this.props.snapshotIndex}
19+
/>
20+
{`travelContainer snapshotIndex ${this.props.snapshotIndex}`}
2321
</div>
24-
)
25-
22+
);
2623
}
2724
}
2825
export default TravelContainer;

src/app/styles/components/_jsonTree.scss

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,5 @@
33
padding: 10px;
44
background-color: $brand-color;
55
list-style: none;
6+
min-width: 300px;
67
}

src/extension/background.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ chrome.runtime.onConnect.addListener((port) => {
3232

3333
// background.js recieves message from contentScript.js
3434
chrome.runtime.onMessage.addListener((request, sender, sendResponse) => {
35-
console.log(request);
35+
console.log('npm -> background', request);
3636
// if port is not null, send a message to devtools
3737
if (bg) {
3838
// get active tab id

src/extension/contentScript.js

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ console.log('contentScript running');
33
// listening for messages from npm package
44
window.addEventListener('message', (msg) => {
55
const { action, payload } = msg.data;
6-
console.log(msg.data);
6+
console.log('npm -> contentScript', msg.data);
77
if (action === 'recordSnap') chrome.runtime.sendMessage(payload);
88
});
99

@@ -12,6 +12,14 @@ chrome.runtime.onMessage.addListener((request, sender, sendResponse) => {
1212
// send the message to npm package
1313
console.log('devtools -> contentScript', request);
1414
const { action } = request;
15-
if (action === 'jumpToSnap') window.postMessage(request);
16-
if (action === 'stepToSnap') window.postMessage(request);
15+
switch (action) {
16+
case 'jumpToSnap':
17+
window.postMessage(request);
18+
break;
19+
case 'stepToSnap':
20+
window.postMessage(request);
21+
break;
22+
default:
23+
break;
24+
}
1725
});

0 commit comments

Comments
 (0)