diff --git a/services/frontend/src/components/layout/header.tsx b/services/frontend/src/components/layout/header.tsx index 4bd1cdd..9ebacc2 100644 --- a/services/frontend/src/components/layout/header.tsx +++ b/services/frontend/src/components/layout/header.tsx @@ -13,7 +13,13 @@ import { useUserStore } from "@/shared/stores/user"; const Header = () => { const user = useUserStore((state) => state.user); + const clearUser = useUserStore((state) => state.clearUser); const [isProfileOpen, setIsProfileOpen] = useState(false); + + const handleLogout = () => { + clearUser(); + setIsProfileOpen(false); + }; return (
@@ -69,9 +75,7 @@ const Header = () => { } label="Выйти" - onClick={() => { - setIsProfileOpen(false); - }} + onClick={handleLogout} /> diff --git a/services/frontend/src/pages/Competition/index.tsx b/services/frontend/src/pages/Competition/index.tsx index e472ddb..3381ad7 100644 --- a/services/frontend/src/pages/Competition/index.tsx +++ b/services/frontend/src/pages/Competition/index.tsx @@ -1,6 +1,6 @@ import { useParams, Link, useNavigate } from "react-router-dom"; import { Button } from "@/components/ui/button"; -import { ArrowLeft, Clock, Trophy, BookOpen } from "lucide-react"; +import { ArrowLeft, Clock, Trophy, BookOpen, BarChart2 } from "lucide-react"; import ReactMarkdown from "react-markdown"; import { useQuery, useMutation } from "@tanstack/react-query"; import { getCompetition, startCompetition } from "@/shared/api/competitions"; @@ -39,6 +39,7 @@ const CompetitionPage = () => { console.error("Failed to start competition:", error); } }); + const formatDate = (date?: Date | string) => { if (!date) return ""; @@ -56,6 +57,20 @@ const CompetitionPage = () => { const handleStart = () => { startMutation.mutate(); }; + + const handleViewResults = () => { + navigate(`/competition/${competitionId}/results`); + }; + + // Check if competition has ended + const isCompetitionEnded = () => { + if (!competitionQuery.data?.end_date) return false; + + const endDate = new Date(competitionQuery.data.end_date); + const now = new Date(); + + return now > endDate; + }; if (competitionQuery.isLoading) { return ; @@ -66,6 +81,7 @@ const CompetitionPage = () => { } const competition = competitionQuery.data; + const competitionEnded = isCompetitionEnded(); return (
@@ -103,6 +119,12 @@ const CompetitionPage = () => { )}
+ + {competitionEnded && competition.type === CompetitionType.COMPETITIVE && ( +
+ Завершено +
+ )}

@@ -133,13 +155,24 @@ const CompetitionPage = () => {
- + {competitionEnded && competition.type === CompetitionType.COMPETITIVE ? ( + + ) : ( + + )}
diff --git a/services/frontend/src/shared/stores/user.ts b/services/frontend/src/shared/stores/user.ts index 6e7509d..08921c6 100644 --- a/services/frontend/src/shared/stores/user.ts +++ b/services/frontend/src/shared/stores/user.ts @@ -7,6 +7,7 @@ interface UserState { loading: boolean; fetchUser: () => Promise; + clearUser: () => void; } const useUserStore = create((set) => ({ @@ -18,6 +19,10 @@ const useUserStore = create((set) => ({ const user = await getCurrentUser(); set({ user, loading: false }); }, + + clearUser: () => { + set({ user: null }); + }, })); -export { useUserStore }; +export { useUserStore }; \ No newline at end of file