Skip to content

Commit b9fc68e

Browse files
committed
added functioning individual vertical sliders per route
1 parent 8f70979 commit b9fc68e

File tree

5 files changed

+105
-10
lines changed

5 files changed

+105
-10
lines changed

src/app/FrontendTypes.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,7 @@ export interface HandleProps {
250250
export interface MainSliderProps {
251251
className: string;
252252
snapshotsLength: number;
253+
snapshots: any[];
253254
}
254255

255256
export interface DefaultMargin {
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
import React, { useState, useEffect } from 'react';
2+
import Slider from 'rc-slider';
3+
import Tooltip from 'rc-tooltip';
4+
import { changeSlider, pause } from '../../slices/mainSlice';
5+
import { useDispatch, useSelector } from 'react-redux';
6+
import { HandleProps, MainSliderProps, MainState, RootState } from '../../FrontendTypes';
7+
8+
const { Handle } = Slider; // component constructor of Slider that allows customization of the handle
9+
//takes in snapshot length
10+
const handle = (props: HandleProps): JSX.Element => {
11+
const { value, dragging, index, ...restProps } = props;
12+
13+
return (
14+
<Tooltip // Tooltip that pop's up when clicking/dragging the slider thumb/handle that displays the current snapshot index
15+
className='travel-tooltip'
16+
prefixCls='rc-slider-tooltip'
17+
overlay={value} // the currentIndex
18+
visible={dragging} // tooltip only visible when slider thumb is click and/or dragged
19+
placement='top' // display the tooltip above the slider thumb
20+
key={index}
21+
>
22+
<Handle
23+
value={value} // the currentIndex / slider thumb position on the slider
24+
{...restProps}
25+
/>
26+
</Tooltip>
27+
);
28+
};
29+
30+
function VerticalSlider(props: MainSliderProps): JSX.Element {
31+
const dispatch = useDispatch();
32+
const { snapshotsLength, snapshots } = props; // destructure props to get our total number of snapshots
33+
const [sliderIndex, setSliderIndex] = useState(0); // create a local state 'sliderIndex' and set it to 0.
34+
const { tabs, currentTab }: MainState = useSelector((state: RootState) => state.main);
35+
const { currLocation } = tabs[currentTab]; // we destructure the currentTab object
36+
37+
// useEffect(() => {
38+
// if (currLocation) {
39+
// // if we have a 'currLocation'
40+
// //@ts-ignore
41+
// setSliderIndex(currLocation.index); // set our slider thumb position to the 'currLocation.index'
42+
// } else {
43+
// setSliderIndex(0); // just set the thumb position to the beginning
44+
// }
45+
// }, [currLocation]); // if currLocation changes, rerun useEffect
46+
47+
return (
48+
<Slider
49+
className='travel-slider'
50+
color='#0af548'
51+
vertical = 'true'
52+
reverse = 'true'
53+
height = '100%'
54+
min={0} // index of our first snapshot
55+
max={snapshotsLength - 1} // index of our last snapshot
56+
value={sliderIndex} // currently slider thumb position
57+
onChange={(index: any) => {
58+
// when the slider position changes
59+
setSliderIndex(index); // update the sliderIndex
60+
dispatch(changeSlider(snapshots[index].props.index));
61+
}}
62+
// onChangeComplete={() => {
63+
// // after updating the sliderIndex
64+
// console.log("sliderIndex", sliderIndex)
65+
// dispatch(changeSlider(sliderIndex)); // updates currentTab's 'sliderIndex' and replaces our snapshot with the appropriate snapshot[sliderIndex]
66+
// dispatch(pause()); // pauses playing and sets currentTab object'a intervalId to null
67+
// }}
68+
handle={handle}
69+
/>
70+
);
71+
}
72+
73+
export default VerticalSlider;

src/app/containers/ActionContainer.tsx

Lines changed: 27 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@
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';
9-
import DropDown from '../components/Actions/DropDown';
108
import { ActionContainerProps, CurrentTab, MainState, Obj, RootState } from '../FrontendTypes';
119
import { Button, Switch } from '@mui/material';
10+
import Slider from 'rc-slider';
11+
import VerticalSlider from '../components/TimeTravel/VerticalSlider';
1212

1313
/*
1414
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.
@@ -223,8 +223,6 @@ function ActionContainer(props: ActionContainerProps): JSX.Element {
223223
{recordingActions ? <Switch defaultChecked /> : <Switch />}
224224
</a>
225225
<SwitchAppDropdown />
226-
{/* add new component here for dropdown menu for useStae/ useReducer- ragad */}
227-
<DropDown />
228226
<div className='action-component exclude'>
229227
<Button
230228
className='clear-button'
@@ -239,10 +237,31 @@ function ActionContainer(props: ActionContainerProps): JSX.Element {
239237
Clear
240238
</Button>
241239
</div>
242-
{/* Rendering of route description components */}
243-
{Object.keys(routes).map((route, i) => (
244-
<RouteDescription key={`route${i}`} actions={routes[route]} />
245-
))}
240+
<div className='MapRouteAndSlider' style={{
241+
display: 'flex',
242+
flexDirection: 'row',
243+
alignItems: 'flex-start',
244+
}}>
245+
{/* <div className='slider' style={{
246+
// height: '65vh',
247+
}}>
248+
<VerticalSlider className='main-slider' snapshotsLength={Object.keys(routes).length} />
249+
</div> */}
250+
<div className='snapshots'>
251+
{/* Rendering of route description components */}
252+
{Object.keys(routes).map((route, i) => (
253+
<div style={{
254+
display: 'flex',
255+
flexDirection: 'row',
256+
height: `${routes[route].length * 4.5}vh`,
257+
marginBottom: '30px'
258+
}}>
259+
<VerticalSlider className='main-slider' snapshotsLength={routes[route].length} snapshots={routes[route]}/>
260+
<RouteDescription key={`route${i}`} actions={routes[route]} />
261+
</div>
262+
))}
263+
</div>
264+
</div>
246265
</div>
247266
) : null}
248267
</div>

src/app/containers/TravelContainer.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ function TravelContainer(props: TravelContainerProps): JSX.Element {
8585
>
8686
{playing ? 'Pause' : 'Play'}
8787
</Button>
88-
<MainSlider className='main-slider' snapshotsLength={snapshotsLength} />
88+
{/* <MainSlider className='main-slider' snapshotsLength={snapshotsLength} /> */}
8989
<Button
9090
variant='contained'
9191
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)