Skip to content

Commit

Permalink
Update UI
Browse files Browse the repository at this point in the history
  • Loading branch information
SuveenE committed Jan 17, 2025
1 parent 6fe9c77 commit af9fe77
Show file tree
Hide file tree
Showing 6 changed files with 549 additions and 95 deletions.
10 changes: 5 additions & 5 deletions app/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import GitHubLink from "@/components/GitHubLink";
import CustomGameDialog from "@/components/CustomGameDialog";
import { Switch } from "@/components/ui/switch";
import { WORD_LIST } from "@/data/wordsList";
import testGame from "@/data/testGame.json";
import testGame from "@/data/testGame2.json";
import { ClueResponse, GuessResponse } from "@/types/requests";

export default function Home() {
Expand Down Expand Up @@ -362,10 +362,6 @@ export default function Home() {

// Replay each turn
for (const turn of testGame.history) {
if (window.innerWidth < 768) {
window.scrollBy({ top: 100, behavior: "smooth" });
}

setGameState((prev) => {
if (!prev) return prev;

Expand All @@ -391,6 +387,10 @@ export default function Home() {
(word) => word.toLowerCase() === guess.word.toLowerCase(),
);

if (window.innerWidth < 768) {
window.scrollBy({ top: 200, behavior: "smooth" });
}

if (cardIndex !== -1) {
setGameState((prev) => {
if (!prev) return prev;
Expand Down
253 changes: 163 additions & 90 deletions components/GameHistory.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
"use client";

import { GameTurn } from "@/types/game";
import { useEffect, useState } from "react";
import { Button } from "@/components/ui/button";
import { cn } from "@/lib/utils";

interface GameHistoryProps {
history: GameTurn[];
Expand All @@ -7,10 +12,17 @@ interface GameHistoryProps {

export default function GameHistory({ history, winner }: GameHistoryProps) {
const redTurns = history.filter((turn) => turn.team === "red");
const [selectedRedTurn, setSelectedRedTurn] = useState<number>(0);
const [selectedBlueTurn, setSelectedBlueTurn] = useState<number>(0);
const blueTurns = history.filter((turn) => turn.team === "blue");

useEffect(() => {
setSelectedRedTurn(redTurns.length - 1);
setSelectedBlueTurn(blueTurns.length - 1);
}, [history]);

return (
<div className="bg-neutral-100 rounded-lg p-4 h-fit overflow-y-auto min-w-[360px] md:min-w-[500px]">
<div className="bg-neutral-100 rounded-lg p-4 h-fit min-w-[360px] md:min-w-[500px]">
<h2 className="text-md font-bold mb-4 text-neutral-800">Game History</h2>
{winner && (
<div
Expand All @@ -23,109 +35,170 @@ export default function GameHistory({ history, winner }: GameHistoryProps) {
{winner.charAt(0).toUpperCase() + winner.slice(1)} Team Wins!
</div>
)}

<div className="grid grid-cols-2 gap-4">
<div className="space-y-1 text-[9px] md:text-xs">
<h3 className="font-semibold text-red-500 mb-2">Red Team</h3>
{redTurns.length > 0 ? (
redTurns.map((turn, index) => (
<div
key={index}
className="bg-white rounded-xl p-2 md:p-3 shadow-sm"
>
<div className="flex">
<div className="w-1.5 rounded mr-3 bg-red-500" />
<div className="">
<div className="flex items-center gap-2 mb-1">
<span className="font-semibold text-neutral-700">
Clue:
</span>
<span className="text-neutral-600">
{turn.clue.word} ({turn.clue.number})
</span>
</div>
<div className="flex gap-2 items-center">
<span className="font-semibold text-neutral-700">
Guesses:
</span>
<div className="flex flex-wrap gap-2 max-w-[120px] md:max-w-full">
{turn.guesses.map((guess, guessIndex) => (
<span
key={guessIndex}
className="flex items-center gap-1 text-neutral-600"
>
{guess.word}
{guess.word === "SKIP" ? (
<span>⏭️</span>
) : guess.wasCorrect ? (
<span className="text-emerald-500"></span>
) : (
<span className="text-red-500"></span>
)}
<div className="max-w-[200px] md:max-w-[300px]">
<div className="mb-1 md:mb-4">
<h3 className="font-semibold text-red-500 mb-2 text-sm md:text-base">
Red Team
</h3>
<div className="flex gap-2 overflow-x-auto pb-2">
{redTurns.map((_, index) => (
<Button
key={index}
variant={selectedRedTurn === index ? "default" : "outline"}
size="sm"
className={cn(
"rounded-full w-5 h-5 md:w-8 md:h-8 p-0 border-red-200 hover:bg-red-50 hover:text-red-600",
selectedRedTurn === index &&
"bg-red-500 hover:bg-red-500 hover:text-white",
)}
onClick={() => setSelectedRedTurn(index)}
aria-label={`View Red team turn ${index + 1}`}
>
{index + 1}
</Button>
))}
</div>
</div>
{redTurns.map((turn, index) => (
<div
key={index}
className={cn(
"bg-white rounded-xl p-3 shadow-sm border-l-4 border-red-500 mb-3",
selectedRedTurn === index ? "block" : "hidden",
)}
>
<div className="text-[8px] md:text-[11px]">
<div className="flex items-center justify-between mb-2">
<span className="font-bold text-red-500">
Turn #{index + 1}
</span>
</div>
<div className="flex flex-col gap-1 mb-2">
<div className="flex items-center gap-2">
<span className="font-semibold text-neutral-700">
Clue:
</span>
<span className="text-neutral-600 font-bold">
{turn.clue.word} ({turn.clue.number})
</span>
</div>
<p className="text-[8px] md:text-[11px] text-neutral-600">
{turn.clue.reasoning}
</p>
</div>
<div className="flex flex-col gap-1">
<span className="font-semibold text-neutral-700">
Guesses:
</span>
<div className="flex flex-wrap gap-1">
{turn.guesses.map((guess, guessIndex) => (
<div key={guessIndex} className="flex flex-col">
<span className="flex items-center gap-1 font-bold text-neutral-600">
{guess.word}
{guess.word === "SKIP" ? (
<span>⏭️</span>
) : guess.wasCorrect ? (
<span className="text-emerald-500"></span>
) : (
<span className="text-red-500"></span>
)}
</span>
{guess.reasoning && (
<span className="text-[8px] md:text-[11px] text-neutral-600">
{guess.reasoning}
</span>
))}
)}
</div>
</div>
))}
</div>
</div>
</div>
))
) : (
<div className="bg-white rounded-xl p-3 shadow-sm w-fit">
<div className="flex">
<div className="w-max rounded mr-3 bg-red-500" />
<div className="text-neutral-500 italic"></div>
</div>
</div>
)}
))}
</div>
<div className="space-y-1 text-[9px] md:text-xs">
<h3 className="font-semibold text-blue-500 mb-2">Blue Team</h3>
{blueTurns.length > 0 ? (
blueTurns.map((turn, index) => (
<div key={index} className="bg-white rounded-xl p-3 shadow-sm">
<div className="flex">
<div className="w-1.5 rounded mr-3 bg-blue-500" />
<div className="">
<div className="flex items-center gap-2 mb-1">
<span className="font-semibold text-neutral-700">
Clue:
</span>
<span className="text-neutral-600">
{turn.clue.word} ({turn.clue.number})
</span>
</div>
<div className="flex gap-2 items-center">
<span className="font-semibold text-neutral-700">
Guesses:
</span>
<div className="flex flex-wrap gap-2 max-w-[100px] md:max-w-full">
{turn.guesses.map((guess, guessIndex) => (
<span
key={guessIndex}
className="flex items-center gap-1 text-neutral-600"
>
{guess.word}
{guess.wasCorrect ? (
<span className="text-emerald-500"></span>
) : (
<span className="text-red-500"></span>
)}

<div className="max-w-[200px] md:max-w-[300px]">
<div className="mb-1 md:mb-4">
<h3 className="font-semibold text-blue-500 mb-2 text-sm md:text-base">
Blue Team
</h3>
<div className="flex gap-2 overflow-x-auto pb-2">
{blueTurns.map((_, index) => (
<Button
key={index}
variant={selectedBlueTurn === index ? "default" : "outline"}
size="sm"
className={cn(
"rounded-full w-5 h-5 md:w-8 md:h-8 p-0 border-blue-200 hover:bg-blue-50 hover:text-blue-600",
selectedBlueTurn === index &&
"bg-blue-500 hover:bg-blue-500 hover:text-white",
)}
onClick={() => setSelectedBlueTurn(index)}
aria-label={`View Blue team turn ${index + 1}`}
>
{index + 1}
</Button>
))}
</div>
</div>
{blueTurns.map((turn, index) => (
<div
key={index}
className={cn(
"bg-white rounded-xl p-3 shadow-sm border-l-4 border-blue-500 mb-3",
selectedBlueTurn === index ? "block" : "hidden",
)}
>
<div className="text-[8px] md:text-[11px]">
<div className="flex items-center justify-between mb-2">
<span className="font-bold text-blue-500">
Turn #{index + 1}
</span>
</div>
<div className="flex flex-col gap-1 mb-2">
<div className="flex items-center gap-1">
<span className="font-semibold text-neutral-700">
Clue:
</span>
<span className="text-neutral-600 font-bold">
{turn.clue.word} ({turn.clue.number})
</span>
</div>
<p className="text-[8px] md:text-[11px] text-neutral-600">
{turn.clue.reasoning}
</p>
</div>
<div className="flex flex-col gap-1">
<span className="font-semibold text-neutral-700">
Guesses:
</span>
<div className="flex flex-wrap gap-1">
{turn.guesses.map((guess, guessIndex) => (
<div key={guessIndex} className="flex flex-col">
<span className="flex items-center gap-1 font-bold text-neutral-600">
{guess.word}
{guess.word === "SKIP" ? (
<span>⏭️</span>
) : guess.wasCorrect ? (
<span className="text-emerald-500"></span>
) : (
<span className="text-red-500"></span>
)}
</span>
{guess.reasoning && (
<span className="text-[8px] md:text-[11px] text-neutral-600 ">
{guess.reasoning}
</span>
))}
)}
</div>
</div>
))}
</div>
</div>
</div>
))
) : (
<div className="bg-white rounded-xl p-3 shadow-sm w-fit">
<div className="flex">
<div className="w-1.5 rounded mr-3 bg-blue-500" />
<div className="text-neutral-500 italic"></div>
</div>
</div>
)}
))}
</div>
</div>
</div>
Expand Down
57 changes: 57 additions & 0 deletions components/ui/button.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import * as React from "react";
import { Slot } from "@radix-ui/react-slot";
import { cva, type VariantProps } from "class-variance-authority";

import { cn } from "@/lib/utils";

const buttonVariants = cva(
"inline-flex items-center justify-center gap-2 whitespace-nowrap rounded-md text-sm font-medium transition-colors focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring disabled:pointer-events-none disabled:opacity-50 [&_svg]:pointer-events-none [&_svg]:size-4 [&_svg]:shrink-0",
{
variants: {
variant: {
default:
"bg-primary text-primary-foreground shadow hover:bg-primary/90",
destructive:
"bg-destructive text-destructive-foreground shadow-sm hover:bg-destructive/90",
outline:
"border border-input bg-background shadow-sm hover:bg-accent hover:text-accent-foreground",
secondary:
"bg-secondary text-secondary-foreground shadow-sm hover:bg-secondary/80",
ghost: "hover:bg-accent hover:text-accent-foreground",
link: "text-primary underline-offset-4 hover:underline",
},
size: {
default: "h-9 px-4 py-2",
sm: "h-8 rounded-md px-3 text-xs",
lg: "h-10 rounded-md px-8",
icon: "h-9 w-9",
},
},
defaultVariants: {
variant: "default",
size: "default",
},
},
);

export interface ButtonProps
extends React.ButtonHTMLAttributes<HTMLButtonElement>,
VariantProps<typeof buttonVariants> {
asChild?: boolean;
}

const Button = React.forwardRef<HTMLButtonElement, ButtonProps>(
({ className, variant, size, asChild = false, ...props }, ref) => {
const Comp = asChild ? Slot : "button";
return (
<Comp
className={cn(buttonVariants({ variant, size, className }))}
ref={ref}
{...props}
/>
);
},
);
Button.displayName = "Button";

export { Button, buttonVariants };
Loading

0 comments on commit af9fe77

Please sign in to comment.