From f3a2f5ee23e23be53217da9d8875609576bdb5f9 Mon Sep 17 00:00:00 2001 From: moolcoov Date: Mon, 3 Mar 2025 20:35:47 +0300 Subject: [PATCH 1/2] feat: user --- .../Profile/components/user-stat-block.tsx | 14 +++++++ services/frontend/src/pages/Profile/index.tsx | 6 +-- .../Profile/widgets/user-achievements.tsx | 2 +- .../src/pages/Profile/widgets/user-info.tsx | 2 +- .../src/pages/Profile/widgets/user-stats.tsx | 38 +++++++++++++++++-- services/frontend/src/shared/api/user.ts | 6 ++- services/frontend/src/shared/types/user.ts | 5 +++ 7 files changed, 64 insertions(+), 9 deletions(-) create mode 100644 services/frontend/src/pages/Profile/components/user-stat-block.tsx diff --git a/services/frontend/src/pages/Profile/components/user-stat-block.tsx b/services/frontend/src/pages/Profile/components/user-stat-block.tsx new file mode 100644 index 0000000..3fec3af --- /dev/null +++ b/services/frontend/src/pages/Profile/components/user-stat-block.tsx @@ -0,0 +1,14 @@ +export const UserStatBlock = ({ + value, + description, +}: { + value: number; + description: string; +}) => { + return ( +
+

{value}

+

{description}

+
+ ); +}; diff --git a/services/frontend/src/pages/Profile/index.tsx b/services/frontend/src/pages/Profile/index.tsx index 75cd2ff..d9b61c1 100644 --- a/services/frontend/src/pages/Profile/index.tsx +++ b/services/frontend/src/pages/Profile/index.tsx @@ -1,6 +1,6 @@ import { UserInfo } from "./widgets/user-info"; import { UserAchievements } from "./widgets/user-achievements"; -import { UserStats } from "./widgets/user-stats"; +import { UserStatsSections } from "./widgets/user-stats"; import { useQuery } from "@tanstack/react-query"; import { getCurrentUser } from "@/shared/api/user"; import { Loading } from "@/components/ui/loading"; @@ -25,11 +25,11 @@ const ProfilePage = () => { return (
-
+
- +
); }; diff --git a/services/frontend/src/pages/Profile/widgets/user-achievements.tsx b/services/frontend/src/pages/Profile/widgets/user-achievements.tsx index decd815..8231fbf 100644 --- a/services/frontend/src/pages/Profile/widgets/user-achievements.tsx +++ b/services/frontend/src/pages/Profile/widgets/user-achievements.tsx @@ -11,7 +11,7 @@ export const UserAchievements = ({

Достижения

{achievements && ( -
+
{achievements.map((a) => ( diff --git a/services/frontend/src/pages/Profile/widgets/user-info.tsx b/services/frontend/src/pages/Profile/widgets/user-info.tsx index 3b3b927..808619b 100644 --- a/services/frontend/src/pages/Profile/widgets/user-info.tsx +++ b/services/frontend/src/pages/Profile/widgets/user-info.tsx @@ -2,7 +2,7 @@ import { User } from "@/shared/types/user"; export const UserInfo = ({ user }: { user: User }) => { return ( -
+
{user.avatar && (
{ +import { Loading } from "@/components/ui/loading"; +import { UserStatBlock } from "../components/user-stat-block"; +import { getCurrentUserStats } from "@/shared/api/user"; +import { useQuery } from "@tanstack/react-query"; + +export const UserStatsSections = () => { + const { data: stats, isLoading } = useQuery({ + queryKey: ["user-stats"], + queryFn: getCurrentUserStats, + }); + return ( -
+

Аналитика

-
+ {isLoading ? ( +
+ +
+ ) : stats ? ( +
+ + +
+ ) : ( +
+

+ Что-то пошло не так 😔 +

+
+ )} +
); }; diff --git a/services/frontend/src/shared/api/user.ts b/services/frontend/src/shared/api/user.ts index 84b000d..7640390 100644 --- a/services/frontend/src/shared/api/user.ts +++ b/services/frontend/src/shared/api/user.ts @@ -1,6 +1,10 @@ import { userFetch } from "."; -import { User } from "../types/user"; +import { User, UserStats } from "../types/user"; export const getCurrentUser = async () => { return await userFetch("/me"); }; + +export const getCurrentUserStats = async () => { + return await userFetch("/me/stat"); +}; diff --git a/services/frontend/src/shared/types/user.ts b/services/frontend/src/shared/types/user.ts index 650c8d8..b9e927f 100644 --- a/services/frontend/src/shared/types/user.ts +++ b/services/frontend/src/shared/types/user.ts @@ -12,3 +12,8 @@ export interface Achievement { received_at: Date; icon?: string; } + +export interface UserStats { + total_attempts: number; + solved_tasks: number; +} From 2e0ea88db559b328abc0262c81728d449ba196f9 Mon Sep 17 00:00:00 2001 From: rngsurrounded Date: Tue, 4 Mar 2025 02:39:14 +0900 Subject: [PATCH 2/2] results rework --- .../CompetitionResultModal/index.tsx | 56 +++++++++++++++++-- .../frontend/src/pages/Competition/index.tsx | 4 +- 2 files changed, 52 insertions(+), 8 deletions(-) diff --git a/services/frontend/src/pages/Competition/components/CompetitionResultModal/index.tsx b/services/frontend/src/pages/Competition/components/CompetitionResultModal/index.tsx index 565354e..b691e77 100644 --- a/services/frontend/src/pages/Competition/components/CompetitionResultModal/index.tsx +++ b/services/frontend/src/pages/Competition/components/CompetitionResultModal/index.tsx @@ -1,3 +1,4 @@ +// src/components/competition/CompetitionResultsModal.tsx import React from 'react'; import { Dialog, @@ -33,13 +34,58 @@ export const CompetitionResultsModal: React.FC = ( }) => { const renderResultValue = (result: number, maxPoints: number) => { if (result === -1) { - return На проверке; + return ( + + На проверке + + ); } else if (result === -2) { - return Нет ответа; + return ( + + Нет ответа + + ); + } else if (result === 0) { + return ( + + Неверно (0/{maxPoints}) + + ); + } else if (result < maxPoints) { + return ( + + Частично верно ({result}/{maxPoints}) + + ); } else { return ( - - Зачтено {result}/{maxPoints} баллов + + Верно ({result}/{maxPoints}) ); } @@ -71,7 +117,7 @@ export const CompetitionResultsModal: React.FC = ( className="flex flex-col md:flex-row justify-between items-start md:items-center p-4 bg-gray-50 rounded-lg border" >
{result.task_name}
-
+
{renderResultValue(result.result, result.max_points)}
diff --git a/services/frontend/src/pages/Competition/index.tsx b/services/frontend/src/pages/Competition/index.tsx index 6571c4f..4cf4911 100644 --- a/services/frontend/src/pages/Competition/index.tsx +++ b/services/frontend/src/pages/Competition/index.tsx @@ -93,7 +93,6 @@ const CompetitionPage = () => { return now < startDate; }; - // Check if competition has ended const isCompetitionEnded = () => { if (!competition?.end_date) return false; @@ -212,7 +211,6 @@ const CompetitionPage = () => {