Skip to content
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

[C-4421] Add mobile UserCard and skeletons #8696

Merged
merged 4 commits into from
Jun 5, 2024
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
@@ -1,51 +1,25 @@
import { View } from 'react-native'
import { Divider, Flex, Paper } from '@audius/harmony-native'

import { Tile } from 'app/components/core'
import { Skeleton, StaticSkeleton } from 'app/components/skeleton'
import { makeStyles } from 'app/styles'

const useStyles = makeStyles(({ spacing }) => ({
root: {
height: 218
},
cardContent: {
paddingHorizontal: spacing(2)
},
imageContainer: {
paddingTop: spacing(2),
paddingHorizontal: spacing(1)
},
image: {
height: 152,
width: '100%',
borderRadius: 6
},
textContainer: {
paddingVertical: spacing(1),
alignItems: 'center'
},
title: {
height: 16,
width: 75,
marginVertical: spacing(1)
},
stats: {
height: 14,
width: 150
}
}))
Comment on lines -7 to -36
Copy link
Contributor

Choose a reason for hiding this comment

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

goodbye styles

import { Skeleton } from '../skeleton'

export const CollectionCardSkeleton = () => {
const styles = useStyles()
return (
<Tile styles={{ tile: styles.root, content: styles.cardContent }}>
<View style={styles.imageContainer}>
<Skeleton style={styles.image} />
</View>
<View style={styles.textContainer}>
<StaticSkeleton style={styles.title} />
<StaticSkeleton style={styles.stats} />
</View>
</Tile>
<Paper border='default'>
<Flex p='s' gap='s' alignItems='center'>
<Skeleton style={{ width: '100%', aspectRatio: 1 }} />
<Skeleton height={20} width={150} style={{ marginBottom: 6 }} />
<Skeleton height={18} width={100} style={{ marginBottom: 4 }} />
</Flex>
<Divider orientation='horizontal' />
<Flex
pv='s'
backgroundColor='surface1'
alignItems='center'
borderBottomLeftRadius='m'
borderBottomRightRadius='m'
>
<Skeleton height={16} width={100} />
</Flex>
</Paper>
)
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ import {
import LinearGradient from 'react-native-linear-gradient'
import { useDispatch, useSelector } from 'react-redux'

import type { ProfileListProps } from 'app/components/profile-list'
import { ProfileCard, ProfileList } from 'app/components/profile-list'
import type { UserListProps } from 'app/components/user-list'
import { ProfileCard, UserList } from 'app/components/user-list'
import type { AppState } from 'app/store'
import { makeStyles } from 'app/styles'
import { useThemeColors } from 'app/utils/theme'
Expand All @@ -24,7 +24,7 @@ const useStyles = makeStyles(({ palette }) => ({
}
}))

type SuggestedArtistsListProps = Partial<ProfileListProps>
type SuggestedArtistsListProps = Partial<UserListProps>

export const SuggestedArtistsList = (props: SuggestedArtistsListProps) => {
const styles = useStyles()
Expand Down Expand Up @@ -59,7 +59,7 @@ export const SuggestedArtistsList = (props: SuggestedArtistsListProps) => {
)

return (
<ProfileList
<UserList
profiles={suggestedArtists}
renderItem={({ item: artist }) => {
const { user_id } = artist
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ type ProfileCardProps = Partial<Omit<BaseProfileCardProps, 'onPress'>> & {
onPress?: (id: ID) => void
}

// @deprecated -- use UserCard instead
export const ProfileCard = (props: ProfileCardProps) => {
const { profile, preventNavigation, onPress, ...other } = props
const { user_id, handle } = profile
Expand Down
81 changes: 81 additions & 0 deletions packages/mobile/src/components/user-list/UserCard.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
import { useCallback } from 'react'

import { SquareSizes, type ID } from '@audius/common/models'
import { cacheUsersSelectors } from '@audius/common/store'
import { formatCount, pluralize } from '@audius/common/utils'
import type { GestureResponderEvent } from 'react-native'
import { useSelector } from 'react-redux'

import {
Avatar,
Divider,
Flex,
Paper,
Text,
type PaperProps
} from '@audius/harmony-native'
import { useNavigation } from 'app/hooks/useNavigation'

import { useProfilePicture } from '../image/UserImage'
import { UserLink } from '../user-link'

const { getUser } = cacheUsersSelectors

const messages = {
follower: 'Follower'
}

type UserCardProps = PaperProps & {
userId: ID
noNavigation?: boolean
}
export const UserCard = (props: UserCardProps) => {
const { userId, onPress, noNavigation, ...other } = props

const user = useSelector((state) => getUser(state, { id: userId }))
const navigation = useNavigation()

const handlePress = useCallback(
(e: GestureResponderEvent) => {
onPress?.(e)
if (noNavigation) return
navigation.navigate('Profile', { id: userId })
Copy link
Contributor

Choose a reason for hiding this comment

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

do we have route constants for this? (e.g. navigate(PROFILE_PAGE, ...)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

it types so i just use that, but we could prob use constants moving forward?

},
[onPress, noNavigation, navigation, userId]
)

const { source, handleError } = useProfilePicture(
userId,
SquareSizes.SIZE_480_BY_480
)

if (user === null) return null

const { handle, follower_count } = user

return (
<Paper border='default' onPress={handlePress} {...other}>
<Avatar source={source} onError={handleError} aria-hidden p='m' pb='s' />
<Flex ph='l' pb='s' gap='xs'>
<UserLink userId={userId} textVariant='title' />
<Text ellipses textAlign='center'>
@{handle}
</Text>
</Flex>
<Divider />
<Flex
pv='s'
backgroundColor='surface1'
alignItems='center'
borderBottomLeftRadius='m'
borderBottomRightRadius='m'
>
{/* Ensures correct footer height */}
<Text size='s' strength='strong' style={{ lineHeight: 16 }}>
Copy link
Contributor

Choose a reason for hiding this comment

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

I assume this line height is a corner case where our standard styles don't line up right?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yeah, i have a comment in collectioncard, but ill add here as well

{formatCount(follower_count)}{' '}
{pluralize(messages.follower, follower_count)}
</Text>
</Flex>
</Paper>
)
}
31 changes: 31 additions & 0 deletions packages/mobile/src/components/user-list/UserCardSkeleton.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { Box, Divider, Flex, Paper } from '@audius/harmony-native'

import { Skeleton } from '../skeleton'

export const UserCardSkeleton = () => {
return (
<Paper border='default'>
<Box p='m' pb='s'>
<Skeleton
style={{ width: '100%', aspectRatio: 1, borderRadius: 1000 }}
/>
</Box>
<Flex ph='l' pt='xs' pb='m' gap='xs' alignItems='center'>
{/* marginBottom is simulating line-height */}
<Skeleton height={18} width={150} style={{ marginBottom: 6 }} />
Copy link
Contributor

Choose a reason for hiding this comment

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

kinda weird to have margin and also flex gap

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yeah super weird, its trying to mimic line height fwiw, can add a comment

<Skeleton height={16} width={100} />
</Flex>
<Divider />
<Flex
pv='s'
backgroundColor='surface1'
alignItems='center'
borderBottomLeftRadius='m'
borderBottomRightRadius='m'
>
{/* marginBottom is simulating line-height */}
<Skeleton height={16} width={100} style={{ marginBottom: 2 }} />
</Flex>
</Paper>
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,28 @@ import type { ID, User } from '@audius/common/models'
import type { CardListProps } from 'app/components/core'
import { CardList } from 'app/components/core'

import { ProfileCard } from './ProfileCard'
import { ProfileCardSkeleton } from './ProfileCardSkeleton'
import { UserCard } from './UserCard'
import { UserCardSkeleton } from './UserCardSkeleton'

type ListProps = Omit<CardListProps<User>, 'data'>

export type ProfileListProps = {
export type UserListProps = {
profiles: User[] | undefined
onCardPress?: (user_id: ID) => void
} & Partial<ListProps>

export const ProfileList = (props: ProfileListProps) => {
export const UserList = (props: UserListProps) => {
const { profiles, onCardPress, ...other } = props
return (
<CardList
data={profiles}
renderItem={({ item }) => (
<ProfileCard profile={item} onPress={onCardPress} />
<UserCard
userId={item.user_id}
onPress={() => onCardPress?.(item.user_id)}
/>
)}
LoadingCardComponent={ProfileCardSkeleton}
LoadingCardComponent={UserCardSkeleton}
{...other}
/>
)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
export * from './ProfileList'
export * from './UserList'
export * from './ProfileCard'
43 changes: 22 additions & 21 deletions packages/mobile/src/harmony-native/components/Avatar/Avatar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,8 @@ import { css } from '@emotion/native'
import { View } from 'react-native'
import type { SetRequired } from 'type-fest'

import { useTheme } from '@audius/harmony-native'
import type { MarginProps } from 'app/harmony-native/utils/styleProps'
import { useMargin } from 'app/harmony-native/utils/styleProps'
import type { BoxProps } from '@audius/harmony-native'
import { Box, useTheme } from '@audius/harmony-native'

import type { FastImageProps } from '../FastImage/FastImage'
import { FastImage } from '../FastImage/FastImage'
Expand All @@ -16,11 +15,14 @@ type TweakedFastImageProps = Omit<FastImageProps, 'priority'> &
Partial<PickRename<FastImageProps, 'priority', 'imagePriority'>>

export type AvatarProps = Omit<HarmonyAvatarProps, 'src'> &
SetRequired<TweakedFastImageProps, 'accessibilityLabel'> &
MarginProps
(
| SetRequired<TweakedFastImageProps, 'accessibilityLabel'>
| (TweakedFastImageProps & { 'aria-hidden'?: true })
) &
BoxProps
Copy link
Contributor

Choose a reason for hiding this comment

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

🔥


const sizeMap = {
auto: '100%' as const,
auto: undefined,
small: 24,
medium: 40,
large: 72,
Expand All @@ -40,7 +42,7 @@ export const Avatar = (props: AvatarProps) => {
const {
children,
source,
size = 'medium',
size = 'auto',
strokeWidth = 'default',
variant = 'default',
style,
Expand All @@ -49,8 +51,6 @@ export const Avatar = (props: AvatarProps) => {

const { color, shadows } = useTheme()

const margin = useMargin(other)

const borderRadius = 9999

const rootCss = css({
Expand All @@ -65,24 +65,25 @@ export const Avatar = (props: AvatarProps) => {
})

const imageCss = css({
flex: 1,
width: '100%',
aspectRatio: 1,
alignItems: 'center',
justifyContent: 'center',
overflow: 'hidden',
borderRadius
})

return (
<View style={[rootCss, margin, style]}>
{source !== undefined ? (
<FastImage style={imageCss} source={source} {...other}>
{children}
</FastImage>
) : (
<View style={imageCss} {...other}>
{children}
</View>
)}
</View>
<Box {...other}>
<Box style={[rootCss, style]}>
{source !== undefined ? (
<FastImage style={imageCss} source={source}>
{children}
</FastImage>
) : (
<View style={imageCss}>{children}</View>
)}
</Box>
</Box>
)
}
Loading