Skip to content

Commit

Permalink
Server: Implement doSendEventsnFunction
Browse files Browse the repository at this point in the history
Work On doSendEvent Function that send event if response object is available.

Fixes #61
  • Loading branch information
sksmagr23 authored and asmit27rai committed Jun 6, 2024
1 parent 9360849 commit 084b39d
Show file tree
Hide file tree
Showing 7 changed files with 258 additions and 19 deletions.
1 change: 1 addition & 0 deletions backend/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 7 additions & 3 deletions backend/src/eventRecipients.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,11 @@ export function scheduleSend(clientId: ClientId, event: AppEvent) {
//todo: Enqueue the event for sending.
}

// eslint-disable-next-line @typescript-eslint/no-unused-vars
export function doSendEvent(clientId: ClientId) {
//todo: Send all the events in the queue to the client, only if the response object is available.
export function doSendEvents(clientId: ClientId) {
const res = clients.get(clientId);
const events = eventQueue.get(clientId) || [];
if (res && events.length > 0) {
res.json({ events });
eventQueue.set(clientId, []);
}
}
175 changes: 175 additions & 0 deletions frontend/public/UNO_Logo.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions frontend/src/index.css
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
@tailwind base;
@tailwind components;
@tailwind utilities;

body::-webkit-scrollbar {
display: none;
}
9 changes: 8 additions & 1 deletion frontend/src/library/button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,14 @@ type ButtonProps = {
};

function Button({ onClick, children }: ButtonProps) {
return <button onClick={onClick}>{children}</button>;
return (
<button
className="text-white bg-red-600 px-5 py-2 rounded-3xl text-md shadow-md transform transition-transform hover:scale-105 hover:shadow-glow hover:bg-red-900 active:bg-black active:scale-95 active:shadow-none"
onClick={onClick}
>
{children}
</button>
);
}

export default Button;
13 changes: 13 additions & 0 deletions frontend/src/library/heading.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
type InputProps = {
name?: string;
};

const heading = ({ name }: InputProps) => {
return (
<div>
<h1 className="text-white text-3xl font-bold font-serif">{name}</h1>
</div>
);
};

export default heading;
65 changes: 50 additions & 15 deletions frontend/src/pages/PlayOptions.tsx
Original file line number Diff line number Diff line change
@@ -1,26 +1,61 @@
import { useState } from 'react';
import { useNavigate } from 'react-router-dom';
import Input from '../library/input';
import Button from '../library/button';
import Heading from '../library/heading';
import '../index.css';

function PlayOptions() {
const PlayOptions = () => {
const [gameCode, setGameCode] = useState('');
const navigate = useNavigate();
function handleCreateGame() {
console.log('Creating a new game');
const CreateGame = () => {
// Logic to create a game
console.log('Create Game');
navigate('/game');
}
};

const JoinGame = () => {
// Logic to join a game
console.log('Join Game with code:', gameCode);
};

return (
<>
<div>
<h1>Create a new game</h1>
<Button onClick={handleCreateGame}>Create game</Button>
</div>
<div>
<h1>Join a game</h1>
<Input placeholder="Enter game code" />
<div className="flex flex-col items-center justify-center h-screen bg-gradient-to-r from-neutral-950 via-red-950 to-neutral-950">
<div className="max-h-screen w-screen max-w-screen-md p-1 md:items-center md:justify-center">
<div className="flex items-center justify-center p-3 mb-10 ">
<img
src="/UNO_Logo.svg"
alt="UNO Logo"
className="h-12 w-auto mr-2"
/>
<h1 className="text-white text-4xl font-bold font-serif">
Ready for Action?
</h1>
</div>
<div className="flex flex-col md:flex-row w-full md:max-w-screen-md space-y-10 md:space-y-0 md:space-x-10 p-10">
<div className="bg-gradient-to-r from-red-900 via-blue-950 to-red-900 flex-1 w-full p-5 border-2 border-spacing-2 border-opacity-80 border-red-950 rounded-xl shadow-md flex flex-col items-center">
<div className="pb-12 pt-3">
<Heading name="Create a new game" />
</div>
<Button onClick={CreateGame}>New Game</Button>
</div>
<div className="bg-gradient-to-r from-red-900 via-green-950 to-red-900 flex-1 w-full p-3 border-2 border-spacing-2 border-opacity-80 border-red-950 rounded-xl shadow-md flex flex-col items-center">
<div className="pt-2 pb-2">
<Heading name="Join an existing Game" />
</div>
<div className="p-2 pb-2 w-full justify-self-center">
<input
placeholder="Enter the Game Code"
value={gameCode}
onChange={(e) => setGameCode(e.target.value)}
className="border-2 border-red-600 rounded-lg p-1 mb-4 text-md w-full bg-black text-white"
/>
</div>
<Button onClick={JoinGame}>Join Game</Button>
</div>
</div>
</div>
</>
</div>
);
}
};

export default PlayOptions;

0 comments on commit 084b39d

Please sign in to comment.