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-3003] Add album backlink to track screen #8531

Merged
merged 2 commits into from
May 17, 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
6 changes: 5 additions & 1 deletion packages/mobile/src/components/details-tile/DetailsTile.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -392,7 +392,11 @@ export const DetailsTile = ({
contentType={contentType}
/>
) : null}
<DetailsTileMetadata genre={track?.genre} mood={track?.mood} />
<DetailsTileMetadata
id={contentId}
genre={track?.genre}
mood={track?.mood}
/>
<SecondaryStats
isCollection={isCollection}
playCount={playCount}
Expand Down
42 changes: 30 additions & 12 deletions packages/mobile/src/components/details-tile/DetailsTileMetadata.tsx
Original file line number Diff line number Diff line change
@@ -1,21 +1,25 @@
import type { PropsWithChildren } from 'react'

import type { ID } from '@audius/common/models'
import type { Nullable } from '@audius/common/utils'
import { trpc } from '@audius/web/src/utils/trpcClientWeb'
import { Image } from 'react-native'

import { Flex, Text, useTheme } from '@audius/harmony-native'
import { Flex, Text, TextLink, useTheme } from '@audius/harmony-native'
import { moodMap } from 'app/utils/moods'

const messages = {
genre: 'Genre',
mood: 'Mood'
mood: 'Mood',
album: 'Album'
}

type MetadataProps = {
type MetadataProps = PropsWithChildren<{
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

imo its easier to read with children?: ReactNode, but curious what folks think

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

love the change to children though, esp with the TextLink add

label: string
value: string
}
}>

const Metadata = (props: MetadataProps) => {
const { label, value } = props
const { label, children } = props

return (
<Text>
Expand All @@ -28,35 +32,49 @@ const Metadata = (props: MetadataProps) => {
{label}
</Text>{' '}
<Text variant='body' size='s' strength='strong'>
{value}
{children}
</Text>
</Text>
)
}

type DetailsTileMetadataProps = {
id?: ID
genre?: string
mood?: Nullable<string>
}

export const DetailsTileMetadata = (props: DetailsTileMetadataProps) => {
const { genre, mood } = props
const { id, genre, mood } = props
const { spacing } = useTheme()

if (!genre && !mood) return null
const { data: albumInfo } = trpc.tracks.getAlbumBacklink.useQuery(
// @ts-ignore enabled flag handles the case where track is undefined
{ trackId: id },
{ enabled: !!id }
)

if (!genre && !mood && !albumInfo) return null

return (
<Flex w='100%' direction='row' gap='l'>
{genre ? <Metadata label={messages.genre} value={genre} /> : null}
<Flex w='100%' direction='row' gap='l' wrap='wrap'>
{genre ? <Metadata label={messages.genre}>{genre}</Metadata> : null}
{mood ? (
<Flex direction='row' gap='xs'>
<Metadata label={messages.mood} value={mood} />
<Metadata label={messages.mood}>{mood}</Metadata>
<Image
source={moodMap[mood]}
style={{ height: spacing.l, width: spacing.l }}
/>
</Flex>
) : null}
{albumInfo ? (
<Metadata label={messages.album}>
<TextLink to={albumInfo.permalink}>
{albumInfo.playlist_name}
</TextLink>
</Metadata>
) : null}
</Flex>
)
}