Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: moved playing player state to store #2547

Merged
merged 1 commit into from
Dec 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading