Skip to content

Commit 7bb8211

Browse files
authored
Merge pull request #7 from oslabs-beta/PatriceFeature
Created Functioning Vertical Sliders Per Route
2 parents 20a5052 + bcd1cba commit 7bb8211

File tree

5 files changed

+50
-21
lines changed

5 files changed

+50
-21
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/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: 26 additions & 5 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';
@@ -11,11 +10,14 @@ import ProvConContainer from './ProvConContainer';
1110
import { ActionContainerProps, CurrentTab, MainState, Obj, RootState } from '../FrontendTypes';
1211
import { Button, Switch } from '@mui/material';
1312

13+
import Slider from 'rc-slider';
14+
import VerticalSlider from '../components/TimeTravel/VerticalSlider';
1415

1516
/*
1617
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.
1718
*/
1819

20+
1921
// resetSlider locates the rc-slider elements on the document and resets it's style attributes
2022
const resetSlider = () => {
2123
const slider = document.querySelector('.rc-slider-handle');
@@ -59,6 +61,7 @@ function ActionContainer(props: ActionContainerProps): JSX.Element {
5961
children?: [];
6062
}
6163
*/
64+
6265

6366
const displayArray = (obj: Obj): void => {
6467
if (
@@ -87,6 +90,7 @@ function ActionContainer(props: ActionContainerProps): JSX.Element {
8790
if (obj.children) {
8891
// if argument has a 'children' array, we iterate through it and run 'displayArray' on each element
8992
obj.children.forEach((element): void => {
93+
//recursive call
9094
displayArray(element);
9195
});
9296
}
@@ -134,6 +138,7 @@ function ActionContainer(props: ActionContainerProps): JSX.Element {
134138
const selected = index === viewIndex; // boolean on whether the current index is the same as the viewIndex
135139
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
136140
const isCurrIndex = index === currLocation.index;
141+
137142
return (
138143
<Action
139144
key={`action${index}`}
@@ -247,12 +252,28 @@ function ActionContainer(props: ActionContainerProps): JSX.Element {
247252
Clear
248253
</Button>
249254
</div>
250-
{dropdownSelection === 'Provider/Consumer' && <ProvConContainer/>}
251-
{dropdownSelection === 'TimeJump' &&
255+
<div className='MapRouteAndSlider' style={{
256+
display: 'flex',
257+
flexDirection: 'row',
258+
alignItems: 'flex-start',
259+
}}>
260+
<div className='snapshots'>
261+
{dropdownSelection === 'Provider/Consumer' && <ProvConContainer/>}
262+
{dropdownSelection === 'TimeJump' &&
252263
Object.keys(routes).map((route, i) => (
253-
<RouteDescription key={`route${i}`} actions={routes[route]} />
254-
))
264+
<div style={{
265+
display: 'flex',
266+
flexDirection: 'row',
267+
height: `${routes[route].length * 4.5}vh`,
268+
marginBottom: '30px'
269+
}}>
270+
<VerticalSlider className='main-slider' snapshots={routes[route]}/>
271+
<RouteDescription key={`route${i}`} actions={routes[route]} />
272+
</div>
273+
))
255274
}
275+
</div>
276+
</div>
256277
</div>
257278
) : null}
258279
</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)