Skip to content

Commit fec95d1

Browse files
authored
Merge pull request #40 from oslabs-beta/rydang/persist
persist button implemented
2 parents b5ea775 + 417a775 commit fec95d1

File tree

6 files changed

+40
-23
lines changed

6 files changed

+40
-23
lines changed

package/index.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
const snapShot = { tree: null };
22

3-
const mode = { jumping: false, paused: false, locked: false };
3+
const mode = {
4+
jumping: false, paused: false, locked: false,
5+
};
46

57
const linkFiber = require('./linkFiber')(snapShot, mode);
68
const timeJump = require('./timeJump')(snapShot, mode);

src/app/containers/ButtonsContainer.jsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
import React from 'react';
22
import PropTypes from 'prop-types';
33

4-
const ButtonsContainer = ({ mode: { paused, locked }, toggleMode }) => (
4+
const ButtonsContainer = ({ mode: { paused, locked, persist }, toggleMode }) => (
55
<div className="buttons-container">
66
<div className="pause-button" onClick={() => toggleMode('paused')}>{(paused) ? 'Resume' : 'Pause'}</div>
77
<div className="lock-button" onClick={() => toggleMode('locked')}>{(locked) ? 'Unlock' : 'Lock'}</div>
8+
<div className="persist-button" onClick={() => toggleMode('persist')}>{(persist) ? 'Unpersist' : 'Persist'}</div>
89
</div>
910
);
1011

@@ -13,6 +14,7 @@ ButtonsContainer.propTypes = {
1314
mode: PropTypes.shape({
1415
paused: PropTypes.bool,
1516
locked: PropTypes.bool,
17+
persist: PropTypes.bool,
1618
}).isRequired,
1719
};
1820

src/app/containers/MainContainer.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ class MainContainer extends Component {
120120
mode.locked = !locked;
121121
break;
122122
case 'persist':
123-
port.postMessage({ action: 'setPersist', payload: !locked });
123+
port.postMessage({ action: 'setPersist', payload: !persist });
124124
mode.persist = !persist;
125125
break;
126126
default:

src/app/styles/components/_buttons.scss

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,9 @@
4545
margin: 7px;
4646
}
4747

48-
.lock-button {
49-
@extend %button-shared;
50-
}
51-
52-
.pause-button {
48+
.lock-button,
49+
.pause-button,
50+
.persist-button {
5351
@extend %button-shared;
5452
}
5553

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
.buttons-container {
22
margin: 0 1% 0 1%;
33
display: grid;
4-
grid-template-columns: 1fr 1fr;
4+
grid-template-columns: repeat(3, 1fr);
55
grid-gap: 1%;
66
padding: 1% 0 1% 0;
77
}

src/extension/background.js

Lines changed: 29 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ const mode = {
55
locked: false,
66
paused: false,
77
};
8+
let firstSnapshot = true;
89

910
// establishing connection with devtools
1011
chrome.runtime.onConnect.addListener((port) => {
@@ -50,21 +51,35 @@ chrome.runtime.onConnect.addListener((port) => {
5051

5152
// background.js recieves message from contentScript.js
5253
chrome.runtime.onMessage.addListener((request) => {
53-
if (request.action === 'tabReload') snapshotArr = [];
54+
const { action } = request;
55+
const { persist } = mode;
5456

55-
if (request.action === 'recordSnap') {
56-
snapshotArr.push(request.payload);
57-
// if port is not null, send a message to devtools
58-
if (bg) {
59-
// TODO:
60-
// get active tab id
61-
// get snapshot arr from tab object
57+
switch (action) {
58+
case 'tabReload':
59+
firstSnapshot = true;
60+
if (!persist) snapshotArr = [];
61+
break;
62+
case 'recordSnap':
63+
// don't do anything for the first snapshot if current mode is persist
64+
if (persist && firstSnapshot) {
65+
firstSnapshot = false;
66+
break;
67+
}
68+
firstSnapshot = false;
69+
snapshotArr.push(request.payload);
70+
// if port is not null, send a message to devtools
71+
if (bg) {
72+
// TODO:
73+
// get active tab id
74+
// get snapshot arr from tab object
6275

63-
// send message to devtools
64-
bg.postMessage({
65-
action: 'sendSnapshots',
66-
payload: snapshotArr,
67-
});
68-
}
76+
// send message to devtools
77+
bg.postMessage({
78+
action: 'sendSnapshots',
79+
payload: snapshotArr,
80+
});
81+
}
82+
break;
83+
default:
6984
}
7085
});

0 commit comments

Comments
 (0)