Skip to content

Commit

Permalink
[C-2365] Update play buttons on web and mobile to show resume when tr…
Browse files Browse the repository at this point in the history
…ack is current (#3101)
  • Loading branch information
Kyle-Shanks committed Mar 24, 2023
1 parent 453910f commit b0441f5
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 5 deletions.
13 changes: 10 additions & 3 deletions packages/mobile/src/components/details-tile/DetailsTile.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import { useCallback } from 'react'

import type { Track } from '@audius/common'
import type { CommonState, Track } from '@audius/common'
import {
FeatureFlags,
Genre,
usePremiumContentAccess,
squashNewLines,
accountSelectors,
playerSelectors,
playbackPositionSelectors
} from '@audius/common'
import { TouchableOpacity, View } from 'react-native'
Expand Down Expand Up @@ -38,6 +39,7 @@ import { DetailsTileNoAccess } from './DetailsTileNoAccess'
import { DetailsTileStats } from './DetailsTileStats'
import type { DetailsTileProps } from './types'

const { getTrackId } = playerSelectors
const { getTrackPosition } = playbackPositionSelectors

const messages = {
Expand Down Expand Up @@ -220,6 +222,9 @@ export const DetailsTile = ({
const navigation = useNavigation()

const currentUserId = useSelector(accountSelectors.getUserId)
const isCurrentTrack = useSelector((state: CommonState) => {
return track && track.track_id === getTrackId(state)
})

const isOwner = user?.user_id === currentUserId
const isLongFormContent =
Expand Down Expand Up @@ -295,13 +300,15 @@ export const DetailsTile = ({

const playText =
isNewPodcastControlsEnabled && playbackPositionInfo?.status
? playbackPositionInfo?.status === 'IN_PROGRESS'
? playbackPositionInfo?.status === 'IN_PROGRESS' || isCurrentTrack
? messages.resume
: messages.replay
: messages.play

const PlayIcon =
isNewPodcastControlsEnabled && playbackPositionInfo?.status === 'COMPLETED'
isNewPodcastControlsEnabled &&
playbackPositionInfo?.status === 'COMPLETED' &&
!isCurrentTrack
? IconRepeat
: IconPlay

Expand Down
11 changes: 9 additions & 2 deletions packages/web/src/components/track/PlayPauseButton.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import {
FeatureFlags,
ID,
playerSelectors,
playbackPositionSelectors,
CommonState
} from '@audius/common'
Expand All @@ -12,6 +13,7 @@ import { useFlag } from 'hooks/useRemoteConfig'

import styles from './GiantTrackTile.module.css'

const { getTrackId } = playerSelectors
const { getTrackPosition } = playbackPositionSelectors

type PlayPauseButtonProps = {
Expand Down Expand Up @@ -45,16 +47,21 @@ export const PlayPauseButton = ({
const trackPlaybackInfo = useSelector((state: CommonState) =>
getTrackPosition(state, { trackId })
)
const isCurrentTrack = useSelector(
(state: CommonState) => trackId === getTrackId(state)
)

const playText =
isNewPodcastControlsEnabled && trackPlaybackInfo
? trackPlaybackInfo.status === 'IN_PROGRESS'
? trackPlaybackInfo.status === 'IN_PROGRESS' || isCurrentTrack
? messages.resume
: messages.replay
: messages.play

const playIcon =
isNewPodcastControlsEnabled && trackPlaybackInfo?.status === 'COMPLETED' ? (
isNewPodcastControlsEnabled &&
trackPlaybackInfo?.status === 'COMPLETED' &&
!isCurrentTrack ? (
<IconRepeat />
) : (
<IconPlay />
Expand Down

0 comments on commit b0441f5

Please sign in to comment.