-
Notifications
You must be signed in to change notification settings - Fork 133
Add remix contest and loading skeletons to new explore page #12075
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
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
96 changes: 96 additions & 0 deletions
96
packages/web/src/components/remix-contest-card/RemixContestCard.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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> | ||
| ) | ||
| } | ||
| ) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| export { RemixContestCard } from './RemixContestCard' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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, | ||
|
|
@@ -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' | ||
|
|
@@ -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' | ||
|
|
@@ -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() | ||
| 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) => { | ||
|
|
@@ -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) => ( | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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'> | ||
|
|
@@ -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> | ||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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!
There was a problem hiding this comment.
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