From 4202ad5776110de8d38d7ac446255b13fd71df27 Mon Sep 17 00:00:00 2001 From: moolcoov Date: Sat, 1 Mar 2025 13:39:47 +0300 Subject: [PATCH] fix: competition page --- services/frontend/src/App.tsx | 16 +-- .../frontend/src/components/ui/button.tsx | 5 +- .../frontend/src/pages/Competition/index.tsx | 53 +++++++++ .../pages/CompetitionPreviewPage/index.tsx | 108 ------------------ .../index.tsx | 3 - .../components/CompetitionCard/index.tsx | 0 .../components/CompetitionSkeleton/index.tsx | 0 .../components/CompetitionTag/index.tsx | 0 .../index.tsx | 0 .../modules/CompetitionGrid/index.tsx | 5 +- .../types.ts | 0 services/frontend/src/shared/mocks/mocks.ts | 7 +- 12 files changed, 72 insertions(+), 125 deletions(-) create mode 100644 services/frontend/src/pages/Competition/index.tsx delete mode 100644 services/frontend/src/pages/CompetitionPreviewPage/index.tsx rename services/frontend/src/pages/{CompetitionRunnerPage => CompetitionSession}/index.tsx (98%) rename services/frontend/src/pages/{CompetitionsPage => Competitions}/components/CompetitionCard/index.tsx (100%) rename services/frontend/src/pages/{CompetitionsPage => Competitions}/components/CompetitionSkeleton/index.tsx (100%) rename services/frontend/src/pages/{CompetitionsPage => Competitions}/components/CompetitionTag/index.tsx (100%) rename services/frontend/src/pages/{CompetitionsPage => Competitions}/index.tsx (100%) rename services/frontend/src/pages/{CompetitionsPage => Competitions}/modules/CompetitionGrid/index.tsx (67%) rename services/frontend/src/pages/{CompetitionsPage => Competitions}/types.ts (100%) diff --git a/services/frontend/src/App.tsx b/services/frontend/src/App.tsx index d7bd1eb..9c7f555 100644 --- a/services/frontend/src/App.tsx +++ b/services/frontend/src/App.tsx @@ -1,8 +1,8 @@ import { Routes, Route } from "react-router"; import "./styles/globals.css"; -import CompetitionsPage from "./pages/CompetitionsPage"; -import CompetitionPreviewPage from "./pages/CompetitionPreviewPage"; -import CompetitionRunnerPage from "./pages/CompetitionRunnerPage"; +import CompetitionsPage from "./pages/Competitions"; +import CompetitionPage from "./pages/Competition"; +import CompetitionRunnerPage from "./pages/CompetitionSession"; import { NavbarLayout } from "./widgets/navbar-layout"; const App = () => { @@ -10,12 +10,12 @@ const App = () => { }> } /> + } /> + } + /> - } /> - } - /> ); }; diff --git a/services/frontend/src/components/ui/button.tsx b/services/frontend/src/components/ui/button.tsx index 49dcad9..7558e04 100644 --- a/services/frontend/src/components/ui/button.tsx +++ b/services/frontend/src/components/ui/button.tsx @@ -9,8 +9,7 @@ const buttonVariants = cva( { variants: { variant: { - default: - "bg-primary text-primary-foreground shadow-xs hover:bg-primary/90", + default: "bg-primary text-foreground hover:bg-primary/80", destructive: "bg-destructive text-white shadow-xs hover:bg-destructive/90 focus-visible:ring-destructive/20 dark:focus-visible:ring-destructive/40", outline: @@ -21,7 +20,7 @@ const buttonVariants = cva( link: "text-primary underline-offset-4 hover:underline", }, size: { - default: "h-9 px-4 py-2 has-[>svg]:px-3", + default: "h-12 px-5 py-3 has-[>svg]:px-3 text-lg font-semibold", sm: "h-8 rounded-md gap-1.5 px-3 has-[>svg]:px-2.5", lg: "h-10 rounded-md px-6 has-[>svg]:px-4", icon: "size-9", diff --git a/services/frontend/src/pages/Competition/index.tsx b/services/frontend/src/pages/Competition/index.tsx new file mode 100644 index 0000000..bdddd5a --- /dev/null +++ b/services/frontend/src/pages/Competition/index.tsx @@ -0,0 +1,53 @@ +import { useState } from "react"; +import { useParams, Link } from "react-router-dom"; +import { Button } from "@/components/ui/button"; +import { ArrowLeft } from "lucide-react"; +import { Competition } from "@/shared/types"; +import { mockCompetitions } from "@/shared/mocks/mocks"; + +const CompetitionPage = () => { + const { id } = useParams<{ id: string }>(); + const [competition] = useState( + mockCompetitions.find((comp) => comp.id === id)!, + ); + + return ( +
+ + + Назад к соревнованиям + + +
+
+ {competition.name} +
+ +
+
+

+ {competition.name} +

+
+ {competition.description + ?.split("\n") + .map((line, i) =>

{line}

)} +
+
+
+ +
+
+
+
+ ); +}; + +export default CompetitionPage; diff --git a/services/frontend/src/pages/CompetitionPreviewPage/index.tsx b/services/frontend/src/pages/CompetitionPreviewPage/index.tsx deleted file mode 100644 index e6261f7..0000000 --- a/services/frontend/src/pages/CompetitionPreviewPage/index.tsx +++ /dev/null @@ -1,108 +0,0 @@ -import { useEffect, useState } from "react"; -import { useParams, useNavigate } from "react-router-dom"; -import Navbar from "@/widgets/Navbar"; -import { Button } from "@/components/ui/button"; -import { ArrowLeft } from "lucide-react"; -import { Competition } from "@/shared/types"; -import { mockCompetitions, mockTasks } from "@/shared/mocks/mocks"; - -const CompetitionPreview = () => { - const { id } = useParams<{ id: string }>(); - const navigate = useNavigate(); - const [competition, setCompetition] = useState(null); - const [isLoading, setIsLoading] = useState(true); - - useEffect(() => { - const fetchCompetition = async () => { - try { - setTimeout(() => { - const found = mockCompetitions.find((comp) => comp.id === id); - setCompetition(found || null); - setIsLoading(false); - }, 500); - } catch (error) { - console.error("Error fetching competition:", error); - setIsLoading(false); - } - }; - - fetchCompetition(); - }, [id]); - - const handleBack = () => { - navigate(-1); - }; - - const handleContinue = () => { - if (competition?.id) { - const competitionTasks = mockTasks[competition.id]; - - if (competitionTasks && competitionTasks.length > 0) { - const firstTaskId = competitionTasks[0].id; - navigate(`/competition/${competition.id}/tasks/${firstTaskId}`); - } else { - navigate(`/competition/${competition.id}/tasks`); - } - } - }; - - return ( - <> - -
- - - {isLoading ? ( -
-

Загрузка...

-
- ) : competition ? ( -
-
- {competition.name} -
- -
-
-

- {competition.name} -

- -
- -
-

{competition.description}

-
-
-
- ) : ( -
-

- Соревнование не найдено -

-

- Запрошенное соревнование не существует или было удалено. -

-
- )} -
- - ); -}; - -export default CompetitionPreview; diff --git a/services/frontend/src/pages/CompetitionRunnerPage/index.tsx b/services/frontend/src/pages/CompetitionSession/index.tsx similarity index 98% rename from services/frontend/src/pages/CompetitionRunnerPage/index.tsx rename to services/frontend/src/pages/CompetitionSession/index.tsx index 73b8797..8b3f3fd 100644 --- a/services/frontend/src/pages/CompetitionRunnerPage/index.tsx +++ b/services/frontend/src/pages/CompetitionSession/index.tsx @@ -1,6 +1,5 @@ import { useState } from "react"; import { useParams } from "react-router-dom"; -import Navbar from "@/widgets/Navbar"; import { Task, TaskStatus } from "@/shared/types"; const sampleTasks: Task[] = [ @@ -58,8 +57,6 @@ const CompetitionRunnerPage = () => { return ( <> - -
diff --git a/services/frontend/src/pages/CompetitionsPage/components/CompetitionCard/index.tsx b/services/frontend/src/pages/Competitions/components/CompetitionCard/index.tsx similarity index 100% rename from services/frontend/src/pages/CompetitionsPage/components/CompetitionCard/index.tsx rename to services/frontend/src/pages/Competitions/components/CompetitionCard/index.tsx diff --git a/services/frontend/src/pages/CompetitionsPage/components/CompetitionSkeleton/index.tsx b/services/frontend/src/pages/Competitions/components/CompetitionSkeleton/index.tsx similarity index 100% rename from services/frontend/src/pages/CompetitionsPage/components/CompetitionSkeleton/index.tsx rename to services/frontend/src/pages/Competitions/components/CompetitionSkeleton/index.tsx diff --git a/services/frontend/src/pages/CompetitionsPage/components/CompetitionTag/index.tsx b/services/frontend/src/pages/Competitions/components/CompetitionTag/index.tsx similarity index 100% rename from services/frontend/src/pages/CompetitionsPage/components/CompetitionTag/index.tsx rename to services/frontend/src/pages/Competitions/components/CompetitionTag/index.tsx diff --git a/services/frontend/src/pages/CompetitionsPage/index.tsx b/services/frontend/src/pages/Competitions/index.tsx similarity index 100% rename from services/frontend/src/pages/CompetitionsPage/index.tsx rename to services/frontend/src/pages/Competitions/index.tsx diff --git a/services/frontend/src/pages/CompetitionsPage/modules/CompetitionGrid/index.tsx b/services/frontend/src/pages/Competitions/modules/CompetitionGrid/index.tsx similarity index 67% rename from services/frontend/src/pages/CompetitionsPage/modules/CompetitionGrid/index.tsx rename to services/frontend/src/pages/Competitions/modules/CompetitionGrid/index.tsx index 19b376c..1281f06 100644 --- a/services/frontend/src/pages/CompetitionsPage/modules/CompetitionGrid/index.tsx +++ b/services/frontend/src/pages/Competitions/modules/CompetitionGrid/index.tsx @@ -1,5 +1,6 @@ import { Competition } from "@/shared/types"; import { CompetitionCard } from "../../components/CompetitionCard"; +import { Link } from "react-router"; interface CompetitionGridProps { competitions: Competition[]; @@ -9,7 +10,9 @@ export function CompetitionGrid({ competitions }: CompetitionGridProps) { return (
{competitions.map((competition) => ( - + + + ))}
); diff --git a/services/frontend/src/pages/CompetitionsPage/types.ts b/services/frontend/src/pages/Competitions/types.ts similarity index 100% rename from services/frontend/src/pages/CompetitionsPage/types.ts rename to services/frontend/src/pages/Competitions/types.ts diff --git a/services/frontend/src/shared/mocks/mocks.ts b/services/frontend/src/shared/mocks/mocks.ts index b05ad67..b892d8b 100644 --- a/services/frontend/src/shared/mocks/mocks.ts +++ b/services/frontend/src/shared/mocks/mocks.ts @@ -7,8 +7,11 @@ const mockCompetitions: Competition[] = [ imageUrl: "/DANO.png", isOlympics: true, status: CompetitionStatus.InProgress, - description: - "Проверка глубоких знаний и навыков в анализе данных. Будет несколько творческих заданий со свободным ответом. Задания выполняются индивидуально, вес тура в итоговом результате – 0,5. Этап пройдет онлайн в заданное время, с применением системы прокторинга. На работу дается 240 минут.", + description: `Проверка глубоких знаний и навыков в анализе данных. +Будет несколько творческих заданий со свободным ответом. +Задания выполняются индивидуально, вес тура в итоговом результате – 0,5. +Этап пройдет онлайн в заданное время, с применением системы прокторинга. +На работу дается 240 минут.`, }, { id: "2",