Skip to content

Commit 2cbc888

Browse files
authored
Merge branch 'dev' into jimmyFeat
2 parents af45f54 + e9e207e commit 2cbc888

File tree

3 files changed

+80
-10
lines changed

3 files changed

+80
-10
lines changed

src/app/RTKslices.tsx

Lines changed: 57 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,7 @@ export const mainSlice = createSlice({
202202
tabs[currentTab].playing = false;
203203
tabs[currentTab].intervalId = null;
204204
},
205+
205206
playForward: (state, action) => {
206207
const {port, tabs, currentTab} = state
207208
const { hierarchy, snapshots, sliderIndex, intervalId } = tabs[currentTab] || {};
@@ -301,8 +302,60 @@ export const mainSlice = createSlice({
301302
tabId: currentTab,
302303
});
303304
tabs[currentTab].sliderIndex = 0;
304-
}
305+
},
306+
307+
305308

309+
toggleMode: (state, action)=>{
310+
console.log('Toggle Mode')
311+
const { port, tabs, currentTab } = state;
312+
const {mode} = tabs[currentTab] || {};
313+
mode[action.payload] = !mode[action.payload];
314+
const newMode = mode[action.payload];
315+
let actionText;
316+
switch (action.payload) {
317+
case 'paused':
318+
actionText = 'setPause';
319+
default:
320+
}
321+
port.postMessage({
322+
action: actionText,
323+
payload: newMode,
324+
tabId: currentTab,
325+
});
326+
},
327+
importSnapshots: (state, action) => {
328+
console.log('importSnapshots')
329+
const { port, tabs, currentTab } = state;
330+
// Log the value of tabs[currentTab].snapshots before the update
331+
port.postMessage({
332+
action: 'import',
333+
payload: action.payload,
334+
tabId: currentTab,
335+
});
336+
337+
const savedSnapshot = action.payload;
338+
339+
tabs[currentTab].sliderIndex = savedSnapshot.sliderIndex;
340+
tabs[currentTab].viewIndex = savedSnapshot.viewIndex;
341+
tabs[currentTab].playing = false;
342+
343+
// resets hierarchy to page last state recorded
344+
tabs[currentTab].hierarchy.stateSnapshot = savedSnapshot.hierarchy.stateSnapshot;
345+
346+
// resets hierarchy
347+
tabs[currentTab].hierarchy.children = savedSnapshot.hierarchy.children;
348+
349+
// resets snapshots to page last state recorded
350+
tabs[currentTab].snapshots = savedSnapshot.snapshots;
351+
352+
// resets currLocation to page last state recorded
353+
tabs[currentTab].currLocation = tabs[currentTab].hierarchy;
354+
tabs[currentTab].index = savedSnapshot.index;
355+
tabs[currentTab].currParent = savedSnapshot.currParent;
356+
tabs[currentTab].currBranch = savedSnapshot.Branch;
357+
tabs[currentTab].seriesSavedStatus = false;
358+
}
306359

307360
},
308361
})
@@ -324,7 +377,9 @@ export const {
324377
startPlaying,
325378
moveForward,
326379
moveBackward,
327-
resetSlider
380+
resetSlider,
381+
toggleMode,
382+
importSnapshots
328383
} = mainSlice.actions
329384

330385

src/app/components/SwitchApp.tsx

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
import React from 'react';
22
import Select from 'react-select';
3-
import { useStoreContext } from '../store';
4-
import { setTab } from '../actions/actions';
3+
//commented out for RTK
4+
// import { useStoreContext } from '../store';
5+
import { setTab } from '../RTKslices';
6+
//importing these methods for RTK
7+
import { useSelector, useDispatch } from 'react-redux';
58

69
/*
710
This is the dropdown menu on the left column above the 'clear' button and the state snapshots list. It allows us to switch between which website/application we are currently working on.
@@ -10,8 +13,13 @@ import { setTab } from '../actions/actions';
1013
*/
1114

1215
const SwitchAppDropdown = (): JSX.Element => {
13-
const [{ currentTab, tabs }, dispatch] = useStoreContext(); // we destructure the returned context object from the invocation of the useStoreContext function. Properties not found on the initialState object (dispatch) are from the useReducer function invocation in the App component
14-
16+
//commented out to implement RTK
17+
// const [{ currentTab, tabs }, dispatch] = useStoreContext(); // we destructure the returned context object from the invocation of the useStoreContext function. Properties not found on the initialState object (dispatch) are from the useReducer function invocation in the App component
18+
//here we are adding useSelector and useDispatch for RTK state conversion
19+
const dispatch = useDispatch();
20+
const currentTab = useSelector((state: any) => state.main.currentTab)
21+
const tabs = useSelector((state: any) => state.main.tabs)
22+
1523
const tabsArray: {}[] = []; // tabsArray is an empty array that will take objects as it's elements
1624

1725
Object.keys(tabs).forEach((tab) => { // We populate our 'tabsArray' with objects derived from the 'tab' that is currently being iterated on.

src/app/containers/ButtonsContainer.tsx

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
import * as React from 'react';
2-
import { importSnapshots, toggleMode } from '../actions/actions';
3-
import { useStoreContext } from '../store';
2+
// import { importSnapshots, toggleMode } from '../actions/actions';
3+
// import { useStoreContext } from '../store';
44
import { Button } from '@mui/material';
55
import Tutorial from '../components/Tutorial';
66
import LockIcon from '@mui/icons-material/Lock';
77
import LockOpenIcon from '@mui/icons-material/LockOpen';
88
import FileDownloadIcon from '@mui/icons-material/FileDownload';
99
import FileUploadIcon from '@mui/icons-material/FileUpload';
10+
import { toggleMode, importSnapshots } from '../RTKslices';
11+
import { useDispatch, useSelector } from 'react-redux';
1012

1113
function exportHandler(snapshots: []): void { // function that takes in our tabs[currentTab] object to be exported as a JSON file. NOTE: TypeScript needs to be updated
1214
const fileDownload: HTMLAnchorElement = document.createElement('a'); // invisible HTML element that will hold our tabs[currentTab] object
@@ -43,8 +45,13 @@ function importHandler(dispatch: (a: unknown) => void): void { // function handl
4345
}
4446

4547
function ButtonsContainer(): JSX.Element {
46-
const [{ tabs, currentTab, currentTabInApp }, dispatch] = useStoreContext();
47-
const { snapshots, mode: { paused }} = tabs[currentTab];
48+
// const [{ tabs, currentTab, currentTabInApp }, dispatch] = useStoreContext();
49+
// const [state, dispatch] = useStoreContext();
50+
const dispatch = useDispatch();
51+
const currentTab = useSelector((state: any) => state.main.currentTab);
52+
const tabs = useSelector((state: any)=>state.main.tabs);
53+
const currentTabInApp = useSelector((state: any)=> state.main.currentTabInApp);
54+
const { mode: { paused }} = tabs[currentTab];
4855

4956
return (
5057
<div className='buttons-container'>

0 commit comments

Comments
 (0)