Skip to content

Commit 384a752

Browse files
authored
Merge pull request #14 from C-STYR/expander
Add a "View Time Travel" button to collapse/expand actions container
2 parents 9555327 + e444e62 commit 384a752

File tree

6 files changed

+96
-25
lines changed

6 files changed

+96
-25
lines changed

src/app/components/SwitchApp.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import Select from 'react-select';
33
import { useStoreContext } from '../store';
44
import { setTab } from '../actions/actions';
55

6+
67
const SwitchAppDropdown = () => {
78
const [{ currentTab, tabs }, dispatch] = useStoreContext();
89

src/app/containers/ActionContainer.tsx

Lines changed: 35 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,13 @@ const resetSlider = () => {
1414
}
1515
};
1616

17-
function ActionContainer() {
17+
function ActionContainer(props) {
1818
const [{ tabs, currentTab }, dispatch] = useStoreContext();
1919
const { hierarchy, sliderIndex, viewIndex } = tabs[currentTab];
2020
let actionsArr = [];
2121
const hierarchyArr: any[] = [];
22+
const { timeTravel } = props;
23+
// React.useEffect(() => { console.log("component updated"); }, [timeTravel]);
2224

2325
// function to traverse state from hiararchy and also getting information on display name and component name
2426
const displayArray = (obj: {
@@ -112,25 +114,39 @@ function ActionContainer() {
112114
}
113115
);
114116

115-
return (
116-
<div className="action-container">
117-
<SwitchAppDropdown />
118-
<div className="action-component exclude">
119-
<button
120-
className="empty-button"
121-
onClick={() => {
122-
dispatch(emptySnapshots());
123-
// set slider back to zero
124-
resetSlider();
125-
}}
126-
type="button"
127-
>
128-
Empty
129-
</button>
117+
if (!timeTravel) {
118+
console.log("should be false:", timeTravel)
119+
return (
120+
//returns an empty div when timeTravel is false
121+
122+
<div></div>
123+
)
124+
}
125+
else {
126+
console.log("Should be true:", timeTravel);
127+
// this is not logging; the prop is not being udpdated or the component is not being re-rendered.
128+
return (
129+
<div className="action-container">
130+
<SwitchAppDropdown />
131+
<div className="action-component exclude">
132+
<button
133+
className="empty-button"
134+
onClick={() => {
135+
dispatch(emptySnapshots());
136+
// set slider back to zero
137+
resetSlider();
138+
}}
139+
type="button"
140+
>
141+
Empty
142+
</button>
143+
</div>
144+
<div>{actionsArr}</div>
130145
</div>
131-
<div>{actionsArr}</div>
132-
</div>
133-
);
146+
);
147+
148+
}
149+
134150
}
135151

136152
export default ActionContainer;

src/app/containers/MainContainer.tsx

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React, { useEffect } from 'react';
1+
import React, { useEffect, useState } from 'react';
22
import HeadContainer from './HeadContainer';
33
import ActionContainer from './ActionContainer';
44
import StateContainer from './StateContainer';
@@ -13,16 +13,38 @@ import {
1313
} from '../actions/actions';
1414
import { useStoreContext } from '../store';
1515
import MPID from '../user_id/user_id';
16+
import useForceUpdate from '../components/useForceUpdate'
17+
18+
19+
//logic for toggling on the action container sidebar
20+
1621

1722
const mixpanel = require('mixpanel').init('12fa2800ccbf44a5c36c37bc9776e4c0', {
1823
debug: false,
1924
protocol: 'https',
2025
});
2126

2227
function MainContainer(): any {
28+
const [timeTravel, setTimeTravel] = useState(false);
2329
const [store, dispatch] = useStoreContext();
2430
const { tabs, currentTab, port: currentPort } = store;
2531
// add event listeners to background script
32+
33+
function toggleActionContainer(): void {
34+
setTimeTravel(!timeTravel)
35+
const bodyContainer = document.getElementById("bodyContainer");
36+
37+
if (timeTravel) {
38+
bodyContainer.classList.remove("body-container2");
39+
bodyContainer.classList.add("body-container1");
40+
41+
}
42+
else {
43+
bodyContainer.classList.remove("body-container1");
44+
bodyContainer.classList.add("body-container2");
45+
}
46+
}
47+
2648
useEffect(() => {
2749
// only open port once
2850
if (currentPort) return;
@@ -177,11 +199,12 @@ function MainContainer(): any {
177199
const hierarchyDisplay = statelessCleaning(hierarchy);
178200
return (
179201
<div className="main-container">
180-
<HeadContainer />
181-
<div className="body-container">
182-
<ActionContainer />
202+
{/* <HeadContainer /> */}
203+
<div id="bodyContainer" className="body-container1">
204+
<ActionContainer timeTravel={timeTravel}/>
183205
{snapshots.length ? (
184206
<StateContainer
207+
toggleActionContainer={toggleActionContainer}
185208
viewIndex={viewIndex}
186209
snapshot={snapshotDisplay}
187210
hierarchy={hierarchyDisplay}

src/app/containers/StateContainer.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,17 @@ interface StateContainerProps {
2323
atomsComponents?: object;
2424
}
2525
>;
26+
toggleActionContainer?: any;
2627
AtomsRelationship?: any[];
2728
hierarchy: Record<string, unknown>;
2829
snapshots: [];
2930
viewIndex: number;
31+
3032
}
3133

3234
// eslint-disable-next-line react/prop-types
3335
const StateContainer = (props: StateContainerProps): JSX.Element => {
34-
const { snapshot, hierarchy, snapshots, viewIndex } = props;
36+
const { snapshot, hierarchy, snapshots, viewIndex, toggleActionContainer } = props;
3537
const [Text, setText] = useState('State');
3638

3739
return (
@@ -40,6 +42,7 @@ const StateContainer = (props: StateContainerProps): JSX.Element => {
4042
<div className="main-navbar-container">
4143
<div className="main-navbar-text">{Text}</div>
4244
<div className="main-navbar">
45+
<button className="toggleAC" onClick={()=> toggleActionContainer()}>View Time Travel</button>
4346
<NavLink
4447
className="main-router-link"
4548
activeClassName="is-active"

src/app/styles/layout/_bodyContainer.scss

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,16 @@
1-
.body-container {
1+
.body-container1 {
2+
height: 94%;
3+
overflow: hidden;
4+
display: grid;
5+
grid-template-columns: 1fr 2fr;
6+
grid-template-rows: 8fr 1fr;
7+
grid-template-areas:
8+
'states states'
9+
'travel travel'
10+
'buttons buttons';
11+
}
12+
13+
.body-container2 {
214
height: 94%;
315
overflow: hidden;
416
display: grid;
@@ -10,6 +22,8 @@
1022
'buttons buttons';
1123
}
1224

25+
26+
1327
/* if extension width is less than 500px, stack the body containers */
1428
@media (max-width: 500px) {
1529
.body-container {

src/app/styles/layout/_stateContainer.scss

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,20 @@
99
overflow: hidden;
1010
}
1111

12+
.toggleAC {
13+
color: $background-color;
14+
background: $blue-brand;
15+
border-radius: 5px;
16+
border: 1px solid rgba(184, 196, 194, 0.25);
17+
height: 75%;
18+
text-decoration: none;
19+
}
20+
21+
.toggleAC:focus {
22+
outline: none;
23+
box-shadow: none;
24+
}
25+
1226
.state-container .navbar {
1327
background-color: $background-color;
1428
display: flex;

0 commit comments

Comments
 (0)