2025-12-08 16:31:30 +03:00

95 lines
3.5 KiB
TypeScript
Raw Permalink Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

'use client'
import { useEffect, useState } from 'react'
export default function ChallengesPage() {
const [challenges, setChallenges] = useState<any[]>([])
useEffect(() => {
loadChallenges()
}, [])
const loadChallenges = async () => {
try {
const res = await fetch('/api/challenges')
const data = await res.json()
setChallenges(data)
} catch (error) {
console.error('Failed to load challenges:', error)
}
}
const createChallenge = async (opponentFid: string) => {
try {
await fetch('/api/challenges', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ opponentFid }),
})
loadChallenges()
} catch (error) {
console.error('Failed to create challenge:', error)
}
}
return (
<div className="min-h-screen bg-gradient-to-br from-gray-900 to-gray-800 p-4">
<div className="max-w-4xl mx-auto pt-20">
<h1 className="text-3xl font-bold text-white mb-8">⚔️ Challenges</h1>
{/* Active Challenges */}
<div className="mb-8">
<h2 className="text-xl font-bold text-white mb-4">Active Challenges</h2>
<div className="space-y-4">
{challenges.filter(c => c.status === 'active').map(challenge => (
<div key={challenge.id} className="bg-gray-800 rounded-xl p-6">
<div className="flex items-center justify-between mb-4">
<div className="flex items-center gap-4">
<div className="text-4xl">⚔️</div>
<div>
<h3 className="font-bold text-white">
{challenge.challenger} vs {challenge.opponent}
</h3>
<p className="text-sm text-gray-400">Best of 5 polls</p>
</div>
</div>
<div className="text-right">
<div className="text-2xl font-bold text-white">
{challenge.challengerScore} - {challenge.opponentScore}
</div>
</div>
</div>
<div className="flex gap-2">
<div className="flex-1 bg-gray-700 rounded-lg p-3 text-center">
<div className="text-sm text-gray-400">Win Rate</div>
<div className="text-lg font-bold text-celo-green">
{challenge.challengerWinRate}%
</div>
</div>
<div className="flex-1 bg-gray-700 rounded-lg p-3 text-center">
<div className="text-sm text-gray-400">Win Rate</div>
<div className="text-lg font-bold text-celo-yellow">
{challenge.opponentWinRate}%
</div>
</div>
</div>
</div>
))}
</div>
</div>
{/* Create Challenge */}
<div className="bg-gradient-to-r from-celo-green/20 to-celo-yellow/20 border-2 border-celo-green rounded-xl p-6">
<h2 className="text-xl font-bold text-white mb-2">Challenge a Friend</h2>
<p className="text-gray-300 mb-4">
Compete head-to-head on the next 5 polls. Best predictor wins!
</p>
<button className="bg-celo-green text-white px-6 py-3 rounded-xl font-semibold hover:bg-celo-green/90">
Create Challenge
</button>
</div>
</div>
</div>
)
}