Skip to content

Commit

Permalink
Update collection list id flow to add the create tile (#3591)
Browse files Browse the repository at this point in the history
  • Loading branch information
Kyle-Shanks authored Jun 14, 2023
1 parent dc15518 commit fc7541b
Showing 1 changed file with 37 additions and 13 deletions.
50 changes: 37 additions & 13 deletions packages/mobile/src/components/collection-list/CollectionList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,21 +18,26 @@ type IDCardListItem = {
type IDListProps = Omit<CardListProps<IDCardListItem>, 'data' | 'renderItem'>
type CreateCard = { _create: boolean }

// Props to show and setup tile for creating new playlists
type CreateCollectionTileProps = {
showCreatePlaylistTile?: boolean
createPlaylistSource?: CreatePlaylistSource | null
createPlaylistTrackId?: ID | null
createPlaylistCallback?: () => void
}

type FullCollectionListProps = {
collection?: Collection[]
/** Optional mapping of collection ids to the number that should be shown as the # of tracks in the collection's info card. Added this because im offline mode, the number of tracks downloaded may not yet match the actual number of tracks in the collection. */
collectionIdsToNumTracks?: Record<number, number>
renderItem?: ListRenderItem<Collection | CreateCard> | null
// Props to show and setup tile for creating new playlists
showCreatePlaylistTile?: boolean
createPlaylistSource?: CreatePlaylistSource | null
createPlaylistTrackId?: ID | null
createPlaylistCallback?: () => void
} & FullListProps
} & FullListProps &
CreateCollectionTileProps

type CollectionIdListProps = {
collectionIds: ID[]
} & IDListProps
} & IDListProps &
CreateCollectionTileProps

type CollectionListProps = FullCollectionListProps | CollectionIdListProps

Expand Down Expand Up @@ -91,22 +96,41 @@ function isIdListProps(
}

const CollectionIDList = (props: CollectionIdListProps) => {
const { collectionIds, ...other } = props
const {
collectionIds,
showCreatePlaylistTile = false,
createPlaylistSource = CreatePlaylistSource.FAVORITES_PAGE,
createPlaylistTrackId,
createPlaylistCallback,
...other
} = props

const renderCard = useCallback(
({ item }: { item: IDCardListItem }) => (
<CollectionCard collectionId={item.id} />
),
[]
({ item }: { item: IDCardListItem | CreateCard }) =>
'_create' in item ? (
<AddCollectionCard
source={createPlaylistSource!}
sourceTrackId={createPlaylistTrackId}
onCreate={createPlaylistCallback}
/>
) : (
<CollectionCard collectionId={item.id} />
),
[createPlaylistCallback, createPlaylistSource, createPlaylistTrackId]
)

const idList: IDCardListItem[] = useMemo(
() => collectionIds.map((id) => ({ id })),
[collectionIds]
)

const updatedList = showCreatePlaylistTile
? [{ _create: true }, ...idList]
: idList

return (
<CardList
data={idList}
data={updatedList}
renderItem={renderCard}
LoadingCardComponent={CollectionCardSkeleton}
{...other}
Expand Down

0 comments on commit fc7541b

Please sign in to comment.