diff --git a/components/HostView.tsx b/components/HostView.tsx index 8c46bd0..5bd83c5 100644 --- a/components/HostView.tsx +++ b/components/HostView.tsx @@ -1,8 +1,9 @@ import React, { useState } from 'react'; import { useGame } from '../context/GameContext'; -import { GamePhase, Game, Question } from '../types'; +import { GamePhase } from '../types'; +import type { Question } from '../types'; import { Soundboard } from './Soundboard'; -import { Play, SkipForward, CheckCircle, XCircle, Users, Library, Sparkles, Plus, Trash2, Edit, Save, ArrowLeft, Upload, RefreshCw, Image as ImageIcon, List, Trophy, RotateCcw } from 'lucide-react'; +import { Play, SkipForward, CheckCircle, XCircle, Users, Library, Sparkles, Plus, Trash2, Edit, ArrowLeft, Upload, RefreshCw, Image as ImageIcon, List, Trophy, RotateCcw } from 'lucide-react'; import { generateQuestions } from '../services/geminiService'; export const HostView: React.FC = () => { diff --git a/components/PlayerView.tsx b/components/PlayerView.tsx index 2eef2ad..d43357c 100644 --- a/components/PlayerView.tsx +++ b/components/PlayerView.tsx @@ -1,7 +1,8 @@ import React, { useState, useEffect } from 'react'; import { useGame } from '../context/GameContext'; import { GamePhase } from '../types'; -import { Trophy, Zap, Target, LogOut, Image as ImageIcon } from 'lucide-react'; +import type { Player } from '../types'; +import { Trophy, Zap, LogOut } from 'lucide-react'; export const PlayerView: React.FC = () => { const { gameState, players, teams, currentPlayerId, addPlayer, removePlayer, buzzQueue, handleBuzz, questions } = useGame(); @@ -149,7 +150,7 @@ export const PlayerView: React.FC = () => { if (gameState.phase === GamePhase.FINAL_STATS) { const winningTeam = sortedTeams[0]; - let fastestPlayer = null; + let fastestPlayer: Player | null = null; let fastestTime = Infinity; players.forEach(p => { if (p.stats.bestReactionTime && p.stats.bestReactionTime < fastestTime) { @@ -188,7 +189,7 @@ export const PlayerView: React.FC = () => {
Fastest Buzzer
-
{fastestPlayer.name}
+
{(fastestPlayer as Player).name}
{(fastestTime / 1000).toFixed(2)}s reaction
@@ -227,6 +228,8 @@ export const PlayerView: React.FC = () => { ); } + const isGameActive = gameState.phase !== GamePhase.LOBBY && gameState.phase !== GamePhase.LEADERBOARD; + // --- REGULAR GAMEPLAY UI --- return (
@@ -259,7 +262,7 @@ export const PlayerView: React.FC = () => {
{/* Dynamic Question Text & Media on Mobile */} - {gameState.phase !== GamePhase.LOBBY && gameState.phase !== GamePhase.LEADERBOARD && gameState.phase !== GamePhase.FINAL_STATS && currentQ && ( + {isGameActive && currentQ && (

Current Question

diff --git a/components/SpectatorView.tsx b/components/SpectatorView.tsx index 2436db0..a4d0814 100644 --- a/components/SpectatorView.tsx +++ b/components/SpectatorView.tsx @@ -1,6 +1,7 @@ import React from 'react'; import { useGame } from '../context/GameContext'; import { GamePhase } from '../types'; +import type { Player } from '../types'; import { BarChart, Bar, XAxis, YAxis, Tooltip, ResponsiveContainer, Cell } from 'recharts'; import { Trophy, Zap, Users } from 'lucide-react'; @@ -126,7 +127,7 @@ export const SpectatorView: React.FC = () => { - {leaderboardData.map((entry, index) => ( + {leaderboardData.map((_entry, index) => ( ))} @@ -145,7 +146,7 @@ export const SpectatorView: React.FC = () => { const topPlayers = [...players].sort((a,b) => b.score - a.score).slice(0, 5); // Fastest Buzzer Calculation - let fastestPlayer = null; + let fastestPlayer: Player | null = null; let fastestTime = Infinity; players.forEach(p => { if (p.stats.bestReactionTime && p.stats.bestReactionTime < fastestTime) { @@ -202,7 +203,7 @@ export const SpectatorView: React.FC = () => {
Fastest Finger
-
{fastestPlayer?.name || '-'}
+
{(fastestPlayer as Player)?.name || '-'}
diff --git a/context/GameContext.tsx b/context/GameContext.tsx index 5ce236f..9952f27 100644 --- a/context/GameContext.tsx +++ b/context/GameContext.tsx @@ -1,5 +1,6 @@ -import React, { createContext, useContext, useState, useEffect, useCallback } from 'react'; -import { GamePhase, Player, Team, Question, BuzzerLog, GameState, Game } from '../types'; +import React, { createContext, useContext, useState, useEffect } from 'react'; +import { GamePhase } from '../types'; +import type { Player, Team, Question, BuzzerLog, GameState, Game } from '../types'; interface GameContextType { // State diff --git a/services/geminiService.ts b/services/geminiService.ts index 8bbcbba..3888486 100644 --- a/services/geminiService.ts +++ b/services/geminiService.ts @@ -1,5 +1,5 @@ import { GoogleGenAI, Type } from "@google/genai"; -import { Question } from "../types"; +import type { Question } from "../types"; const generateQuestions = async (topic: string, count: number = 5): Promise => { // Use process.env.API_KEY as per guidelines. diff --git a/types.ts b/types.ts index 434a6de..73899fb 100644 --- a/types.ts +++ b/types.ts @@ -1,13 +1,15 @@ -export enum GamePhase { - LOBBY = 'LOBBY', - COUNTDOWN = 'COUNTDOWN', - QUESTION_DISPLAY = 'QUESTION_DISPLAY', - BUZZER_OPEN = 'BUZZER_OPEN', - ADJUDICATION = 'ADJUDICATION', - ANSWER_REVEAL = 'ANSWER_REVEAL', - LEADERBOARD = 'LEADERBOARD', - FINAL_STATS = 'FINAL_STATS' -} +export const GamePhase = { + LOBBY: 'LOBBY', + COUNTDOWN: 'COUNTDOWN', + QUESTION_DISPLAY: 'QUESTION_DISPLAY', + BUZZER_OPEN: 'BUZZER_OPEN', + ADJUDICATION: 'ADJUDICATION', + ANSWER_REVEAL: 'ANSWER_REVEAL', + LEADERBOARD: 'LEADERBOARD', + FINAL_STATS: 'FINAL_STATS' +} as const; + +export type GamePhase = typeof GamePhase[keyof typeof GamePhase]; export interface PlayerStats { correctAnswers: number;