From c8d04d90afbe622cb600498652fae2d4a2b6f8e9 Mon Sep 17 00:00:00 2001 From: Raymond Jacobson Date: Thu, 26 Oct 2023 09:56:05 -0700 Subject: [PATCH 1/3] [PAY-2043] Stop preview when purchase succeeds --- packages/common/src/store/purchase-content/sagas.ts | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/packages/common/src/store/purchase-content/sagas.ts b/packages/common/src/store/purchase-content/sagas.ts index 0d4db145354..898e7f879ae 100644 --- a/packages/common/src/store/purchase-content/sagas.ts +++ b/packages/common/src/store/purchase-content/sagas.ts @@ -23,6 +23,8 @@ import { getUSDCUserBank } from 'store/buy-usdc/utils' import { getTrack } from 'store/cache/tracks/selectors' import { getUser } from 'store/cache/users/selectors' import { getContext } from 'store/effects' +import { getPreviewing, getTrackId } from 'store/player/selectors' +import { stop } from 'store/player/slice' import { saveTrack } from 'store/social/tracks/actions' import { BN_USDC_CENT_WEI, ceilingBNUSDCToNearestCent } from 'utils/wallet' @@ -257,6 +259,13 @@ function* doStartPurchaseContentFlow({ yield* put(saveTrack(contentId, FavoriteSource.IMPLICIT)) } + // Check if playing the purchased track's preview and if so, stop it + const isPreviewing = yield* select(getPreviewing) + const trackId = yield* select(getTrackId) + if (contentId === trackId && isPreviewing) { + yield* put(stop({})) + } + // finish yield* put(purchaseConfirmed({ contentId, contentType })) From 55383d6cb704cf4c124eab9c01ad1c1c1ccffbed Mon Sep 17 00:00:00 2001 From: Raymond Jacobson Date: Fri, 27 Oct 2023 12:10:51 -0700 Subject: [PATCH 2/3] Handle mobile stop --- .../mobile/src/components/audio/Audio.tsx | 23 +++++++++++++++++-- .../now-playing-drawer/NowPlayingDrawer.tsx | 6 +++++ 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/packages/mobile/src/components/audio/Audio.tsx b/packages/mobile/src/components/audio/Audio.tsx index bb8dc2ab6d9..ddf05a70d24 100644 --- a/packages/mobile/src/components/audio/Audio.tsx +++ b/packages/mobile/src/components/audio/Audio.tsx @@ -73,8 +73,14 @@ import { useSavePodcastProgress } from './useSavePodcastProgress' const { getUserId } = accountSelectors const { getUsers } = cacheUsersSelectors const { getTracks } = cacheTracksSelectors -const { getPlaying, getSeek, getCurrentTrack, getCounter, getPlaybackRate } = - playerSelectors +const { + getPlaying, + getSeek, + getCurrentTrack, + getCounter, + getPlaybackRate, + getUid +} = playerSelectors const { setTrackPosition } = playbackPositionActions const { getUserTrackPositions } = playbackPositionSelectors const { recordListen } = tracksSocialActions @@ -170,6 +176,8 @@ export const Audio = () => { const repeatMode = useSelector(getRepeat) const playbackRate = useSelector(getPlaybackRate) const currentUserId = useSelector(getUserId) + const uid = useSelector(getUid) + const previousUid = usePrevious(uid) const trackPositions = useSelector((state: CommonState) => getUserTrackPositions(state, { userId: currentUserId }) ) @@ -703,6 +711,10 @@ export const Audio = () => { } }, [playbackState, playing]) + const handleStop = useCallback(async () => { + await TrackPlayer.reset() + }, []) + const handleRepeatModeChange = useCallback(async () => { if (repeatMode === RepeatMode.SINGLE) { await TrackPlayer.setRepeatMode(TrackPlayerRepeatMode.Track) @@ -746,6 +758,13 @@ export const Audio = () => { handlePlaybackRateChange() }, [handlePlaybackRateChange, playbackRate]) + useEffect(() => { + // Stop playback if we have unloaded a uid from the player + if (previousUid && !uid && !playing) { + handleStop() + } + }, [handleStop, playing, uid, previousUid]) + useSavePodcastProgress() return null diff --git a/packages/mobile/src/components/now-playing-drawer/NowPlayingDrawer.tsx b/packages/mobile/src/components/now-playing-drawer/NowPlayingDrawer.tsx index 61087ae354f..b3d2150b7e7 100644 --- a/packages/mobile/src/components/now-playing-drawer/NowPlayingDrawer.tsx +++ b/packages/mobile/src/components/now-playing-drawer/NowPlayingDrawer.tsx @@ -134,6 +134,12 @@ export const NowPlayingDrawer = memo(function NowPlayingDrawer( } }, [isPlaying, isPlayBarShowing]) + useEffect(() => { + if (!currentUid) { + setIsPlayBarShowing(false) + } + }, [currentUid]) + const onDrawerOpen = useCallback(() => { Keyboard.dismiss() onOpen() From 66805d170f6af0439bd762669f442fd4ad5ea580 Mon Sep 17 00:00:00 2001 From: Raymond Jacobson Date: Fri, 27 Oct 2023 12:45:29 -0700 Subject: [PATCH 3/3] Remove await --- packages/mobile/src/components/audio/Audio.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/mobile/src/components/audio/Audio.tsx b/packages/mobile/src/components/audio/Audio.tsx index ddf05a70d24..f6c33113636 100644 --- a/packages/mobile/src/components/audio/Audio.tsx +++ b/packages/mobile/src/components/audio/Audio.tsx @@ -712,7 +712,7 @@ export const Audio = () => { }, [playbackState, playing]) const handleStop = useCallback(async () => { - await TrackPlayer.reset() + TrackPlayer.reset() }, []) const handleRepeatModeChange = useCallback(async () => {