Skip to content

Commit 10950e8

Browse files
committed
2 parents d2864e6 + 98498ab commit 10950e8

File tree

6 files changed

+56
-26
lines changed

6 files changed

+56
-26
lines changed

src/app/FrontendTypes.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,7 @@ export interface HandleProps {
249249

250250
export interface MainSliderProps {
251251
className: string;
252-
snapshotsLength: number;
252+
snapshots: any[];
253253
}
254254

255255
export interface DefaultMargin {

src/app/components/Actions/RouteDescription.tsx

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
import React from 'react';
2+
import Slider from 'rc-slider';
3+
import VerticalSlider from '../TimeTravel/VerticalSlider';
24

35
/*
46
Render's the red route description on app's left sided column between the clear button and the list of state snapshots. The route description is derived from the first state snapshot.
@@ -12,12 +14,26 @@ const RouteDescription = (props: RouteProps): JSX.Element => {
1214
const { actions } = props;
1315

1416
const url: URL = new URL(actions[0].props.routePath); // Use new URL to use the url.pathname method.
17+
1518
return (
16-
<div className='routedescription'>
17-
<h3 className='route'>Route: {url.pathname}</h3>
18-
{actions}
19-
</div>
19+
<div className='routedescription' >
20+
<h3 className='route'>Route: {url.pathname}</h3>
21+
<div style={{
22+
// div that contains slider and snapshots
23+
display: 'flex',
24+
flexDirection: 'row',
25+
height: `${actions.length * 30}px`,
26+
marginBottom: '50px'
27+
}}>
28+
<VerticalSlider className='main-slider' snapshots={actions} />
29+
<div style={{marginTop: '10px'}}>
30+
{/* actual snapshots per route */}
31+
{actions}
32+
</div>
33+
</div>
34+
</div>
2035
);
2136
};
2237

38+
2339
export default RouteDescription;

src/app/components/TimeTravel/MainSlider.tsx renamed to src/app/components/TimeTravel/VerticalSlider.tsx

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { useDispatch, useSelector } from 'react-redux';
66
import { HandleProps, MainSliderProps, MainState, RootState } from '../../FrontendTypes';
77

88
const { Handle } = Slider; // component constructor of Slider that allows customization of the handle
9-
9+
//takes in snapshot length
1010
const handle = (props: HandleProps): JSX.Element => {
1111
const { value, dragging, index, ...restProps } = props;
1212

@@ -27,42 +27,50 @@ const handle = (props: HandleProps): JSX.Element => {
2727
);
2828
};
2929

30-
function MainSlider(props: MainSliderProps): JSX.Element {
30+
function VerticalSlider(props: MainSliderProps): JSX.Element {
3131
const dispatch = useDispatch();
32-
const { snapshotsLength } = props; // destructure props to get our total number of snapshots
32+
const { snapshots} = props; // destructure props to get our total number of snapshots
3333
const [sliderIndex, setSliderIndex] = useState(0); // create a local state 'sliderIndex' and set it to 0.
3434
const { tabs, currentTab }: MainState = useSelector((state: RootState) => state.main);
3535
const { currLocation } = tabs[currentTab]; // we destructure the currentTab object
3636

3737
useEffect(() => {
3838
if (currLocation) {
3939
// if we have a 'currLocation'
40-
//@ts-ignore
41-
setSliderIndex(currLocation.index); // set our slider thumb position to the 'currLocation.index'
40+
let correctedSliderIndex;
41+
42+
for (let i = 0; i<snapshots.length; i++){
43+
//@ts-ignore -- ignores the errors on the next line
44+
if (snapshots[i].props.index === currLocation.index){
45+
correctedSliderIndex = i;
46+
}
47+
}
48+
setSliderIndex(correctedSliderIndex)
49+
4250
} else {
4351
setSliderIndex(0); // just set the thumb position to the beginning
4452
}
4553
}, [currLocation]); // if currLocation changes, rerun useEffect
54+
4655

4756
return (
4857
<Slider
4958
className='travel-slider'
5059
color='#0af548'
60+
vertical = 'true'
61+
reverse = 'true'
62+
height = '100%'
5163
min={0} // index of our first snapshot
52-
max={snapshotsLength - 1} // index of our last snapshot
64+
max={snapshots.length - 1} // index of our last snapshot
5365
value={sliderIndex} // currently slider thumb position
5466
onChange={(index: any) => {
5567
// when the slider position changes
5668
setSliderIndex(index); // update the sliderIndex
57-
}}
58-
onAfterChange={() => {
59-
// after updating the sliderIndex
60-
dispatch(changeSlider(sliderIndex)); // updates currentTab's 'sliderIndex' and replaces our snapshot with the appropriate snapshot[sliderIndex]
61-
dispatch(pause()); // pauses playing and sets currentTab object'a intervalId to null
69+
dispatch(changeSlider(snapshots[index].props.index));
6270
}}
6371
handle={handle}
6472
/>
6573
);
6674
}
6775

68-
export default MainSlider;
76+
export default VerticalSlider;

src/app/containers/ActionContainer.tsx

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
import React, { useEffect, useState } from 'react';
33
import Action from '../components/Actions/Action';
44
import SwitchAppDropdown from '../components/Actions/SwitchApp';
5-
// Import new dropdown
65
import { emptySnapshots, changeView, changeSlider } from '../slices/mainSlice';
76
import { useDispatch, useSelector } from 'react-redux';
87
import RouteDescription from '../components/Actions/RouteDescription';
@@ -15,6 +14,7 @@ import { Button, Switch } from '@mui/material';
1514
This file renders the 'ActionContainer'. The action container is the leftmost column in the application. It includes the button that shrinks and expands the action container, a dropdown to select the active site, a clear button, the current selected Route, and a list of selectable snapshots with timestamps.
1615
*/
1716

17+
1818
// resetSlider locates the rc-slider elements on the document and resets it's style attributes
1919
const resetSlider = () => {
2020
const slider = document.querySelector('.rc-slider-handle');
@@ -57,6 +57,7 @@ function ActionContainer(props: ActionContainerProps): JSX.Element {
5757
children?: [];
5858
}
5959
*/
60+
6061

6162
const displayArray = (obj: Obj): void => {
6263
if (
@@ -85,6 +86,7 @@ function ActionContainer(props: ActionContainerProps): JSX.Element {
8586
if (obj.children) {
8687
// if argument has a 'children' array, we iterate through it and run 'displayArray' on each element
8788
obj.children.forEach((element): void => {
89+
//recursive call
8890
displayArray(element);
8991
});
9092
}
@@ -132,6 +134,7 @@ function ActionContainer(props: ActionContainerProps): JSX.Element {
132134
const selected = index === viewIndex; // boolean on whether the current index is the same as the viewIndex
133135
const last = viewIndex === -1 && index === hierarchyArr.length - 1; // boolean on whether the view index is less than 0 and if the index is the same as the last snapshot's index value in hierarchyArr
134136
const isCurrIndex = index === currLocation.index;
137+
135138
return (
136139
<Action
137140
key={`action${index}`}
@@ -244,11 +247,14 @@ function ActionContainer(props: ActionContainerProps): JSX.Element {
244247
Clear
245248
</Button>
246249
</div>
247-
{dropdownSelection === 'Provider/Consumer' && <ProvConContainer />}
248-
{dropdownSelection === 'TimeJump' &&
249-
Object.keys(routes).map((route, i) => (
250-
<RouteDescription key={`route${i}`} actions={routes[route]} />
251-
))}
250+
<div className='snapshots'>
251+
{dropdownSelection === 'Provider/Consumer' && <ProvConContainer/>}
252+
{dropdownSelection === 'TimeJump' &&
253+
Object.keys(routes).map((route, i) => (
254+
<RouteDescription key={`route${i}`} actions={routes[route]} />
255+
))
256+
}
257+
</div>
252258
</div>
253259
) : null}
254260
</div>

src/app/containers/TravelContainer.tsx

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
/* eslint-disable max-len */
22
import React, { useState } from 'react';
3-
import MainSlider from '../components/TimeTravel/MainSlider';
43
import Dropdown from '../components/TimeTravel/Dropdown';
54
import {
65
playForward,
@@ -85,7 +84,6 @@ function TravelContainer(props: TravelContainerProps): JSX.Element {
8584
>
8685
{playing ? 'Pause' : 'Play'}
8786
</Button>
88-
<MainSlider className='main-slider' snapshotsLength={snapshotsLength} />
8987
<Button
9088
variant='contained'
9189
className='backward-button'

src/app/slices/mainSlice.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,14 +201,16 @@ export const mainSlice = createSlice({
201201
tabs[currentTab].viewIndex = viewIndex === action.payload ? -1 : action.payload;
202202
},
203203

204-
changeSlider: (state, action) => {
204+
changeSlider: (state, action) => { //should really be called jump to snapshot
205205
const { port, currentTab, tabs } = state;
206206
const { hierarchy, snapshots } = tabs[currentTab] || {};
207207

208208
// finds the name by the action.payload parsing through the hierarchy to send to background.js the current name in the jump action
209209
const nameFromIndex = findName(action.payload, hierarchy);
210210
// nameFromIndex is a number based on which jump button is pushed
211211

212+
console.log("changeSlider to ", action.payload);
213+
212214
port.postMessage({
213215
action: 'jumpToSnap',
214216
payload: snapshots[action.payload],

0 commit comments

Comments
 (0)