This commit is contained in:
Aidan Haas
2025-07-07 17:09:34 -04:00
commit 6b531bb32f
18 changed files with 2249 additions and 0 deletions
Binary file not shown.

After

Width:  |  Height:  |  Size: 25 KiB

+26
View File
@@ -0,0 +1,26 @@
@import "tailwindcss";
:root {
--background: #ffffff;
--foreground: #171717;
}
@theme inline {
--color-background: var(--background);
--color-foreground: var(--foreground);
--font-sans: var(--font-geist-sans);
--font-mono: var(--font-geist-mono);
}
@media (prefers-color-scheme: dark) {
:root {
--background: #0a0a0a;
--foreground: #ededed;
}
}
body {
background: var(--background);
color: var(--foreground);
font-family: Arial, Helvetica, sans-serif;
}
+34
View File
@@ -0,0 +1,34 @@
import type { Metadata } from "next";
import { Geist, Geist_Mono } from "next/font/google";
import "./globals.css";
const geistSans = Geist({
variable: "--font-geist-sans",
subsets: ["latin"],
});
const geistMono = Geist_Mono({
variable: "--font-geist-mono",
subsets: ["latin"],
});
export const metadata: Metadata = {
title: "Create Next App",
description: "Generated by create next app",
};
export default function RootLayout({
children,
}: Readonly<{
children: React.ReactNode;
}>) {
return (
<html lang="en">
<body
className={`${geistSans.variable} ${geistMono.variable} antialiased`}
>
{children}
</body>
</html>
);
}
+54
View File
@@ -0,0 +1,54 @@
'use client';
import { useEffect, useState } from 'react';
import io from 'socket.io-client';
const socket = io('http://localhost:8080');
export default function HomePage() {
const [currentPlayer, setCurrentPlayer] = useState<string | null>(null);
useEffect(() => {
socket.on('connect', () => {
console.log('Connected to Socket.IO server');
});
socket.on('player_update', (data: { nextPlayer: string }) => {
setCurrentPlayer(data.nextPlayer);
});
return () => {
socket.off('player_update');
};
}, []);
const advanceTurn = async () => {
await fetch('http://localhost:8080/next'); // triggers backend to emit event
};
return (
<main className="p-6">
<h1 className="text-2xl font-bold mb-4">Game Turn Tracker</h1>
<div className="mb-4">
{currentPlayer ? (
<p className="text-lg">
🎯 Current Player: <strong>{currentPlayer}</strong>
</p>
) : (
<p className="text-gray-500">Waiting for turn to start</p>
)}
</div>
<button
onClick={advanceTurn}
className="bg-blue-600 text-white px-4 py-2 rounded hover:bg-blue-700"
>
Next Player
</button>
</main>
);
}
+100
View File
@@ -0,0 +1,100 @@
'use client';
import Image from "next/image";
import { useRef, useState } from "react";
export default function Home() {
const nameInputRef = useRef<HTMLInputElement>(null);
const addPlayer = async () => {
const playerName = nameInputRef.current?.value?.trim();
if (!playerName) {
alert("Please enter a player name");
return;
}
try {
const res = await fetch('http://localhost:8080/add', {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ name: playerName, group: selectedGroup }),
});
if (!res.ok) {
throw new Error(`Server error: ${res.statusText}`);
}
if (nameInputRef.current) {
nameInputRef.current.value = "";
}
} catch (error) {
console.error("Failed to add player:", error);
}
};
const [selectedGroup, setSelectedGroup] = useState<"stripes" | "solids">("stripes");
return (
<div className="grid grid-rows-[20px_1fr_20px] items-center justify-items-center min-h-screen p-8 pb-20 gap-16 sm:p-20 font-[family-name:var(--font-geist-sans)]">
<main className="flex flex-col gap-[32px] row-start-2 items-center sm:items-start">
<div className="flex gap-8 mb-4">
<label className="flex items-center gap-2 cursor-pointer">
<input
type="radio"
name="group"
value="stripes"
checked={selectedGroup === "stripes"}
onChange={() => setSelectedGroup("stripes")}
className="cursor-pointer"
/>
Stripes
</label>
<label className="flex items-center gap-2 cursor-pointer">
<input
type="radio"
name="group"
value="solids"
checked={selectedGroup === "solids"}
onChange={() => setSelectedGroup("solids")}
className="cursor-pointer"
/>
Solids
</label>
</div>
<div className="flex gap-4 items-center flex-col sm:flex-row">
<input ref={nameInputRef} id="name" placeholder="Enter Name Here"></input>
<button
onClick={addPlayer}
className="rounded-full border border-solid border-transparent transition-colors flex items-center justify-center bg-foreground text-background gap-2 hover:bg-[#383838] dark:hover:bg-[#ccc] font-medium text-sm sm:text-base h-10 sm:h-12 px-4 sm:px-5 sm:w-auto">Add Player</button>
</div>
<div className="flex gap-4 items-center flex-col sm:flex-row">
<a
className="rounded-full border border-solid border-transparent transition-colors flex items-center justify-center bg-foreground text-background gap-2 hover:bg-[#383838] dark:hover:bg-[#ccc] font-medium text-sm sm:text-base h-10 sm:h-12 px-4 sm:px-5 sm:w-auto"
href="https://vercel.com/new?utm_source=create-next-app&utm_medium=appdir-template-tw&utm_campaign=create-next-app"
target="_blank"
rel="noopener noreferrer"
>
<Image
className="dark:invert"
src="/vercel.svg"
alt="Vercel logomark"
width={20}
height={20}
/>
Start Game
</a>
<a
className="rounded-full border border-solid border-black/[.08] dark:border-white/[.145] transition-colors flex items-center justify-center hover:bg-[#f2f2f2] dark:hover:bg-[#1a1a1a] hover:border-transparent font-medium text-sm sm:text-base h-10 sm:h-12 px-4 sm:px-5 w-full sm:w-auto md:w-[158px]"
href="https://nextjs.org/docs?utm_source=create-next-app&utm_medium=appdir-template-tw&utm_campaign=create-next-app"
target="_blank"
rel="noopener noreferrer"
>
Reset Game
</a>
</div>
</main>
</div>
);
}