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

[PAY-2775] Remove suggested tracks for albums #8288

Merged
merged 2 commits into from
May 1, 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
74 changes: 0 additions & 74 deletions packages/common/src/api/suggestedTracks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import { CommonState } from '~/store/index'
import { useGetFavoritedTrackList } from './favorites'
import { useGetTracksByIds } from './track'
import { useGetTrending } from './trending'
import { useGetTracksByUser } from './user'

const suggestedTrackCount = 5

Expand Down Expand Up @@ -97,79 +96,6 @@ const selectCollectionTrackIds = (state: CommonState, collectionId: ID) => {
return collection?.playlist_contents.track_ids.map((trackId) => trackId.track)
}

export const useGetSuggestedAlbumTracks = (collectionId: ID) => {
const currentUserId = useSelector(getUserId)
const dispatch = useDispatch()
const [suggestedTrackIds, setSuggestedTrackIds] = useState<ID[]>([])
const [isRefreshing, setIsRefreshing] = useState(false)

const collectionTrackIds = useSelector((state: CommonState) =>
selectCollectionTrackIds(state, collectionId)
)

const { data: ownTracks, status } = useGetTracksByUser(
{ userId: currentUserId!, currentUserId },
{ disabled: !currentUserId }
)

const reset = useCallback(() => {
if (status === Status.SUCCESS && ownTracks) {
const suggestedTrackIds = difference(
shuffle(ownTracks).map((track) => track.track_id),
collectionTrackIds
)
setSuggestedTrackIds(suggestedTrackIds)
}
}, [collectionTrackIds, ownTracks, status])

// eslint-disable-next-line react-hooks/exhaustive-deps
useEffect(reset, [status, ownTracks?.length])

const suggestedTracks = useSelector(
(state: CommonState) =>
selectSuggestedTracks(
state,
suggestedTrackIds,
setSuggestedTrackIds,
suggestedTrackIds.length
),
isEqual
)

const handleRefresh = useCallback(() => {
// Reset and shuffle owned tracks if we get too close to the end
if (suggestedTrackIds.length <= 2 * suggestedTrackCount - 1) {
reset()
return
}
setSuggestedTrackIds(suggestedTrackIds.slice(suggestedTrackCount))
setIsRefreshing(true)
}, [reset, suggestedTrackIds])

useEffect(() => {
if (suggestedTracks.every((suggestedTrack) => !suggestedTrack.isLoading)) {
setIsRefreshing(false)
}
}, [suggestedTracks])

const handleAddTrack = useCallback(
(trackId: ID) => {
dispatch(addTrackToPlaylist(trackId, collectionId))
const trackIndexToRemove = suggestedTrackIds.indexOf(trackId)
suggestedTrackIds.splice(trackIndexToRemove, 1)
setSuggestedTrackIds(suggestedTrackIds)
},
[collectionId, dispatch, suggestedTrackIds]
)

return {
suggestedTracks,
isRefreshing,
onRefresh: handleRefresh,
onAddTrack: handleAddTrack
}
}

export const useGetSuggestedPlaylistTracks = (collectionId: ID) => {
const currentUserId = useSelector(getUserId)
const dispatch = useDispatch()
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Fragment, useCallback, useEffect, useRef } from 'react'

import type { SuggestedTrack } from '@audius/common/api'
import { useGetSuggestedPlaylistTracks } from '@audius/common/api'
import { SquareSizes } from '@audius/common/models'
import type { ID, Track } from '@audius/common/models'
import { cacheUsersSelectors } from '@audius/common/store'
Expand All @@ -13,9 +13,9 @@ import { IconCaretDown, IconRefresh } from '@audius/harmony-native'
import { Button, Divider, Text, TextButton, Tile } from 'app/components/core'
import { makeStyles } from 'app/styles'

import { TrackImage } from '../../image/TrackImage'
import { Skeleton } from '../../skeleton'
import { UserBadges } from '../../user-badges'
import { TrackImage } from '../image/TrackImage'
import { Skeleton } from '../skeleton'
import { UserBadges } from '../user-badges'

const { getUser } = cacheUsersSelectors

