feat: change skip segment button position depending if controls are visible

This commit is contained in:
Prayag Prajapati committed 2025-07-04 15:29:31 +05:30
1 parent c9d16f4669
commit f919162dfc
3 files changed
+36 -23

No files matched your search

@@ -4,25 +4,32 @@ import { useShallow } from "zustand/shallow";
import { usePlaybackStore } from "@/utils/store/playback";
const SkipSegmentButton = () => {
const { mediaSegments, currentSegmentIndex, skipSegment, activeSegmentId } =
usePlaybackStore(
useShallow((state) => ({
mediaSegments: state.metadata.mediaSegments,
currentSegmentIndex: state.nextSegmentIndex - 1,
skipSegment: state.skipSegment,
activeSegmentId: state.activeSegmentId,
})),
);
const {
mediaSegments,
currentSegmentIndex,
skipSegment,
activeSegmentId,
isUserHovering,
isPlayerPlaying,
isUserSeeking,
} = usePlaybackStore(
useShallow((state) => ({
mediaSegments: state.metadata.mediaSegments,
currentSegmentIndex: state.nextSegmentIndex - 1,
skipSegment: state.skipSegment,
activeSegmentId: state.activeSegmentId,
isUserHovering: state.playerState.isUserHovering,
isPlayerPlaying: state.playerState.isPlayerPlaying,
isUserSeeking: state.playerState.isUserSeeking,
})),
);
console.info("Active segment ID:", activeSegmentId);
console.info("Current segment index:", currentSegmentIndex);
console.info("Media segments:", mediaSegments?.Items);
if (
!mediaSegments?.Items?.length ||
currentSegmentIndex < 0 ||
!activeSegmentId
) {
return <></>; // No segments to skip
return null; // No segments to skip
}
return (
@@ -33,8 +40,10 @@ const SkipSegmentButton = () => {
color="white"
style={{
position: "absolute",
bottom: "18vh",
bottom:
isUserHovering || !isPlayerPlaying || isUserSeeking ? "18vh" : "2em",
right: "2em",
transition: "bottom 0.3s ease-in-out",
zIndex: 10000,
}}
onClick={skipSegment}
@@ -38,13 +38,13 @@ import ProgressDislay from "./ProgressDisplay";
const VOLUME_SCROLL_INTERVAL = 0.02;
type VideoPlayerControlsProps = {
isVisible: boolean;
// isVisible: boolean;
onHover?: (event: MouseEvent<HTMLDivElement>) => void;
onLeave?: (event: MouseEvent<HTMLDivElement>) => void;
};
const VideoPlayerControls = ({
isVisible,
// isVisible,
onHover,
onLeave,
}: VideoPlayerControlsProps) => {
@@ -69,6 +69,7 @@ const VideoPlayerControls = ({
increaseVolumeByStep,
decreaseVolumeByStep,
getCurrentTime,
isUserHovering,
} = usePlaybackStore(
useShallow((state) => ({
mediaSourceId: state.mediaSource.id,
@@ -90,6 +91,7 @@ const VideoPlayerControls = ({
increaseVolumeByStep: state.increaseVolumeByStep,
decreaseVolumeByStep: state.decreaseVolumeByStep,
getCurrentTime: state.getCurrentTime,
isUserHovering: state.playerState.isUserHovering,
})),
);
@@ -168,7 +170,7 @@ const VideoPlayerControls = ({
return (
<motion.div
className={
isVisible || isUserSeeking || !isPlayerPlaying
isUserHovering || isUserSeeking || !isPlayerPlaying
? "video-player-osd hovering"
: "video-player-osd"
}
@@ -179,7 +181,7 @@ const VideoPlayerControls = ({
opacity: 0,
}}
animate={{
opacity: isVisible || isUserSeeking || !isPlayerPlaying ? 1 : 0,
opacity: isUserHovering || isUserSeeking || !isPlayerPlaying ? 1 : 0,
}}
style={{
zIndex: 2,