Skip to content

Commit e2ae093

Browse files
authored
Merge pull request #2 from oslabs-beta/andrewb
buttons container converted, added toggleMode and importSnapshots to …
2 parents 34a53b3 + d8dfdd5 commit e2ae093

File tree

2 files changed

+63
-5
lines changed

2 files changed

+63
-5
lines changed

src/app/RTKslices.tsx

Lines changed: 52 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,56 @@ export const mainSlice = createSlice({
202202
tabs[currentTab].playing = false;
203203
tabs[currentTab].intervalId = null;
204204
},
205-
205+
toggleMode: (state, action)=>{
206+
console.log('Toggle Mode')
207+
const { port, tabs, currentTab } = state;
208+
const {mode} = tabs[currentTab] || {};
209+
mode[action.payload] = !mode[action.payload];
210+
const newMode = mode[action.payload];
211+
let actionText;
212+
switch (action.payload) {
213+
case 'paused':
214+
actionText = 'setPause';
215+
default:
216+
}
217+
port.postMessage({
218+
action: actionText,
219+
payload: newMode,
220+
tabId: currentTab,
221+
});
222+
},
223+
importSnapshots: (state, action) => {
224+
console.log('importSnapshots')
225+
const { port, tabs, currentTab } = state;
226+
// Log the value of tabs[currentTab].snapshots before the update
227+
port.postMessage({
228+
action: 'import',
229+
payload: action.payload,
230+
tabId: currentTab,
231+
});
232+
233+
const savedSnapshot = action.payload;
234+
235+
tabs[currentTab].sliderIndex = savedSnapshot.sliderIndex;
236+
tabs[currentTab].viewIndex = savedSnapshot.viewIndex;
237+
tabs[currentTab].playing = false;
238+
239+
// resets hierarchy to page last state recorded
240+
tabs[currentTab].hierarchy.stateSnapshot = savedSnapshot.hierarchy.stateSnapshot;
241+
242+
// resets hierarchy
243+
tabs[currentTab].hierarchy.children = savedSnapshot.hierarchy.children;
244+
245+
// resets snapshots to page last state recorded
246+
tabs[currentTab].snapshots = savedSnapshot.snapshots;
247+
248+
// resets currLocation to page last state recorded
249+
tabs[currentTab].currLocation = tabs[currentTab].hierarchy;
250+
tabs[currentTab].index = savedSnapshot.index;
251+
tabs[currentTab].currParent = savedSnapshot.currParent;
252+
tabs[currentTab].currBranch = savedSnapshot.Branch;
253+
tabs[currentTab].seriesSavedStatus = false;
254+
}
206255
},
207256
})
208257

@@ -219,6 +268,8 @@ export const {
219268
changeSlider,
220269
setCurrentTabInApp,
221270
pause,
271+
toggleMode,
272+
importSnapshots
222273
} = mainSlice.actions
223274

224275

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)