NOVAESPORT / src /components /GamesView.tsx
Musabek's picture
Deploy all codebase from Google AI Studio
049b896
Raw History Blame Contribute Delete
19.2 kB
import React, { useState } from 'react';
import { doc, updateDoc, increment } from 'firebase/firestore';
import { db, handleFirestoreError, OperationType } from '../firebase';
import { CyberMatch } from '../types';
import { Calendar, Clock, Trophy, Flame, CheckCircle, ChevronRight, Vote, Sparkles } from 'lucide-react';
import { Language } from '../translations';
interface GamesViewProps {
cyberMatches: CyberMatch[];
currentLanguage: Language;
}
export const GamesView: React.FC<GamesViewProps> = ({ cyberMatches, currentLanguage }) => {
const [selectedGameFilter, setSelectedGameFilter] = useState<string>('all');
const [votedMatchIds, setVotedMatchIds] = useState<string[]>(() => {
try {
const saved = localStorage.getItem('nova_voted_matches');
return saved ? JSON.parse(saved) : [];
} catch {
return [];
}
});
// Localized UI strings
const localDict = {
EN: {
title: "🎮 Cyber Match Schedule",
subtitle: "Track live and upcoming professional matches, vote for your favorite squad, and watch the win probability rise in real-time!",
allGames: "All Games",
upcomingTab: "Upcoming",
liveTab: "Live Now",
finishedTab: "Completed",
voteForA: "Vote Team A",
voteForB: "Vote Team B",
totalVotes: "Total Votes",
winRateLabel: "Win Probability",
noMatches: "No matches scheduled at the moment. Admins can create new matches in the Control Board!",
votedMessage: "Your vote has been counted!",
timeLabel: "Match Date & Time",
vsLabel: "VS",
popularVote: "Popular Choice"
},
UZ: {
title: "🎮 O'yinlar O'tkaziladigan Taqvim",
subtitle: "Professional va jonli o'yinlar jadvalini kuzatib boring, sevimli jamoangizga ovoz bering va ularning g'alaba qozonish imkoniyatini real vaqtda oshiring!",
allGames: "Barcha O'yinlar",
upcomingTab: "Kutilayotgan",
liveTab: "Jonli Efir",
finishedTab: "Yakunlangan",
voteForA: "A Jamoaga Ovoz Berish",
voteForB: "B Jamoaga Ovoz Berish",
totalVotes: "Umumiy Ovozlar",
winRateLabel: "G'alaba Imkoniyati",
noMatches: "Hozircha hech qanday o'yin rejalashtirilmagan. Adminlar Boshqaruv Panelida yangi o'yinlar qo'shishlari mumkin!",
votedMessage: "Ovozingiz qabul qilindi!",
timeLabel: "O'yin Kuni va Vaqti",
vsLabel: "VS",
popularVote: "Ko'pchilik Tanlovi"
},
RU: {
title: "🎮 Расписание Кибер-Матчей",
subtitle: "Следите за профессиональными матчами в прямом эфире и расписанием, голосуйте за свои команды и наблюдайте за ростом шансов на победу в реальном времени!",
allGames: "Все Игры",
upcomingTab: "Ожидаемые",
liveTab: "Прямой Эфир",
finishedTab: "Завершенные",
voteForA: "Голосовать за команду А",
voteForB: "Голосовать за команду Б",
totalVotes: "Всего Голосов",
winRateLabel: "Вероятность Победы",
noMatches: "На данный момент матчей не запланировано. Администраторы могут создать новые матчи в Панели Управления!",
votedMessage: "Ваш голос учтен!",
timeLabel: "Дата и Время Матча",
vsLabel: "VS",
popularVote: "Выбор большинства"
}
};
const ui = localDict[currentLanguage] || localDict['EN'];
// Handle voting logic
const handleVote = async (matchId: string, team: 'teamA' | 'teamB') => {
try {
const matchRef = doc(db, 'cyber_matches', matchId);
const updateData = team === 'teamA'
? { 'teamA.votes': increment(1) }
: { 'teamB.votes': increment(1) };
await updateDoc(matchRef, updateData);
const newVoted = [...votedMatchIds, `${matchId}-${team}`];
setVotedMatchIds(newVoted);
localStorage.setItem('nova_voted_matches', JSON.stringify(newVoted));
} catch (err) {
handleFirestoreError(err, OperationType.UPDATE, `cyber_matches/${matchId}`);
}
};
// Get game list for filtering
const gamesList: string[] = Array.from(new Set(cyberMatches.map(m => m.gameName as string))).filter(Boolean) as string[];
// Filtered matches
const filteredMatches = cyberMatches.filter(m => {
if (selectedGameFilter === 'all') return true;
return m.gameName.toLowerCase() === selectedGameFilter.toLowerCase();
});
return (
<div className="max-w-7xl mx-auto px-4 py-8 space-y-12 animate-in fade-in duration-300 font-sans" id="cyber-matches-calendar-view">
{/* Header and intro banner */}
<div className="relative p-6 md:p-10 rounded-3xl bg-gradient-to-r from-purple-900/30 via-slate-900/80 to-cyan-900/20 border border-white/10 overflow-hidden shadow-2xl">
<div className="absolute top-0 right-0 w-80 h-80 bg-cyan-500/10 rounded-full blur-[100px] pointer-events-none" />
<div className="absolute bottom-0 left-0 w-64 h-64 bg-purple-500/10 rounded-full blur-[80px] pointer-events-none" />
<div className="relative z-10 space-y-4 max-w-4xl text-left">
<span className="inline-flex items-center gap-1.5 px-3 py-1 rounded-full text-[10px] font-black uppercase tracking-widest bg-cyan-500/10 border border-cyan-500/30 text-cyan-400">
<Sparkles className="w-3.5 h-3.5 animate-spin" style={{ animationDuration: '6s' }} /> Live Tournament Taqvim & Predictor
</span>
<h1 className="text-3xl md:text-4xl font-extrabold text-white uppercase tracking-wider font-mono">
{ui.title}
</h1>
<p className="text-slate-350 text-slate-350 text-sm md:text-base leading-relaxed">
{ui.subtitle}
</p>
</div>
</div>
{/* Game Filters Section */}
<div className="flex flex-wrap items-center gap-2 border-b border-white/10 pb-4 justify-start">
<button
onClick={() => setSelectedGameFilter('all')}
className={`px-4 py-2 rounded-xl text-xs font-bold uppercase tracking-wider transition-all duration-200 cursor-pointer ${
selectedGameFilter === 'all'
? 'bg-gradient-to-r from-cyan-500 to-purple-600 text-white shadow-lg'
: 'bg-white/5 border border-white/10 text-slate-350 hover:bg-white/10 hover:text-white'
}`}
>
{ui.allGames}
</button>
{gamesList.map((g) => (
<button
key={g}
onClick={() => setSelectedGameFilter(g)}
className={`px-4 py-2 rounded-xl text-xs font-bold uppercase tracking-wider transition-all duration-200 cursor-pointer ${
selectedGameFilter.toLowerCase() === g.toLowerCase()
? 'bg-gradient-to-r from-cyan-500 to-purple-600 text-white shadow-lg'
: 'bg-white/5 border border-white/10 text-slate-350 hover:bg-white/10 hover:text-white'
}`}
>
{g}
</button>
))}
</div>
{/* Calendar Matches Grid */}
{filteredMatches.length === 0 ? (
<div className="p-16 rounded-2xl bg-white/5 border border-white/10 text-center max-w-2xl mx-auto space-y-4">
<Calendar className="w-12 h-12 text-slate-500 mx-auto animate-bounce" />
<h3 className="text-white font-bold font-mono text-sm uppercase">{ui.vsLabel} NO EVENT SCHEDULED</h3>
<p className="text-slate-400 text-xs">
{ui.noMatches}
</p>
</div>
) : (
<div className="grid grid-cols-1 gap-8">
{filteredMatches.map((match) => {
const votesA = match.teamA.votes || 0;
const votesB = match.teamB.votes || 0;
const total = votesA + votesB;
const percentA = total > 0 ? Math.round((votesA / total) * 100) : 50;
const percentB = total > 0 ? Math.round((votesB / total) * 100) : 50;
const hasVotedA = votedMatchIds.includes(`${match.id}-teamA`);
const hasVotedB = votedMatchIds.includes(`${match.id}-teamB`);
const hasVotedAny = hasVotedA || hasVotedB;
return (
<div
key={match.id}
className="relative overflow-hidden bg-[#090918]/80 border border-white/10 rounded-2xl p-6 md:p-8 flex flex-col md:flex-row items-center justify-between gap-6 transition-all duration-300 hover:border-cyan-500/30 hover:shadow-[0_0_20px_rgba(34,211,238,0.05)] text-left"
>
{/* Status indicator line on the side */}
<div className={`absolute left-0 top-0 bottom-0 w-1 ${
match.status === 'live' ? 'bg-red-500' : match.status === 'finished' ? 'bg-slate-500' : 'bg-cyan-500'
}`} />
{/* Left Section: Metadata */}
<div className="w-full md:w-1/4 space-y-3 shrink-0">
<div className="flex items-center gap-2">
<span className={`inline-flex items-center gap-1.5 px-2.5 py-0.5 rounded text-[9px] font-black uppercase tracking-wider ${
match.status === 'live'
? 'bg-red-500/20 text-red-400 border border-red-500/30'
: match.status === 'finished'
? 'bg-slate-500/20 text-slate-400 border border-slate-500/30'
: 'bg-cyan-500/20 text-cyan-400 border border-cyan-500/30'
}`}>
{match.status === 'live' && <span className="w-1.5 h-1.5 rounded-full bg-red-500 animate-pulse shrink-0" />}
{match.status === 'live' ? ui.liveTab : match.status === 'finished' ? ui.finishedTab : ui.upcomingTab}
</span>
<span className="text-[10px] text-slate-400 font-mono font-bold uppercase tracking-widest bg-white/5 px-2 py-0.5 rounded border border-white/5">
{match.gameName}
</span>
</div>
<div className="space-y-1.5">
<div className="flex items-center gap-2 text-xs text-slate-350">
<Calendar className="w-3.5 h-3.5 text-cyan-400 shrink-0" />
<span className="font-semibold">{match.dateTime.split(' ')[0]}</span>
</div>
<div className="flex items-center gap-2 text-xs text-slate-350">
<Clock className="w-3.5 h-3.5 text-purple-400 shrink-0" />
<span className="font-mono">{match.dateTime.split(' ')[1] || 'TBD'}</span>
</div>
</div>
</div>
{/* Middle Section: Teams & Interactive Voting Arena */}
<div className="flex-1 w-full grid grid-cols-1 md:grid-cols-11 items-center gap-4 py-4 md:py-0">
{/* TEAM A */}
<div className="col-span-1 md:col-span-5 flex flex-col items-center md:items-end text-center md:text-right space-y-3">
<button
onClick={() => !hasVotedAny && handleVote(match.id, 'teamA')}
disabled={hasVotedAny}
className={`group w-full max-w-[240px] p-4 rounded-xl border transition-all duration-300 relative ${
hasVotedA
? 'bg-cyan-500/10 border-cyan-400/50 shadow-[0_0_15px_rgba(34,211,238,0.1)]'
: hasVotedAny
? 'bg-white/5 border-white/5 opacity-50 cursor-not-allowed'
: 'bg-white/5 border-white/10 hover:border-cyan-500/30 hover:bg-white/10 cursor-pointer'
}`}
>
{percentA > percentB && (
<span className="absolute -top-2 right-2 bg-gradient-to-r from-yellow-500 to-amber-600 text-[8px] font-black uppercase text-white px-1.5 py-0.5 rounded shadow flex items-center gap-0.5">
<Flame className="w-2.5 h-2.5 shrink-0" /> {ui.popularVote}
</span>
)}
<div className="flex items-center gap-3 justify-center md:justify-end">
<div className="order-2 md:order-1 text-right">
<span className="text-xs font-black text-white uppercase block tracking-wide group-hover:text-cyan-400 transition-colors">
{match.teamA.name}
</span>
<span className="text-[10px] text-slate-500 font-mono block mt-0.5">
{votesA} {ui.voteForA.split(' ')[0].toLowerCase()}s
</span>
</div>
<div className="order-1 md:order-2 w-10 h-10 rounded-lg bg-[#020205] border border-white/10 p-1 flex items-center justify-center shrink-0">
{match.teamA.logo && match.teamA.logo.length > 5 ? (
<img src={match.teamA.logo} referrerPolicy="no-referrer" className="w-full h-full object-contain" alt="" />
) : (
<span className="text-lg">{match.teamA.logo || '🛡️'}</span>
)}
</div>
</div>
{!hasVotedAny && (
<div className="mt-2 text-center md:text-right">
<span className="text-[9px] text-cyan-400 font-bold tracking-wider uppercase inline-flex items-center gap-1 group-hover:underline">
<Vote className="w-3 h-3" /> {ui.voteForA}
</span>
</div>
)}
</button>
</div>
{/* VS SPLITTER */}
<div className="col-span-1 md:col-span-1 flex flex-col items-center justify-center">
<span className="text-sm font-black text-transparent bg-clip-text bg-gradient-to-r from-cyan-400 to-purple-500 font-mono tracking-wider animate-pulse">
{ui.vsLabel}
</span>
</div>
{/* TEAM B */}
<div className="col-span-1 md:col-span-5 flex flex-col items-center md:items-start text-center md:text-left space-y-3">
<button
onClick={() => !hasVotedAny && handleVote(match.id, 'teamB')}
disabled={hasVotedAny}
className={`group w-full max-w-[240px] p-4 rounded-xl border transition-all duration-300 relative ${
hasVotedB
? 'bg-purple-500/10 border-purple-400/50 shadow-[0_0_15px_rgba(168,85,247,0.1)]'
: hasVotedAny
? 'bg-white/5 border-white/5 opacity-50 cursor-not-allowed'
: 'bg-white/5 border-white/10 hover:border-purple-500/30 hover:bg-white/10 cursor-pointer'
}`}
>
{percentB > percentA && (
<span className="absolute -top-2 left-2 bg-gradient-to-r from-yellow-500 to-amber-600 text-[8px] font-black uppercase text-white px-1.5 py-0.5 rounded shadow flex items-center gap-0.5">
<Flame className="w-2.5 h-2.5 shrink-0" /> {ui.popularVote}
</span>
)}
<div className="flex items-center gap-3 justify-center md:justify-start">
<div className="w-10 h-10 rounded-lg bg-[#020205] border border-white/10 p-1 flex items-center justify-center shrink-0">
{match.teamB.logo && match.teamB.logo.length > 5 ? (
<img src={match.teamB.logo} referrerPolicy="no-referrer" className="w-full h-full object-contain" alt="" />
) : (
<span className="text-lg">{match.teamB.logo || '⚔️'}</span>
)}
</div>
<div>
<span className="text-xs font-black text-white uppercase block tracking-wide group-hover:text-purple-400 transition-colors">
{match.teamB.name}
</span>
<span className="text-[10px] text-slate-500 font-mono block mt-0.5">
{votesB} {ui.voteForB.split(' ')[0].toLowerCase()}s
</span>
</div>
</div>
{!hasVotedAny && (
<div className="mt-2 text-center md:text-left">
<span className="text-[9px] text-purple-400 font-bold tracking-wider uppercase inline-flex items-center gap-1 group-hover:underline">
<Vote className="w-3 h-3" /> {ui.voteForB}
</span>
</div>
)}
</button>
</div>
</div>
{/* Right Section: Win Percentage Bar & Total votes */}
<div className="w-full md:w-1/4 space-y-3 border-t md:border-t-0 md:border-l border-white/10 pt-4 md:pt-0 md:pl-6 flex flex-col justify-center shrink-0">
<div className="flex justify-between items-center text-xs font-bold uppercase tracking-wider font-mono text-slate-350">
<span>{ui.winRateLabel}</span>
<span className="text-cyan-400">{percentA}% vs {percentB}%</span>
</div>
{/* Dual ProgressBar */}
<div className="w-full h-2 rounded-full bg-white/5 overflow-hidden flex">
<div className="bg-cyan-500 h-full transition-all duration-500" style={{ width: `${percentA}%` }} />
<div className="bg-purple-500 h-full transition-all duration-500" style={{ width: `${percentB}%` }} />
</div>
<div className="flex items-center justify-between text-[10px] text-slate-500 font-mono">
<span>{ui.totalVotes}:</span>
<strong className="text-white font-bold">{total}</strong>
</div>
{hasVotedAny && (
<div className="text-center p-1.5 rounded bg-emerald-500/10 border border-emerald-500/20 text-emerald-400 text-[10px] font-bold flex items-center justify-center gap-1 animate-pulse">
<CheckCircle className="w-3.5 h-3.5 shrink-0" /> {ui.votedMessage}
</div>
)}
</div>
</div>
);
})}
</div>
)}
</div>
);
};