diff --git a/back/src/app.module.ts b/back/src/app.module.ts index 68493ec..1e633bb 100644 --- a/back/src/app.module.ts +++ b/back/src/app.module.ts @@ -15,6 +15,7 @@ import { AlbumModule } from './album/album.module'; import { SearchModule } from './search/search.module'; import { HistoryModule } from './history/history.module'; import { MailerModule } from '@nestjs-modules/mailer'; +import { ScoresModule } from './scores/scores.module'; @Module({ imports: [ @@ -29,6 +30,7 @@ import { MailerModule } from '@nestjs-modules/mailer'; SearchModule, SettingsModule, HistoryModule, + ScoresModule, MailerModule.forRoot({ transport: process.env.SMTP_TRANSPORT, defaults: { diff --git a/back/src/models/user.ts b/back/src/models/user.ts index e64d3c6..ff7bbe6 100644 --- a/back/src/models/user.ts +++ b/back/src/models/user.ts @@ -11,4 +11,6 @@ export class User { isGuest: boolean; @ApiProperty() partyPlayed: number; + @ApiProperty() + totalScore: number; } diff --git a/back/src/scores/scores.controller.ts b/back/src/scores/scores.controller.ts index 7065958..a833e11 100644 --- a/back/src/scores/scores.controller.ts +++ b/back/src/scores/scores.controller.ts @@ -11,9 +11,8 @@ import { User } from '@prisma/client'; export class ScoresController { constructor(private readonly scoresService: ScoresService) {} - @ApiOkResponse({ description: 'Successfully sent the Top 20 players'}) - @Get('scores/top/20') + @Get('top/20') getTopTwenty(): Promise { return this.scoresService.topTwenty(); } diff --git a/back/src/scores/scores.service.ts b/back/src/scores/scores.service.ts index f2b78f3..c48f229 100644 --- a/back/src/scores/scores.service.ts +++ b/back/src/scores/scores.service.ts @@ -11,7 +11,7 @@ export class ScoresService { async topTwenty(): Promise { return this.prisma.user.findMany({ orderBy: { - partyPlayed: 'desc', + totalScore: 'desc', }, take: 20, }); diff --git a/front/models/User.ts b/front/models/User.ts index 6a66759..6e9db3d 100644 --- a/front/models/User.ts +++ b/front/models/User.ts @@ -18,6 +18,7 @@ export const UserValidator = yup googleID: yup.string().required().nullable(), isGuest: yup.boolean().required(), partyPlayed: yup.number().required(), + totalScore: yup.number().required().nullable(), }) .concat(ModelValidator); @@ -30,6 +31,7 @@ export const UserHandler: ResponseHandler, U premium: false, data: { gamesPlayed: value.partyPlayed as number, + totalScore: value.totalScore as number, xp: 0, createdAt: new Date('2023-04-09T00:00:00.000Z'), avatar: `${API.baseUrl}/users/${value.id}/picture`, @@ -51,6 +53,7 @@ interface User extends Model { interface UserData { gamesPlayed: number; xp: number; + totalScore: number; avatar: string; createdAt: Date; } diff --git a/front/views/LeaderboardView.tsx b/front/views/LeaderboardView.tsx index 0eafcc9..f5167d9 100644 --- a/front/views/LeaderboardView.tsx +++ b/front/views/LeaderboardView.tsx @@ -1,16 +1,21 @@ import { Box, Heading, useBreakpointValue, ScrollView, Text } from 'native-base'; import { View, Image } from 'react-native'; -import { useQuery } from 'react-query'; -import User from '../models/User'; +import { useQuery } from '../Queries'; import API from '../API'; import { Ionicons } from '@expo/vector-icons'; +import { LoadingView } from '../components/Loading'; +import { useNavigation } from '../Navigation'; +import { MedalStar } from 'iconsax-react-native'; type PodiumCardProps = { offset: number; medalColor: string; + userAvatarUrl: string; + userPseudo: string; + userLvl: number; }; -const PodiumCardComponent = ({ offset, medalColor }: PodiumCardProps) => { +const PodiumCardComponent = ({ offset, medalColor, userAvatarUrl, userPseudo, userLvl }: PodiumCardProps) => { return ( { > { borderRadius: 12, }} /> - @@ -55,7 +60,7 @@ const PodiumCardComponent = ({ offset, medalColor }: PodiumCardProps) => { fontWeight: '500', }} > - Momo + {userPseudo} { fontWeight: '500', }} > - 2400 LVL + {userLvl} LVL ); }; -const BoardRowComponent = () => { +type BoardRowProps = { + userAvatarUrl: string; + userPseudo: string; + userLvl: number; + index: number +} + +const BoardRowComponent = ({userAvatarUrl, userPseudo, userLvl, index}: BoardRowProps) => { return ( { > @@ -112,7 +125,7 @@ const BoardRowComponent = () => { fontWeight: '500', }} > - Momo est boutain + {userPseudo} { marginHorizontal: 10, }} > - 200 LVL + { userLvl } LVL { textAlign: 'center', }} > - 8 + { index + 4 } ); }; -const dummyScores = [ - { - id: 1, - }, - { - id: 2, - }, - { - id: 3, - }, - { - id: 4, - }, - { - id: 5, - }, - { - id: 6, - }, - { - id: 7, - }, - { - id: 8, - }, - { - id: 9, - }, -]; - const Leaderboardiew = () => { - // const scoresQuery = useQuery(API.getTopTwentyPlayers()) + const navigation = useNavigation(); + const scoresQuery = useQuery(API.getTopTwentyPlayers()); + + if (scoresQuery.isError) { + navigation.navigate('Error'); + return <>; + } + if (scoresQuery.data === undefined) { + return ; + } + return ( { - - - + + + - {dummyScores.map((comp, index) => ( - + {scoresQuery.data.slice(3).map((comp: any, index: number) => ( + ))}