Skip to content
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
import { MouseEvent, Ref, forwardRef, useCallback } from 'react'

import { useRemixContest, useTrack, useUser } from '@audius/common/api'
import { ID, SquareSizes } from '@audius/common/models'
import { formatDate } from '@audius/common/utils'
import { Flex, Skeleton, Text } from '@audius/harmony'
import { useLinkClickHandler } from 'react-router-dom-v5-compat'

import { Card, CardProps, CardFooter, CardContent } from 'components/card'
import { TextLink, UserLink } from 'components/link'
import { TrackArtwork } from 'components/track/TrackArtwork'

const messages = {
deadline: (releaseDate?: string) =>
`Deadline ${releaseDate ? (new Date(releaseDate) < new Date() ? formatDate(releaseDate) : 'Ended') : releaseDate}`
}

type RemixContestCardProps = Omit<CardProps, 'id'> & {
id: ID
loading?: boolean
noNavigation?: boolean
}

export const RemixContestCard = forwardRef(
(props: RemixContestCardProps, ref: Ref<HTMLDivElement>) => {
const { id, loading, size, onClick, noNavigation, ...other } = props

const { data: remixContest, isPending: isRemixContestPending } =
useRemixContest(id)
const { data: track, isPending: isTrackPending } = useTrack(
remixContest?.entityId
)
const { data: user, isPending: isUserPending } = useUser(track?.owner_id)

const isPending =
isRemixContestPending || isTrackPending || isUserPending || !track

const permalink = track?.permalink

const handleNavigate = useLinkClickHandler<HTMLDivElement>(permalink ?? '')

const handleClick = useCallback(
(e: MouseEvent<HTMLDivElement>) => {
onClick?.(e)
if (noNavigation) return
handleNavigate(e)
},
[noNavigation, handleNavigate, onClick]
)

if (isPending || loading) {
return (
<Card size={size} {...other}>
<Flex direction='column' p='s' gap='s'>
<Skeleton border='default' css={{ aspectRatio: 1 }} />
<CardContent gap='xs'>
<Skeleton h={24} w='80%' alignSelf='center' />
<Skeleton h={20} w='50%' alignSelf='center' />
</CardContent>
</Flex>
<CardFooter>
<Skeleton h={16} w='60%' alignSelf='center' />
</CardFooter>
</Card>
)
}

return (
<Card ref={ref} onClick={handleClick} size={size} {...other}>
<Flex direction='column' p='s' gap='s'>
<TrackArtwork
trackId={track.track_id}
size={SquareSizes.SIZE_150_BY_150}
mr='xs'
css={{ minHeight: 24, minWidth: 24 }}
/>
<CardContent gap='xs'>
<TextLink
to={permalink}
textVariant='title'
css={{ justifyContent: 'center' }}
>
<Text ellipses>{track?.title}</Text>
</TextLink>
<Flex justifyContent='center'>
<UserLink userId={user?.user_id} popover center />
</Flex>
</CardContent>
</Flex>
<CardFooter>
<Text>{messages.deadline(remixContest?.endDate)} </Text>
</CardFooter>
</Card>
)
}
)
1 change: 1 addition & 0 deletions packages/web/src/components/remix-contest-card/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { RemixContestCard } from './RemixContestCard'
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import { useCallback, useEffect, useState } from 'react'

import { useFeaturedPlaylists, useFeaturedProfiles } from '@audius/common/api'
import { User } from '@audius/common/models'
import { TQCollection } from '@audius/common/src/api/tan-query/models'
import { useExploreContent } from '@audius/common/api'
import { ExploreCollectionsVariant } from '@audius/common/store'
import {
Paper,
Expand All @@ -26,6 +24,7 @@ import { CollectionCard } from 'components/collection'
import PerspectiveCard, {
TextInterior
} from 'components/perspective-card/PerspectiveCard'
import { RemixContestCard } from 'components/remix-contest-card'
import { UserCard } from 'components/user-card'
import { useIsUSDCEnabled } from 'hooks/useIsUSDCEnabled'
import useTabs from 'hooks/useTabs/useTabs'
Expand Down Expand Up @@ -66,7 +65,7 @@ const messages = {
description: 'Discover the hottest and trendiest tracks on Audius right now',
searchPlaceholder: 'What do you want to listen to?',
featuredPlaylists: 'Featured Playlists',
remixContests: 'Remix Contests',
featuredRemixContests: 'Featured Remix Contests',
artistSpotlight: 'Artist Spotlight',
bestOfAudius: 'Best of Audius',
viewAll: 'View All'
Expand Down Expand Up @@ -119,13 +118,13 @@ const ExplorePage = ({ title, pageTitle, description }: ExplorePageProps) => {
const navigate = useNavigate()
const showSearchResults = useShowSearchResults()

const { data: featuredPlaylists } = useFeaturedPlaylists(
{ limit: FEATURED_LIMIT },
{ placeholderData: (prev: TQCollection[]) => prev }
)
const { data: featuredProfiles } = useFeaturedProfiles({
limit: FEATURED_LIMIT
})
const { data: exploreContent } = useExploreContent()

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

so do we want all the data consolidated to one hook? i kinda think we should keep them separate so they can load asap? fine with this for now though!

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

i think this way is actually slightly more performant because useFeaturedPlaylists for example will use useExploreContent and useCollections, getting more data when all we need is ids here

const featuredPlaylists =
exploreContent?.featuredPlaylists.slice(0, FEATURED_LIMIT) ?? []
const featuredProfiles =
exploreContent?.featuredProfiles.slice(0, FEATURED_LIMIT) ?? []
const featuredRemixContests =
exploreContent?.featuredRemixContests.slice(0, FEATURED_LIMIT) ?? []

const handleTabClick = useCallback(
(newTab: string) => {
Expand Down Expand Up @@ -277,15 +276,29 @@ const ExplorePage = ({ title, pageTitle, description }: ExplorePageProps) => {
</TextLink>
</Flex>
<Flex gap='l' justifyContent='space-between'>
{featuredPlaylists?.map((playlist) => (
{featuredPlaylists?.map((playlist_id) => (

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

nice that it's ids now

<CollectionCard
key={playlist.playlist_id}
id={playlist.playlist_id}
key={playlist_id}
id={playlist_id}
size={'s'}
/>
))}
</Flex>
</Flex>
<Flex>
<Flex direction='column' gap='l'>
<Text variant='heading'>{messages.featuredRemixContests}</Text>
<Flex gap='l' justifyContent='space-between'>
{featuredRemixContests?.map((featuredRemixContest) => (
<RemixContestCard
key={featuredRemixContest}
id={featuredRemixContest}
size={'s'}
/>
))}
</Flex>
</Flex>
</Flex>

{/* Artist Spotlight */}
<Flex direction='column' gap='l'>
Expand All @@ -301,12 +314,8 @@ const ExplorePage = ({ title, pageTitle, description }: ExplorePageProps) => {
</TextLink>
</Flex>
<Flex gap='l' alignSelf='stretch' justifyContent='space-between'>
{featuredProfiles?.map((featuredProfile: User) => (
<UserCard
key={featuredProfile.user_id}
id={featuredProfile.user_id}
size='s'
/>
{featuredProfiles?.map((user_id) => (
<UserCard key={user_id} id={user_id} size='s' />
))}
</Flex>
</Flex>
Expand Down