Expand Down Expand Up @@ -135,15 +135,12 @@ const SuggestedTrackSkeleton = () => {

type SuggestedTracksProps = {
collectionId: ID
suggestedTracks: SuggestedTrack[]
onRefresh: () => void
onAddTrack: (trackId: ID) => void
isRefreshing: boolean
}

export const SuggestedTracks = (props: SuggestedTracksProps) => {
const { collectionId, suggestedTracks, onRefresh, onAddTrack, isRefreshing } =
props
const { collectionId } = props
const { suggestedTracks, onRefresh, onAddTrack, isRefreshing } =
useGetSuggestedPlaylistTracks(collectionId)
const styles = useStyles()

const [isExpanded, toggleIsExpanded] = useToggle(false)
Expand Down
2 changes: 1 addition & 1 deletion packages/mobile/src/components/suggested-tracks/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export * from './SuggestedCollectionTracks'
export * from './SuggestedTracks'
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ import {
Divider
} from 'app/components/core'
import { CollectionImage } from 'app/components/image/CollectionImage'
import { SuggestedCollectionTracks } from 'app/components/suggested-tracks'
import { SuggestedTracks } from 'app/components/suggested-tracks'
import { useIsOfflineModeEnabled } from 'app/hooks/useIsOfflineModeEnabled'
import { useNavigation } from 'app/hooks/useNavigation'
import { useRoute } from 'app/hooks/useRoute'
Expand Down Expand Up @@ -324,10 +324,10 @@ const CollectionScreenComponent = (props: CollectionScreenComponentProps) => {
streamConditions={stream_conditions}
ddexApp={ddex_app}
/>
{isOwner && (!is_album || isEditAlbumsEnabled) && !ddex_app ? (
{isOwner && !is_album && !ddex_app ? (
<>
<Divider style={styles.divider} color={neutralLight5} />
<SuggestedCollectionTracks collectionId={playlist_id} />
<SuggestedTracks collectionId={playlist_id} />
</>
) : null}
</>
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { useCallback } from 'react'

import { SuggestedTrack } from '@audius/common/api'
import { useGetSuggestedPlaylistTracks } from '@audius/common/api'
import { SquareSizes, ID, Track } from '@audius/common/models'
import { cacheUsersSelectors } from '@audius/common/store'
import { Button, IconCaretDown, IconRefresh, useTheme } from '@audius/harmony'
Expand Down Expand Up @@ -82,15 +82,12 @@ const SuggestedTrackSkeleton = () => {

type SuggestedTracksProps = {
collectionId: ID
suggestedTracks: SuggestedTrack[]
onRefresh: () => void
onAddTrack: (trackId: ID) => void
isRefreshing: boolean
}

export const SuggestedTracks = (props: SuggestedTracksProps) => {
const { collectionId, suggestedTracks, onRefresh, onAddTrack, isRefreshing } =
props
const { collectionId } = props
const { suggestedTracks, onRefresh, onAddTrack, isRefreshing } =
useGetSuggestedPlaylistTracks(collectionId)
const [isExpanded, toggleIsExpanded] = useToggle(false)
const { motion } = useTheme()

Expand Down
2 changes: 1 addition & 1 deletion packages/web/src/components/suggested-tracks/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export * from './SuggestedCollectionTracks'
export * from './SuggestedTracks'
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import {
import { CollectionHeader } from 'components/collection/desktop/CollectionHeader'
import { Divider } from 'components/divider'
import Page from 'components/page/Page'
import { SuggestedCollectionTracks } from 'components/suggested-tracks'
import { SuggestedTracks } from 'components/suggested-tracks'
import { Tile } from 'components/tile'
import { TracksTable, TracksTableColumn } from 'components/tracks-table'
import { useFlag } from 'hooks/useRemoteConfig'
Expand Down Expand Up @@ -358,10 +358,10 @@ const CollectionPage = ({
)}
</Tile>
<ClientOnly>
{isOwner && (!isAlbum || isEditAlbumsEnabled) && !isNftPlaylist ? (
{isOwner && !isAlbum && !isNftPlaylist ? (
<>
<Divider variant='default' className={styles.tileDivider} />
<SuggestedCollectionTracks collectionId={playlistId} />
<SuggestedTracks collectionId={playlistId} />
</>
) : null}
</ClientOnly>
Expand Down