Merge branch 'master' of gitlab.prodcontest.ru:team-15/project

This commit is contained in:
moolcoov
2025-03-03 22:00:34 +03:00
10 changed files with 957 additions and 39 deletions
@@ -30,12 +30,13 @@ export const Header = () => {
</Link>
<div className="flex items-center gap-4">
<a
href="/docs/"
className="text-sm font-medium text-gray-700 hover:text-gray-900 transition-colors flex items-center gap-1"
>
<FileText className="h-4 w-4" />
</a>
<a
href="/docs/"
className="hidden md:flex text-sm font-medium text-gray-700 hover:text-gray-900 transition-colors items-center gap-1"
>
<FileText className="h-4 w-4" />
Материалы
</a>
<DropdownMenu>
<DropdownMenuTrigger asChild>
@@ -50,6 +51,16 @@ export const Header = () => {
<Link to="/profile">
<DropdownMenuItem>Аккаунт</DropdownMenuItem>
</Link>
<div className="md:hidden">
<Link to="/docs">
<DropdownMenuItem>
<FileText className="h-4 w-4 mr-2" />
Материалы
</DropdownMenuItem>
</Link>
</div>
<DropdownMenuSeparator />
<DropdownMenuItem
variant="destructive"
@@ -1,3 +1,4 @@
// src/components/competition/CompetitionResultsModal.tsx
import React from 'react';
import {
Dialog,
@@ -33,13 +34,58 @@ export const CompetitionResultsModal: React.FC<CompetitionResultsModalProps> = (
}) => {
const renderResultValue = (result: number, maxPoints: number) => {
if (result === -1) {
return <span className="text-yellow-600">На проверке</span>;
return (
<span className="font-semibold" style={{
color: 'var(--color-task-text-checking)',
backgroundColor: 'var(--color-task-checking)',
padding: '4px 8px',
borderRadius: '4px'
}}>
На проверке
</span>
);
} else if (result === -2) {
return <span className="text-gray-500">Нет ответа</span>;
return (
<span className="font-semibold" style={{
color: 'var(--color-task-text-uncleared)',
backgroundColor: 'var(--color-task-uncleared)',
padding: '4px 8px',
borderRadius: '4px'
}}>
Нет ответа
</span>
);
} else if (result === 0) {
return (
<span className="font-semibold" style={{
color: 'var(--color-task-text-wrong)',
backgroundColor: 'var(--color-task-wrong)',
padding: '4px 8px',
borderRadius: '4px'
}}>
Неверно (0/{maxPoints})
</span>
);
} else if (result < maxPoints) {
return (
<span className="font-semibold" style={{
color: 'var(--color-task-text-partial)',
backgroundColor: 'var(--color-task-partial)',
padding: '4px 8px',
borderRadius: '4px'
}}>
Частично верно ({result}/{maxPoints})
</span>
);
} else {
return (
<span className="text-green-600">
Зачтено {result}/{maxPoints} баллов
<span className="font-semibold" style={{
color: 'var(--color-task-text-correct)',
backgroundColor: 'var(--color-task-correct)',
padding: '4px 8px',
borderRadius: '4px'
}}>
Верно ({result}/{maxPoints})
</span>
);
}
@@ -71,7 +117,7 @@ export const CompetitionResultsModal: React.FC<CompetitionResultsModalProps> = (
className="flex flex-col md:flex-row justify-between items-start md:items-center p-4 bg-gray-50 rounded-lg border"
>
<div className="font-medium mb-2 md:mb-0">{result.task_name}</div>
<div className="text-right font-semibold">
<div className="text-right">
{renderResultValue(result.result, result.max_points)}
</div>
</div>
@@ -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 = () => {
<Button
size={"lg"}
onClick={() => setIsResultsModalOpen(true)}
className="bg-indigo-600 hover:bg-indigo-700"
>
<BarChart2 size={18} className="mr-2" />
Посмотреть результаты
@@ -221,7 +219,7 @@ const CompetitionPage = () => {
{competitionEnded && !hasResults && competition.type === CompetitionType.COMPETITIVE && !resultsQuery.isLoading && (
<div className="text-center p-4 border rounded-md bg-gray-50">
<p className="text-gray-600">Соревнование завершено. Результаты пока не доступны.</p>
<p className="text-gray-600">Соревнование завершено. Увы</p>
</div>
)}
</div>
@@ -1,8 +1,9 @@
import React, { useState, useEffect } from 'react';
import { Link, useNavigate } from 'react-router-dom';
import { Link, useNavigate, useParams } from 'react-router-dom';
import { Task } from '@/shared/types/task';
import { ArrowLeft, Clock } from 'lucide-react';
import { ArrowLeft } from 'lucide-react';
import { CompetitionType } from '@/shared/types/competition';
import { CompetitionResult } from '@/shared/types/competition';
interface CompetitionHeaderProps {
title: string;
@@ -11,8 +12,9 @@ interface CompetitionHeaderProps {
setAnswer: (value: string) => void;
setSelectedFile: (file: File | null) => void;
competitionType?: CompetitionType;
startDate?: Date;
endDate?: Date;
startDate?: Date | string;
endDate?: Date | string;
taskResults?: CompetitionResult[];
}
const CompetitionHeader: React.FC<CompetitionHeaderProps> = ({
@@ -23,9 +25,11 @@ const CompetitionHeader: React.FC<CompetitionHeaderProps> = ({
setSelectedFile,
competitionType,
startDate,
endDate
endDate,
taskResults = []
}) => {
const navigate = useNavigate();
const { taskId } = useParams<{ taskId?: string }>();
const [timeLeft, setTimeLeft] = useState<string>('');
const handleTaskSelect = (taskId: string) => {
@@ -34,7 +38,7 @@ const CompetitionHeader: React.FC<CompetitionHeaderProps> = ({
navigate(`/competition/${competitionId}/tasks/${taskId}`);
}
const formatDate = (date?: Date) => {
const formatDate = (date?: Date | string) => {
if (!date) return '';
const dateObj = typeof date === 'string' ? new Date(date) : date;
@@ -74,6 +78,42 @@ const CompetitionHeader: React.FC<CompetitionHeaderProps> = ({
return () => clearInterval(timerInterval);
}, [endDate, competitionId, navigate, competitionType]);
const getTaskStatus = (task: Task) => {
const result = taskResults.find(r => r.task_name === task.title);
let bgColor = 'var(--color-task-uncleared)';
let textColor = 'var(--color-task-text-uncleared)';
if (result) {
if (result.result === -1) {
bgColor = 'var(--color-task-checking)';
textColor = 'var(--color-task-text-checking)';
} else if (result.result === -2) {
bgColor = 'var(--color-task-uncleared)';
textColor = 'var(--color-task-text-uncleared)';
} else if (result.result === 0) {
bgColor = 'var(--color-task-wrong)';
textColor = 'var(--color-task-text-wrong)';
} else if (result.result < result.max_points) {
bgColor = 'var(--color-task-partial)';
textColor = 'var(--color-task-text-partial)';
} else if (result.result === result.max_points) {
bgColor = 'var(--color-task-correct)';
textColor = 'var(--color-task-text-correct)';
}
}
const isActive = task.id === taskId;
const activeBorder = isActive ? 'border-2 border-blue-500' : '';
return {
backgroundColor: bgColor,
color: textColor,
className: `rounded-lg px-3 py-1.5 font-medium text-sm font-hse-sans cursor-pointer
transition-all hover:brightness-95 flex-shrink-0 ${activeBorder}`
};
};
const showTimeSection = competitionType === CompetitionType.COMPETITIVE && (startDate || endDate);
return (
@@ -120,18 +160,19 @@ const CompetitionHeader: React.FC<CompetitionHeaderProps> = ({
</div>
<div className="flex items-center justify-center gap-4 pb-4 overflow-x-auto no-scrollbar">
{tasks.map((task) => (
<button
key={task.id}
className={`text-[var(--color-task-text-uncleared)] bg-[var(--color-task-uncleared)]
rounded-lg px-3 py-1.5 font-medium text-sm font-hse-sans cursor-pointer
transition-all hover:brightness-95 flex-shrink-0
`}
onClick={() => handleTaskSelect(task.id)}
>
{task.in_competition_position}
</button>
))}
{tasks.map((task) => {
const { backgroundColor, color, className } = getTaskStatus(task);
return (
<button
key={task.id}
style={{ backgroundColor, color }}
className={className}
onClick={() => handleTaskSelect(task.id)}
>
{task.in_competition_position}
</button>
);
})}
</div>
</div>
</header>
@@ -1,10 +1,10 @@
import { useState, useEffect } from "react";
import { useParams, Navigate, useNavigate } from "react-router-dom";
import { useParams, Navigate } from "react-router-dom";
import CompetitionHeader from "./components/CompetitionHeader";
import TaskContent from "./components/TaskContent";
import TaskSolution from "./modules/TaskSolution";
import { getCompetitionTasks, submitTaskSolution } from "@/shared/api/session";
import { getCompetition } from "@/shared/api/competitions";
import { getCompetition, getCompetitionResults } from "@/shared/api/competitions";
import { Loader2 } from "lucide-react";
import { useQuery, useMutation, useQueryClient } from "@tanstack/react-query";
import { TaskType } from "@/shared/types/task";
@@ -16,7 +16,6 @@ const CompetitionSession = () => {
const [isReloading, setIsReloading] = useState(false);
const competitionId = id || "";
const queryClient = useQueryClient();
const navigate = useNavigate();
const competitionQuery = useQuery({
queryKey: ["competition", competitionId],
@@ -30,6 +29,12 @@ const CompetitionSession = () => {
enabled: !!competitionId,
});
const resultsQuery = useQuery({
queryKey: ["competitionResults", competitionId],
queryFn: () => getCompetitionResults(competitionId),
enabled: !!competitionId,
});
const submitMutation = useMutation({
mutationFn: () => {
if (!currentTask || !competitionId) throw new Error("Missing task or competition ID");
@@ -47,10 +52,14 @@ const CompetitionSession = () => {
queryKey: ['solutionHistory', competitionId, taskId]
});
queryClient.invalidateQueries({
queryKey: ['competitionResults', competitionId]
});
setIsReloading(true);
setTimeout(() => {
window.location.reload()
window.location.reload();
setIsReloading(false);
}, 2500);
},
@@ -61,6 +70,7 @@ const CompetitionSession = () => {
const competition = competitionQuery.data;
const tasks = tasksQuery.data || [];
const results = resultsQuery.data || [];
const isLoading = tasksQuery.isLoading || competitionQuery.isLoading;
const error = tasksQuery.error || competitionQuery.error
? "Не удалось загрузить данные. Пожалуйста, попробуйте позже."
@@ -113,6 +123,7 @@ const CompetitionSession = () => {
competitionType={competition?.type}
startDate={competition?.start_date}
endDate={competition?.end_date}
taskResults={results}
/>
<main className="flex-1 bg-[#F8F8F8] pb-8">
@@ -138,6 +149,16 @@ const CompetitionSession = () => {
onSubmit={handleSubmit}
isSubmitting={isSubmitting}
/>
{isReloading && (
<div className="fixed inset-0 flex items-center justify-center bg-black bg-opacity-50 z-50">
<div className="bg-white p-6 rounded-lg shadow-xl text-center">
<Loader2 className="h-8 w-8 animate-spin mx-auto mb-4" />
<p className="font-hse-sans text-gray-700">
Решение отправлено! Пожалуйста, подождите...
</p>
</div>
</div>
)}
</div>
) : (
<div className="flex h-40 items-center justify-center rounded-lg bg-white">
@@ -30,10 +30,9 @@ const ActionButtons: React.FC<ActionButtonsProps> = ({
{isCleared ? (
<Button
className="font-hse-sans flex-grow bg-green-600 hover:bg-green-700"
className="font-hse-sans flex-grow"
disabled={true}
>
<CheckCircle className="mr-2 h-4 w-4" />
Задача сдана!
</Button>
) : hasSubmissionsLeft ? (
@@ -24,7 +24,7 @@ export const UserStatsSections = () => {
/>
<UserStatBlock
value={stats.total_attempts}
description="Попыток выполнено"
description="Решений отправлено"
/>
</div>
) : (