import React, { useState } from "react";
const App = () => {
const [user, setUser] = useState(null);
const [activeTab, setActiveTab] = useState("home");
const [photos, setPhotos] = useState([]);
const [adminDriveLink, setAdminDriveLink] = useState("");
// Тестовые пользователи
const testUsers = {
participant: { email: "participant@example.com", password: "123456" },
judge: { email: "judge@example.com", password: "123456" },
admin: { email: "admin@example.com", password: "123456" },
};
// Данные участников (в реальности хранятся на сервере)
const initialParticipants = [
{
id: 1,
name: "Алексей Иванов",
photos: [
{ id: 1, url: "https://placehold.co/600x400?text=Фото+1", votes: { creativity: 0, composition: 0, other: 0 } },
{ id: 2, url: "https://placehold.co/600x400?text=Фото+2", votes: { creativity: 0, composition: 0, other: 0 } },
],
},
{
id: 2,
name: "Мария Петрова",
photos: [
{ id: 3, url: "https://placehold.co/600x400?text=Фото+3", votes: { creativity: 0, composition: 0, other: 0 } },
],
},
];
const [participants, setParticipants] = useState(initialParticipants);
const handleLogin = (email, password) => {
if (email === testUsers.participant.email && password === testUsers.participant.password) {
setUser({ role: "participant", name: "Участник", email });
setActiveTab("participant");
} else if (email === testUsers.judge.email && password === testUsers.judge.password) {
setUser({ role: "judge", name: "Жюри", email });
setActiveTab("judge");
} else if (email === testUsers.admin.email && password === testUsers.admin.password) {
setUser({ role: "admin", name: "Администратор", email });
setActiveTab("admin");
} else {
alert("Неверный логин или пароль");
}
};
const handleUploadPhoto = (file) => {
if (!file) return;
const reader = new FileReader();
reader.onload = (e) => {
const newPhoto = {
id: Date.now(),
url: e.target.result,
votes: { creativity: 0, composition: 0, other: 0 },
};
setPhotos((prev) => [...prev, newPhoto]);
alert("Фотография загружена в Яндекс.Диск (симуляция)");
};
reader.readAsDataURL(file);
};
const handleVote = (photoId, criterion, value) => {
setParticipants((prev) =>
prev.map((p) => ({
...p,
photos: p.photos.map((ph) =>
ph.id === photoId ? { ...ph, votes: { ...ph.votes, [criterion]: value } } : ph
),
}))
);
alert(`Вы оценили по критерию "${criterion}"`);
};
const calculateAverageRating = (votes) => {
const total = Object.values(votes).reduce((sum, val) => sum + val, 0);
return (total / Object.keys(votes).length).toFixed(2);
};
const renderLoginForm = () => (