-
Notifications
You must be signed in to change notification settings - Fork 111
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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 | ||
} | ||
})) | ||
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 |
---|---|---|
@@ -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 }) | ||
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. do we have route constants for this? (e.g. 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. 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 }}> | ||
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. I assume this line height is a corner case where our standard styles don't line up right? 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. yeah, i have a comment in collectioncard, but ill add here as well |
||
{formatCount(follower_count)}{' '} | ||
{pluralize(messages.follower, follower_count)} | ||
</Text> | ||
</Flex> | ||
</Paper> | ||
) | ||
} |
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 }} /> | ||
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. kinda weird to have margin and also flex gap 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. 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 |
---|---|---|
@@ -1,2 +1,2 @@ | ||
export * from './ProfileList' | ||
export * from './UserList' | ||
export * from './ProfileCard' |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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' | ||
|
@@ -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 | ||
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. 🔥 |
||
|
||
const sizeMap = { | ||
auto: '100%' as const, | ||
auto: undefined, | ||
small: 24, | ||
medium: 40, | ||
large: 72, | ||
|
@@ -40,7 +42,7 @@ export const Avatar = (props: AvatarProps) => { | |
const { | ||
children, | ||
source, | ||
size = 'medium', | ||
size = 'auto', | ||
strokeWidth = 'default', | ||
variant = 'default', | ||
style, | ||
|
@@ -49,8 +51,6 @@ export const Avatar = (props: AvatarProps) => { | |
|
||
const { color, shadows } = useTheme() | ||
|
||
const margin = useMargin(other) | ||
|
||
const borderRadius = 9999 | ||
|
||
const rootCss = css({ | ||
|
@@ -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> | ||
) | ||
} |
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.
goodbye styles