Skip to content

Commit 4c459d5

Browse files
committed
console logs in button container maincontainer main reducer
1 parent 68658d1 commit 4c459d5

File tree

3 files changed

+54
-8
lines changed

3 files changed

+54
-8
lines changed

src/app/containers/ButtonsContainer.tsx

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,24 +32,38 @@ function exportHandler(snapshots: []): void {
3232

3333
function importHandler(dispatch: (a: unknown) => void): void {
3434
const fileUpload = document.createElement('input');
35+
console.log('fileUpload element:', fileUpload)
3536
fileUpload.setAttribute('type', 'file');
3637

3738
fileUpload.onchange = (e: Event) => {
3839
const reader = new FileReader();
40+
console.log('on change triggered')
41+
//console.log('reader :', reader);
42+
43+
const eventFiles = e.target as HTMLInputElement;
44+
// console.log('e.target:', e.target)
45+
// console.log('event files:', eventFiles.files[0]);
46+
47+
if (eventFiles) {
48+
reader.readAsText(eventFiles.files[0]);
49+
}
50+
3951
reader.onload = () => {
52+
console.log('on load triggered:')
4053
const test = reader.result.toString();
4154
return dispatch(importSnapshots(JSON.parse(test)));
4255
};
43-
const eventFiles = e.target as HTMLInputElement;
44-
if (eventFiles?.hasOwnProperty('files')) {
45-
// const eventFiles = target as HTMLInputElement;
46-
if (eventFiles) {
47-
reader.readAsText(eventFiles.files[0]);
48-
}
49-
}
56+
// const eventFiles = e.target as HTMLInputElement;
57+
// if (eventFiles?.hasOwnProperty('files')) {
58+
// // const eventFiles = target as HTMLInputElement;
59+
// if (eventFiles) {
60+
// reader.readAsText(eventFiles.files[0]);
61+
// }
62+
// }
5063
};
5164

5265
fileUpload.click();
66+
//console.log('dispatch importSnapshots successful')
5367
}
5468

5569
function ButtonsContainer(): JSX.Element {
@@ -59,6 +73,8 @@ function ButtonsContainer(): JSX.Element {
5973
mode: { paused },
6074
} = tabs[currentTab];
6175

76+
console.log('----state after any change----', tabs[currentTab])
77+
6278
return (
6379
<div className='buttons-container'>
6480
<button className='pause-button' type='button' onClick={() => dispatch(toggleMode('paused'))}>

src/app/containers/MainContainer.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,11 @@ function MainContainer(): JSX.Element {
4545
// listen for a message containing snapshots from the background script
4646
currentPort.onMessage.addListener(
4747
// parameter message is an object with following type script properties
48-
(message: { action: string; payload: Record<string, unknown>; sourceTab: number }) => {
48+
(message: {
49+
action: string;
50+
payload: Record<string, unknown>;
51+
sourceTab: number
52+
}) => {
4953
const { action, payload, sourceTab } = message;
5054
let maxTab: number;
5155
if (!sourceTab) {

src/app/reducers/mainReducer.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,21 @@
11
import { produce } from 'immer';
22
import _, { values } from 'lodash';
33
import * as types from '../constants/actionTypes.ts';
4+
import { current } from 'immer';
45

56
export default (state, action) =>
67
produce(state, (draft) => {
78
const { port, currentTab, tabs } = draft;
89
const { hierarchy, snapshots, mode, intervalId, viewIndex, sliderIndex } =
910
tabs[currentTab] || {};
1011

12+
// console.log('----consoles before reducer funcs!-----')
13+
// console.log('state:', state)
14+
//console.log(tabs[currentTab]);
15+
//console.log('properties of tabs[currentTab]:', hierarchy, snapshots, mode, intervalId, viewIndex, sliderIndex)
16+
17+
//console.log('reducer file!', 'hierarchy:', hierarchy, 'tabs:', tabs)
18+
1119
// eslint-disable-next-line max-len
1220
// function that finds the index in the hierarchy and extracts the name of the equivalent index to add to the post message
1321
// eslint-disable-next-line consistent-return
@@ -36,6 +44,7 @@ export default (state, action) =>
3644
switch (action.type) {
3745
// This saves the series user wants to save to chrome local storage
3846
case types.SAVE: {
47+
console.log('save action reducer!', 'payload:', action.payload)
3948
const { newSeries, newSeriesName } = action.payload;
4049
if (!tabs[currentTab].seriesSavedStatus) {
4150
tabs[currentTab] = { ...tabs[currentTab], seriesSavedStatus: 'inputBoxOpen' };
@@ -177,6 +186,9 @@ export default (state, action) =>
177186
}
178187
case types.EMPTY: {
179188
// send msg to background script
189+
console.log('-----clear snapshots reducer----')
190+
console.log('state before:', state.tabs[currentTab])
191+
180192
port.postMessage({ action: 'emptySnap', tabId: currentTab });
181193
tabs[currentTab].sliderIndex = 0;
182194
tabs[currentTab].viewIndex = 0;
@@ -201,12 +213,26 @@ export default (state, action) =>
201213
break;
202214
}
203215
case types.IMPORT: {
216+
// Log the value of tabs[currentTab].snapshots before the update
217+
console.log('-----import snapshots reducer----')
218+
console.log('state before:', state.tabs[currentTab])
219+
220+
204221
port.postMessage({
205222
action: 'import',
206223
payload: action.payload,
207224
tabId: currentTab,
208225
});
226+
227+
209228
tabs[currentTab].snapshots = action.payload;
229+
230+
231+
232+
// console.log('New snapshots:', action.payload);
233+
// console.log('updated tabs[CurrentTab].snapshots:', tabs[currentTab].snapshots)
234+
//console.log('state after:', state)
235+
210236
break;
211237
}
212238
case types.TOGGLE_MODE: {

0 commit comments

Comments
 (0)