smov/src/components/video/controls/PauseControl.tsx
2023-01-08 13:15:32 +01:00

32 lines
755 B
TypeScript

import { useCallback, useContext } from "react";
import {
VideoPlayerContext,
VideoPlayerDispatchContext,
} from "../VideoContext";
export function PauseControl() {
const dispatch = useContext(VideoPlayerDispatchContext);
const video = useContext(VideoPlayerContext);
const handleClick = useCallback(() => {
if (video.controlState === "playing")
dispatch({
type: "CONTROL",
do: "PAUSE",
});
else if (video.controlState === "paused")
dispatch({
type: "CONTROL",
do: "PLAY",
});
}, [video, dispatch]);
let text = "paused";
if (video.controlState === "playing") text = "playing";
return (
<button type="button" onClick={handleClick}>
{text}
</button>
);
}