Skip to content

Commit 8c71160

Browse files
committed
fix slider not updating when jumping to a snapshot
1 parent b9fc68e commit 8c71160

File tree

3 files changed

+25
-24
lines changed

3 files changed

+25
-24
lines changed

src/app/FrontendTypes.ts

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

250250
export interface MainSliderProps {
251251
className: string;
252-
snapshotsLength: number;
253252
snapshots: any[];
254253
}
255254

src/app/components/TimeTravel/VerticalSlider.tsx

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -29,20 +29,29 @@ const handle = (props: HandleProps): JSX.Element => {
2929

3030
function VerticalSlider(props: MainSliderProps): JSX.Element {
3131
const dispatch = useDispatch();
32-
const { snapshotsLength, snapshots } = 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

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
37+
useEffect(() => {
38+
if (currLocation) {
39+
// if we have a 'currLocation'
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+
50+
} else {
51+
setSliderIndex(0); // just set the thumb position to the beginning
52+
}
53+
}, [currLocation]); // if currLocation changes, rerun useEffect
54+
4655

4756
return (
4857
<Slider
@@ -52,19 +61,13 @@ function VerticalSlider(props: MainSliderProps): JSX.Element {
5261
reverse = 'true'
5362
height = '100%'
5463
min={0} // index of our first snapshot
55-
max={snapshotsLength - 1} // index of our last snapshot
64+
max={snapshots.length - 1} // index of our last snapshot
5665
value={sliderIndex} // currently slider thumb position
5766
onChange={(index: any) => {
5867
// when the slider position changes
5968
setSliderIndex(index); // update the sliderIndex
6069
dispatch(changeSlider(snapshots[index].props.index));
6170
}}
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-
// }}
6871
handle={handle}
6972
/>
7073
);

src/app/containers/ActionContainer.tsx

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import VerticalSlider from '../components/TimeTravel/VerticalSlider';
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.
1515
*/
1616

17+
1718
// resetSlider locates the rc-slider elements on the document and resets it's style attributes
1819
const resetSlider = () => {
1920
const slider = document.querySelector('.rc-slider-handle');
@@ -54,6 +55,7 @@ function ActionContainer(props: ActionContainerProps): JSX.Element {
5455
children?: [];
5556
}
5657
*/
58+
5759

5860
const displayArray = (obj: Obj): void => {
5961
if (
@@ -82,6 +84,7 @@ function ActionContainer(props: ActionContainerProps): JSX.Element {
8284
if (obj.children) {
8385
// if argument has a 'children' array, we iterate through it and run 'displayArray' on each element
8486
obj.children.forEach((element): void => {
87+
//recursive call
8588
displayArray(element);
8689
});
8790
}
@@ -129,6 +132,7 @@ function ActionContainer(props: ActionContainerProps): JSX.Element {
129132
const selected = index === viewIndex; // boolean on whether the current index is the same as the viewIndex
130133
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
131134
const isCurrIndex = index === currLocation.index;
135+
132136
return (
133137
<Action
134138
key={`action${index}`}
@@ -242,11 +246,6 @@ function ActionContainer(props: ActionContainerProps): JSX.Element {
242246
flexDirection: 'row',
243247
alignItems: 'flex-start',
244248
}}>
245-
{/* <div className='slider' style={{
246-
// height: '65vh',
247-
}}>
248-
<VerticalSlider className='main-slider' snapshotsLength={Object.keys(routes).length} />
249-
</div> */}
250249
<div className='snapshots'>
251250
{/* Rendering of route description components */}
252251
{Object.keys(routes).map((route, i) => (
@@ -256,7 +255,7 @@ function ActionContainer(props: ActionContainerProps): JSX.Element {
256255
height: `${routes[route].length * 4.5}vh`,
257256
marginBottom: '30px'
258257
}}>
259-
<VerticalSlider className='main-slider' snapshotsLength={routes[route].length} snapshots={routes[route]}/>
258+
<VerticalSlider className='main-slider' snapshots={routes[route]}/>
260259
<RouteDescription key={`route${i}`} actions={routes[route]} />
261260
</div>
262261
))}

0 commit comments

Comments
 (0)