Skip to content

changed file structure and added tree class #23

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 26, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ class MainContainer extends Component {
super();
this.state = {
snapshots: [],
snapshotsTree: null,
snapshotIndex: 0,
currentIndex: null,
port: null,
Expand All @@ -20,13 +21,12 @@ class MainContainer extends Component {
}

componentDidMount() {
console.log('componentDidMount');
// open connection with background script
const port = chrome.runtime.connect();

// listen for a message containing snapshots from the background script
port.onMessage.addListener((snapshots) => {
console.log('message from background script', snapshots);
console.log('snapshots', this.state.snapshots);
const snapshotIndex = snapshots.length - 1;

// set state with the information received from the background script
Expand All @@ -49,9 +49,11 @@ class MainContainer extends Component {
}

// change the snapshot index
// --> 1. affects the action that is highlighted
// --> 2. moves the slider
// this will change the state shown in the state container but won't change the DOM
handleChangeSnapshot(snapshotIndex) {
// snapshotIndex
// --> 1. affects the action that is highlighted
// --> 2. moves the slider
this.setState({ snapshotIndex });
}

Expand All @@ -61,23 +63,27 @@ class MainContainer extends Component {
let { currentIndex } = this.state;
const payload = [];

// currentIndex is initialized to null
// currentIndex = null means that the user hasn't jumped yet
currentIndex = currentIndex === null ? snapshots.length - 1 : currentIndex;

// if the user wants to jump backward
if (currentIndex > snapshotIndex) {
for (let i = currentIndex - 1; i >= snapshotIndex; i -= 1) {
payload.push(snapshots[i]);
}
} else {
// if the user wants to jump forward
for (let i = currentIndex + 1; i <= snapshotIndex; i += 1) {
payload.push(snapshots[i]);
}
}

// currentIndex should be changed to index the user jumped to
this.setState({ currentIndex: snapshotIndex });

console.log('payload', payload);
// send the arrays of snapshots to background script
port.postMessage({ action: 'stepToSnap', payload });
// port.postMessage({ action: 'jumpToSnap', payload: snapshots[snapshotIndex] });
}

render() {
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
console.log('contentScript injected');
console.log('contentScript running');

// listening for messages from npm package
window.addEventListener('message', (msg) => {
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion extension/panel.html → src/extension/panel.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

<body>
<div id="root"></div>
<link rel="stylesheet" type="text/css" href="./app/styles/panel.css" />
<link rel="stylesheet" type="text/css" href="./styles/panel.css" />
<script type="text/javascript" src="panel.js"></script>
<script type="text/javascript" src="dist/app.bundle.js"></script>
</body>
Expand Down
File renamed without changes.
File renamed without changes.
7 changes: 7 additions & 0 deletions src/extension/tree.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
module.exports = function Graph(snapshot, parent) {
this.parent = parent;
this.snapshot = snapshot;
this.children = [];
this.add = (snapshot) => {};
this.remove = () => {};
};
25 changes: 12 additions & 13 deletions webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ const ChromeExtensionReloader = require('webpack-chrome-extension-reloader');

const config = {
entry: {
app: './extension/app/index.js',
background: './extension/background.js',
app: './src/app/index.js',
background: './src/extension/background.js',
},
output: {
path: path.resolve(__dirname, 'extension/dist'),
path: path.resolve(__dirname, 'src/extension/dist'),
filename: '[name].bundle.js',
},
module: {
Expand All @@ -27,10 +27,7 @@ const config = {
},
{
test: /\.css$/,
use: [
'style-loader',
'css-loader',
],
use: ['style-loader', 'css-loader'],
},
],
},
Expand All @@ -39,12 +36,14 @@ const config = {

module.exports = (env, argv) => {
if (argv.mode === 'development') {
config.plugins.push(new ChromeExtensionReloader({
entries: {
contentScript: ['app'],
background: ['background'],
},
}));
config.plugins.push(
new ChromeExtensionReloader({
entries: {
contentScript: ['app'],
background: ['background'],
},
}),
);
}
return config;
};