Skip to content

Commit d508696

Browse files
committed
fixed pause/ play logic
1 parent b6a537f commit d508696

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

src/app/containers/TravelContainer.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import {
88
moveForward,
99
moveBackward,
1010
resetSlider,
11+
changeSlider,
1112
} from '../slices/mainSlice';
1213
import { useDispatch, useSelector } from 'react-redux';
1314
import { MainState, RootState, TravelContainerProps } from '../FrontendTypes';
@@ -40,6 +41,7 @@ function play( // function that will start/pause slider movement
4041
if (playing) {
4142
// if already playing, clicking the button will pause the slider
4243
dispatch(pause());
44+
4345
} else {
4446
let currentIndex = sliderIndex; // the 'currentIndex' will be wherever the 'sliderIndex' is
4547
if (currentIndex === snapshotsLength - 1) {
@@ -53,6 +55,7 @@ function play( // function that will start/pause slider movement
5355
// as long as we're not the last snapshot, increment slider up through our dispatch and increment index
5456
dispatch(playForward(true));
5557
currentIndex += 1;
58+
dispatch(changeSlider(currentIndex));
5659
} else {
5760
dispatch(pause()); // pause the slider when we reach the end
5861
}

src/app/slices/mainSlice.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,10 @@ export const mainSlice = createSlice({
8888
const { snapshots: newSnaps } = payload[tab];
8989
tabs[tab] = {
9090
...payload[tab],
91-
sliderIndex: newSnaps.length - 1,
91+
intervalId: tabs[tab].intervalId,
92+
playing: tabs[tab].playing,
93+
//sliderIndex: newSnaps.length - 1,
94+
sliderIndex: tabs[tab].sliderIndex,
9295
seriesSavedStatus: false,
9396
};
9497
}

0 commit comments

Comments
 (0)