Skip to content

Commit

Permalink
Make behavior of forward button more intuitive
Browse files Browse the repository at this point in the history
This patch makes the forward button jump to the end of the video
if you are currently in the last segment.

The previous behavior, jumping to the **beginning** of the last segment,
made it so that the forward button sometimes made you go backwards in the video.
This is especially confusing if there is only one segment,
in which case the forward button put you at the beginning of the video.
  • Loading branch information
JulianKniephoff committed Nov 25, 2024
1 parent 7e81181 commit d204ae4
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions src/redux/videoSlice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -171,14 +171,17 @@ const videoSlice = createSlice({
state.jumpTriggered = true;
},
jumpToNextSegment: state => {
let nextSegmentIndex = state.activeSegmentIndex + 1;
const nextSegmentIndex = state.activeSegmentIndex + 1;
let jumpTarget = 0;

if (state.activeSegmentIndex + 1 >= state.segments.length) {
// Jump to start of last segment
nextSegmentIndex = state.activeSegmentIndex;
// Jump to end of last segment
jumpTarget = state.segments[state.activeSegmentIndex].end;
} else {
jumpTarget = state.segments[nextSegmentIndex].start;
}

updateCurrentlyAt(state, state.segments[nextSegmentIndex].start);
updateCurrentlyAt(state, jumpTarget);
state.jumpTriggered = true;
},
addSegment: (state, action: PayloadAction<video["segments"][0]>) => {
Expand Down

0 comments on commit d204ae4

Please sign in to comment.