diff --git a/front/components/ProgressBar.tsx b/front/components/ProgressBar.tsx index bf9ea72..82b24cd 100644 --- a/front/components/ProgressBar.tsx +++ b/front/components/ProgressBar.tsx @@ -1,9 +1,9 @@ import React from 'react'; import { translate } from '../i18n/i18n'; -import { Box, Text, VStack, Progress, Stack, AspectRatio } from 'native-base'; +import { Box, Text, VStack, Progress, Stack } from 'native-base'; import { useNavigation } from '../Navigation'; -import { Image } from 'native-base'; import Card from '../components/Card'; +import UserAvatar from './UserAvatar'; const ProgressBar = ({ xp }: { xp: number }) => { const level = Math.floor(xp / 1000); @@ -15,18 +15,8 @@ const ProgressBar = ({ xp }: { xp: number }) => { return ( nav.navigate('User')}> - - - Profile picture - + + {`${translate('level')} ${level}`} diff --git a/front/components/UserAvatar.tsx b/front/components/UserAvatar.tsx new file mode 100644 index 0000000..8481c1d --- /dev/null +++ b/front/components/UserAvatar.tsx @@ -0,0 +1,24 @@ +import { Avatar } from 'native-base'; +import API from '../API'; +import { useQuery } from '../Queries'; + +const getInitials = (name: string) => { + return name + .split(' ') + .map((n) => n[0]) + .join(''); +}; + +type UserAvatarProps = Pick[0], 'size'>; + +const UserAvatar = ({ size }: UserAvatarProps) => { + const user = useQuery(API.getUserInfo); + + return ( + + {user.data !== undefined && getInitials(user.data.name)} + + ); +}; + +export default UserAvatar; diff --git a/front/models/User.ts b/front/models/User.ts index 49534eb..1f85df2 100644 --- a/front/models/User.ts +++ b/front/models/User.ts @@ -41,7 +41,7 @@ interface User extends Model { interface UserData { gamesPlayed: number; xp: number; - avatar: string | undefined; + avatar: string; createdAt: Date; } diff --git a/front/views/ProfileView.tsx b/front/views/ProfileView.tsx index 892909d..0dd12ad 100644 --- a/front/views/ProfileView.tsx +++ b/front/views/ProfileView.tsx @@ -1,81 +1,11 @@ import React from 'react'; import { Dimensions, View } from 'react-native'; -import { Box, Image, Heading, HStack, Card, Text } from 'native-base'; -import Translate from '../components/Translate'; +import { Box, Image, Heading, HStack } from 'native-base'; import { useNavigation } from '../Navigation'; import TextButton from '../components/TextButton'; - -const UserMedals = () => { - return ( - - - - - - Profile picture - Profile picture - Profile picture - Profile picture - - - ); -}; - -const PlayerStats = () => { - const answer = 'Answer from back'; - - return ( - - - {' '} - {' '} - - - {' '} - {answer}{' '} - - - {' '} - {answer}{' '} - - - {' '} - {answer}{' '} - - - {' '} - {answer}{' '} - - - ); -}; +import UserAvatar from '../components/UserAvatar'; const ProfilePictureBannerAndLevel = () => { - const profilePic = 'https://wallpaperaccess.com/full/317501.jpg'; const username = 'Username'; const level = '1'; @@ -93,19 +23,13 @@ const ProfilePictureBannerAndLevel = () => { size="lg" style={{ height: imageHeight, width: imageWidth, zIndex: 0, opacity: 0.5 }} /> - - Profile picture - + + + {username} Level : {level} - + ); }; @@ -116,8 +40,6 @@ const ProfileView = () => { return ( - - navigation.navigate('Settings', { screen: 'profile' })} diff --git a/front/views/settings/SettingsProfileView.tsx b/front/views/settings/SettingsProfileView.tsx index a2ff6a0..7d072d3 100644 --- a/front/views/settings/SettingsProfileView.tsx +++ b/front/views/settings/SettingsProfileView.tsx @@ -2,19 +2,13 @@ import API from '../../API'; import { useDispatch } from 'react-redux'; import { unsetAccessToken } from '../../state/UserSlice'; import React from 'react'; -import { Column, Text, Button, Box, Flex, Center, Heading, Avatar, Popover } from 'native-base'; +import { Column, Text, Button, Box, Flex, Center, Heading, Popover } from 'native-base'; import TextButton from '../../components/TextButton'; import { LoadingView } from '../../components/Loading'; import ElementList from '../../components/GtkUI/ElementList'; import { translate } from '../../i18n/i18n'; import { useQuery } from '../../Queries'; - -const getInitials = (name: string) => { - return name - .split(' ') - .map((n) => n[0]) - .join(''); -}; +import UserAvatar from '../../components/UserAvatar'; // Too painful to infer the settings-only, typed navigator. Gave up // eslint-disable-next-line @typescript-eslint/no-explicit-any @@ -41,9 +35,7 @@ const ProfileSettings = ({ navigation }: { navigation: any }) => { }} >
- - {getInitials(user.name)} - +