-
Notifications
You must be signed in to change notification settings - Fork 111
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
1 parent
5bb451a
commit ea7e3b1
Showing
17 changed files
with
486 additions
and
38 deletions.
There are no files selected for viewing
This file contains 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,25 @@ | ||
import { createApi } from 'audius-query' | ||
import { ID } from 'models/Identifiers' | ||
import { Nullable } from 'utils/typeUtils' | ||
|
||
type GetFavoritedTrackListArgs = { | ||
currentUserId: Nullable<ID> | ||
limit?: number | ||
} | ||
|
||
const favoritesApi = createApi({ | ||
reducerPath: 'favoritesApi', | ||
endpoints: { | ||
getFavoritedTrackList: { | ||
fetch: async (args: GetFavoritedTrackListArgs, { apiClient }) => { | ||
const { currentUserId, limit = 10000 } = args | ||
if (!currentUserId) return null | ||
return await apiClient.getFavorites({ currentUserId, limit }) | ||
}, | ||
options: {} | ||
} | ||
} | ||
}) | ||
|
||
export const { useGetFavoritedTrackList } = favoritesApi.hooks | ||
export const favoritesApiReducer = favoritesApi.reducer |
This file contains 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
This file contains 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
This file contains 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,31 @@ | ||
import { useMemo } from 'react' | ||
|
||
import { sampleSize } from 'lodash' | ||
import { useSelector } from 'react-redux' | ||
|
||
import { getUserId } from 'store/account/selectors' | ||
|
||
import { useGetFavoritedTrackList } from './favorites' | ||
import { useGetTracksByIds } from './track' | ||
|
||
export const useGetSuggestedTracks = () => { | ||
const currentUserId = useSelector(getUserId) | ||
const { data: favoritedTracks } = useGetFavoritedTrackList( | ||
{ currentUserId }, | ||
{ disabled: !currentUserId } | ||
) | ||
|
||
const favoritedTracksSample = useMemo(() => { | ||
return sampleSize(favoritedTracks, 5) | ||
}, [favoritedTracks]) | ||
|
||
return useGetTracksByIds( | ||
{ | ||
currentUserId, | ||
ids: favoritedTracksSample?.map((favorite) => favorite.save_item_id) | ||
}, | ||
{ | ||
disabled: !currentUserId || favoritedTracksSample.length === 0 | ||
} | ||
) | ||
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
136 changes: 136 additions & 0 deletions
136
packages/mobile/src/components/suggested-tracks/SuggestedTracks.tsx
This file contains 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,136 @@ | ||
import type { UserTrackMetadata } from '@audius/common' | ||
import { SquareSizes, useGetSuggestedTracks } from '@audius/common' | ||
import { View } from 'react-native' | ||
|
||
import IconRefresh from 'app/assets/images/iconRefresh.svg' | ||
import { Button, Divider, Text, TextButton, Tile } from 'app/components/core' | ||
import { makeStyles } from 'app/styles' | ||
|
||
import { TrackImage } from '../image/TrackImage' | ||
import { UserBadges } from '../user-badges' | ||
|
||
const messages = { | ||
title: 'Add some tracks', | ||
description: | ||
'Placeholder copy: dependent on backend logic and what we decide to do with this new feature.', | ||
addTrack: 'Add', | ||
refresh: 'Refresh' | ||
} | ||
|
||
const useStyles = makeStyles(({ spacing, typography, palette }) => ({ | ||
root: { marginBottom: spacing(12) }, | ||
heading: { | ||
gap: spacing(2), | ||
padding: spacing(4) | ||
}, | ||
suggestedTrack: { | ||
flexDirection: 'row', | ||
alignItems: 'center', | ||
padding: spacing(4), | ||
gap: spacing(3) | ||
}, | ||
trackDetails: { | ||
flexDirection: 'row', | ||
alignItems: 'center', | ||
gap: spacing(3), | ||
flex: 1 | ||
}, | ||
trackInfo: { | ||
gap: 2, | ||
flex: 1 | ||
}, | ||
trackImage: { | ||
height: spacing(10), | ||
width: spacing(10), | ||
borderRadius: 2 | ||
}, | ||
artistName: { | ||
fontSize: typography.fontSize.small, | ||
fontFamily: typography.fontByWeight.medium, | ||
color: palette.neutralLight4 | ||
}, | ||
refreshButton: { | ||
marginVertical: spacing(4), | ||
alignSelf: 'center' | ||
}, | ||
buttonText: { textTransform: 'none', marginHorizontal: spacing(1) } | ||
})) | ||
|
||
type SuggestedTrackProps = { | ||
track: UserTrackMetadata | ||
} | ||
|
||
const SuggestedTrack = (props: SuggestedTrackProps) => { | ||
const { track } = props | ||
const { title, user } = track | ||
const styles = useStyles() | ||
|
||
return ( | ||
<View style={styles.suggestedTrack}> | ||
<View style={styles.trackDetails}> | ||
<TrackImage | ||
track={track} | ||
size={SquareSizes.SIZE_150_BY_150} | ||
style={styles.trackImage} | ||
/> | ||
<View style={styles.trackInfo}> | ||
<Text | ||
numberOfLines={1} | ||
ellipsizeMode='tail' | ||
fontSize='small' | ||
weight='demiBold' | ||
> | ||
{title} | ||
</Text> | ||
<UserBadges user={user} nameStyle={styles.artistName} /> | ||
</View> | ||
</View> | ||
<View> | ||
<Button | ||
variant='common' | ||
title={messages.addTrack} | ||
size='small' | ||
styles={{ text: styles.buttonText }} | ||
/> | ||
</View> | ||
</View> | ||
) | ||
} | ||
|
||
export const SuggestedTracks = () => { | ||
const styles = useStyles() | ||
const { data: suggestedTracks } = useGetSuggestedTracks() | ||
|
||
return ( | ||
<Tile style={styles.root}> | ||
<View style={styles.heading}> | ||
<Text fontSize='large' weight='heavy' textTransform='uppercase'> | ||
{messages.title} | ||
</Text> | ||
<Text fontSize='medium' weight='medium'> | ||
{messages.description} | ||
</Text> | ||
</View> | ||
<View> | ||
<Divider /> | ||
{suggestedTracks?.map((suggestedTrack) => ( | ||
<> | ||
<SuggestedTrack | ||
key={suggestedTrack.track_id} | ||
track={suggestedTrack} | ||
/> | ||
<Divider /> | ||
</> | ||
))} | ||
</View> | ||
<TextButton | ||
variant='neutralLight4' | ||
icon={IconRefresh} | ||
iconPosition='left' | ||
title={messages.refresh} | ||
TextProps={{ weight: 'bold' }} | ||
style={styles.refreshButton} | ||
/> | ||
</Tile> | ||
) | ||
} |
This file contains 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 * from './SuggestedTracks' |
This file contains 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
This file contains 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,5 +1,6 @@ | ||
:root, | ||
root { | ||
--grow: perspective(1px) scale3d(1.04, 1.04, 1.04); | ||
--grow-large: perspective(1px) scale3d(1.1, 1.1, 1.1); | ||
--shrink: scale(0.95); | ||
} |
This file contains 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,4 +1,8 @@ | ||
.root { | ||
.default { | ||
border-color: var(--neutral-light-5); | ||
} | ||
|
||
.subdued { | ||
border-color: var(--neutral-light-8); | ||
} | ||
|
||
|
This file contains 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
Oops, something went wrong.