Skip to content

Commit 1219e2a

Browse files
cursor[bot]cursoragentraymondjacobson
authored
Fix suggested artists popup list formatting (#14399)
## Summary - Fixed the Suggested Artists popup so featured names no longer render with a leading comma. - Filtered blank/whitespace artist names out of the displayed featured-name list. - Kept the remaining-artist count formatted as `, and N others`. ## Verification - `npx eslint --no-cache --ext=js,jsx,ts,tsx src/components/artist-recommendations/ArtistRecommendations.tsx` from `packages/web` - `npm run typecheck -w @audius/web` <div><a href="https://cursor.com/agents/bc-0e858a92-93b8-56b6-ba01-b62512376b12"><picture><source media="(prefers-color-scheme: dark)" srcset="https://cursor.com/assets/images/open-in-web-dark.png"><source media="(prefers-color-scheme: light)" srcset="https://cursor.com/assets/images/open-in-web-light.png"><img alt="Open in Web" width="114" height="28" src="https://cursor.com/assets/images/open-in-web-dark.png"></picture></a>&nbsp;<a href="https://cursor.com/automations/c63aa103-66df-4558-b31d-675358e5c6a1"><picture><source media="(prefers-color-scheme: dark)" srcset="https://cursor.com/assets/images/view-automation-dark.png"><source media="(prefers-color-scheme: light)" srcset="https://cursor.com/assets/images/view-automation-light.png"><img alt="View Automation" width="141" height="28" src="https://cursor.com/assets/images/view-automation-dark.png"></picture></a>&nbsp;</div> Co-authored-by: Cursor Agent <cursoragent@cursor.com> Co-authored-by: Ray Jacobson <raymondjacobson@users.noreply.github.com>
1 parent fa4a923 commit 1219e2a

1 file changed

Lines changed: 38 additions & 21 deletions

File tree

packages/web/src/components/artist-recommendations/ArtistRecommendations.tsx

Lines changed: 38 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,11 @@
1-
import { forwardRef, ReactNode, useCallback, useEffect, useState } from 'react'
1+
import {
2+
Fragment,
3+
forwardRef,
4+
ReactNode,
5+
useCallback,
6+
useEffect,
7+
useState
8+
} from 'react'
29

310
import { useRelatedArtistsUsers } from '@audius/common/api'
411
import { Name, FollowSource, SquareSizes, ID } from '@audius/common/models'
@@ -33,7 +40,10 @@ const messages = {
3340
follow: 'Follow All',
3441
unfollow: 'Unfollow All',
3542
following: 'Following All',
36-
featuring: 'Featuring'
43+
featuring: 'Featuring',
44+
and: 'and',
45+
other: 'other',
46+
others: 'others'
3747
}
3848
const ArtistProfilePictureWrapper = ({
3949
userId,
@@ -136,6 +146,12 @@ export const ArtistRecommendations = forwardRef<
136146
)
137147

138148
const isLoading = !suggestedArtists || suggestedArtists.length === 0
149+
const featuredArtists = suggestedArtists
150+
.filter((artist) => artist.name.trim().length > 0)
151+
.slice(0, 3)
152+
const remainingArtistCount = suggestedArtists.length - featuredArtists.length
153+
const remainingArtistLabel =
154+
remainingArtistCount === 1 ? messages.other : messages.others
139155

140156
const renderMainContent = () => {
141157
if (isLoading) return <LoadingSpinner className={styles.spinner} />
@@ -157,25 +173,26 @@ export const ArtistRecommendations = forwardRef<
157173
</div>
158174
))}
159175
</div>
160-
<div className={cn(styles.contentItem, itemClassName)}>
161-
{`${messages.featuring} `}
162-
{suggestedArtists
163-
.slice(0, 3)
164-
.map<ReactNode>((a, i) => (
165-
<ArtistPopoverWrapper
166-
key={a.user_id}
167-
userId={a.user_id}
168-
handle={a.handle}
169-
name={a.name}
170-
onArtistNameClicked={onArtistNameClicked}
171-
closeParent={onClose}
172-
/>
173-
))
174-
.reduce((prev, curr) => [prev, ', ', curr], '')}
175-
{suggestedArtists.length > 3
176-
? `, and ${suggestedArtists.length - 3} others.`
177-
: ''}
178-
</div>
176+
{featuredArtists.length === 0 ? null : (
177+
<div className={cn(styles.contentItem, itemClassName)}>
178+
{`${messages.featuring} `}
179+
{featuredArtists.map((artist, index) => (
180+
<Fragment key={artist.user_id}>
181+
{index === 0 ? null : ', '}
182+
<ArtistPopoverWrapper
183+
userId={artist.user_id}
184+
handle={artist.handle}
185+
name={artist.name.trim()}
186+
onArtistNameClicked={onArtistNameClicked}
187+
closeParent={onClose}
188+
/>
189+
</Fragment>
190+
))}
191+
{remainingArtistCount > 0
192+
? `, ${messages.and} ${remainingArtistCount} ${remainingArtistLabel}`
193+
: ''}
194+
</div>
195+
)}
179196
</>
180197
)
181198
}

0 commit comments

Comments
 (0)