Skip to content

Commit

Permalink
Merge pull request #2547 from stakwork/bugfix/player-max-call
Browse files Browse the repository at this point in the history
fix: moved playing player state to store
  • Loading branch information
Rassl authored Dec 23, 2024
2 parents c16b233 + b09119d commit 3252ecc
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 20 deletions.
25 changes: 15 additions & 10 deletions src/components/mindset/components/MediaPlayer/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -89,14 +89,6 @@ const MediaPlayerComponent = ({ mediaUrl }: Props) => {
setIsPlaying(!isPlaying)
}, [isPlaying, setIsPlaying])

const handlePlay = useCallback(() => {
setIsPlaying(true)
}, [setIsPlaying])

const handlePause = useCallback(() => {
setIsPlaying(false)
}, [setIsPlaying])

const handleError = () => {
setHasError(true)
setStatus('error')
Expand Down Expand Up @@ -150,8 +142,21 @@ const MediaPlayerComponent = ({ mediaUrl }: Props) => {
}
}

const handlePlayerClick = () => {
togglePlay()
const handlePlay = useCallback(() => {
if (!isPlaying) {
setIsPlaying(true)
}
}, [setIsPlaying, isPlaying])

const handlePause = useCallback(() => {
if (isPlaying) {
setIsPlaying(false)
}
}, [setIsPlaying, isPlaying])

// eslint-disable-next-line @typescript-eslint/no-explicit-any
const handlePlayerClick = (e: any) => {
e.stopPropagation() // Prevent click from propagating to the player
}

const playerRefCallback = useCallback(
Expand Down
14 changes: 4 additions & 10 deletions src/components/mindset/components/PlayerContols/Controls/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ import { usePlayerStore } from '~/stores/usePlayerStore'
import { colors } from '~/utils/colors'

export const Controls = memo(() => {
const { isPlaying, playerRef } = usePlayerStore((s) => s)
const isPlaying = usePlayerStore((s) => s.isPlaying)
const setIsPlaying = usePlayerStore((s) => s.setIsPlaying)
const playerRef = usePlayerStore((s) => s.playerRef)

const handleRewind = () => {
if (playerRef) {
Expand All @@ -27,15 +29,7 @@ export const Controls = memo(() => {
}

const togglePlay = () => {
if (playerRef?.getInternalPlayer()) {
if (isPlaying) {
playerRef.getInternalPlayer().pauseVideo()

return
}

playerRef.getInternalPlayer().playVideo()
}
setIsPlaying(!isPlaying)
}

return (
Expand Down

0 comments on commit 3252ecc

Please sign in to comment.