* LeaderboardView init * back scores handling * blah * add score controller * commit score on end of play * front and back fix * podium component * push the button * ill be baaack * flex css thing * pretty * migration leaderboard * feat(leaderboard): wip * feat(leaderboard): pretty * feat(leaderboard): i might be dumb * fix(leaderboard): misuse of nullable() for totalScore User validator
40 lines
1.0 KiB
TypeScript
40 lines
1.0 KiB
TypeScript
import { Avatar } from 'native-base';
|
|
import API from '../API';
|
|
import { useQuery } from '../Queries';
|
|
import { useMemo } from 'react';
|
|
|
|
export const getInitials = (name: string) => {
|
|
return name
|
|
.split(' ')
|
|
.map((n) => n[0])
|
|
.join('');
|
|
};
|
|
|
|
type UserAvatarProps = Pick<Parameters<typeof Avatar>[0], 'size'>;
|
|
|
|
const UserAvatar = ({ size = 'md' }: UserAvatarProps) => {
|
|
const user = useQuery(API.getUserInfo);
|
|
const avatarUrl = useMemo(() => {
|
|
if (!user.data) {
|
|
return null;
|
|
}
|
|
// NOTE: We do this to avoid parsing URL with `new URL`, which is not compatible with related path
|
|
// (which is used for production, on web)
|
|
return `${user.data.data.avatar}?updatedAt=${user.dataUpdatedAt.toString()}`;
|
|
}, [user.data]);
|
|
|
|
return (
|
|
<Avatar
|
|
borderRadius={12}
|
|
size={size}
|
|
_image={{ borderRadius: 12 }}
|
|
source={avatarUrl ? { uri: avatarUrl.toString() } : undefined}
|
|
style={{ zIndex: 0 }}
|
|
>
|
|
{user.data !== undefined && getInitials(user.data.name)}
|
|
</Avatar>
|
|
);
|
|
};
|
|
|
|
export default UserAvatar;
|