From a7108c300719647fb4b10f1bf9077cc3fd6eda1b Mon Sep 17 00:00:00 2001 From: VK-RED Date: Mon, 6 May 2024 22:30:38 +0530 Subject: [PATCH 1/6] modify JOIN_ROOM message type --- apps/ws/src/GameManager.ts | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/apps/ws/src/GameManager.ts b/apps/ws/src/GameManager.ts index 02703681..290a4ca9 100644 --- a/apps/ws/src/GameManager.ts +++ b/apps/ws/src/GameManager.ts @@ -82,6 +82,7 @@ export class GameManager { game.gameId, JSON.stringify({ type: GAME_ADDED, + gameId:game.gameId, }), ); } @@ -118,6 +119,14 @@ export class GameManager { }, }); + // There is a game created but no second player available + + if (availableGame && !availableGame.player2UserId) { + SocketManager.getInstance().addUser(user, availableGame.gameId); + await availableGame.updateSecondPlayer(user.userId); + return; + } + if (!gameFromDb) { user.socket.send( JSON.stringify({ From 81466da2f7a5bed790e490233ac75c531314c798 Mon Sep 17 00:00:00 2001 From: VK-RED Date: Mon, 6 May 2024 22:31:36 +0530 Subject: [PATCH 2/6] Create ShareGame Component --- apps/frontend/src/components/ShareGame.tsx | 43 ++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 apps/frontend/src/components/ShareGame.tsx diff --git a/apps/frontend/src/components/ShareGame.tsx b/apps/frontend/src/components/ShareGame.tsx new file mode 100644 index 00000000..bfd303a6 --- /dev/null +++ b/apps/frontend/src/components/ShareGame.tsx @@ -0,0 +1,43 @@ +import { useState } from "react" +import { Button } from "./Button"; + +export const ShareGame = ({className,gameId}:{className?:string,gameId:string}) => { + + const [url] = useState(window.origin+"/game/"+gameId); + const [copied,setCopied] = useState(false); + + const handleCopy = ()=>{ + window.navigator.clipboard.writeText(url); + setCopied((p)=>true); + } + + return ( +
+ +

+ Play with Friends +

+ +
+ + + +
+ {url} +
+
+ + +
+ ) +} + +const LinkSvg = () => { + return ( + + + + ) +} \ No newline at end of file From b7d9e24052522b5f00d54ae83b4b5b72755239fa Mon Sep 17 00:00:00 2001 From: VK-RED Date: Mon, 6 May 2024 22:32:24 +0530 Subject: [PATCH 3/6] Add utility class to hide scrollbar --- apps/frontend/src/index.css | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/apps/frontend/src/index.css b/apps/frontend/src/index.css index 65d47b14..c7300174 100644 --- a/apps/frontend/src/index.css +++ b/apps/frontend/src/index.css @@ -79,3 +79,14 @@ background-color: #302e2b; } +@layer utilities { + /* Hide scrollbar for Chrome, Safari and Opera */ + .no-scrollbar::-webkit-scrollbar { + display: none; + } + /* Hide scrollbar for IE, Edge and Firefox */ + .no-scrollbar { + -ms-overflow-style: none; /* IE and Edge */ + scrollbar-width: none; /* Firefox */ +} +} From a6c5972fa133ddb378147e11c75c72434b1e59e8 Mon Sep 17 00:00:00 2001 From: VK-RED Date: Mon, 6 May 2024 22:34:04 +0530 Subject: [PATCH 4/6] Add ShareGame component --- apps/frontend/src/screens/Game.tsx | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/apps/frontend/src/screens/Game.tsx b/apps/frontend/src/screens/Game.tsx index b6f8c0e4..2426dcee 100644 --- a/apps/frontend/src/screens/Game.tsx +++ b/apps/frontend/src/screens/Game.tsx @@ -40,6 +40,7 @@ import { useRecoilValue, useSetRecoilState } from 'recoil'; import { movesAtom, userSelectedMoveIndexAtom } from '@repo/store/chessBoard'; import GameEndModal from '@/components/GameEndModal'; +import { ShareGame } from '../components/ShareGame'; const moveAudio = new Audio(MoveSound); @@ -66,7 +67,7 @@ export const Game = () => { >(null); const [player1TimeConsumed, setPlayer1TimeConsumed] = useState(0); const [player2TimeConsumed, setPlayer2TimeConsumed] = useState(0); - + const [gameID,setGameID] = useState(""); const setMoves = useSetRecoilState(movesAtom); const userSelectedMoveIndex = useRecoilValue(userSelectedMoveIndexAtom); const userSelectedMoveIndexRef = useRef(userSelectedMoveIndex); @@ -90,6 +91,7 @@ export const Game = () => { switch (message.type) { case GAME_ADDED: setAdded(true); + setGameID((p)=>message.gameId); break; case INIT_GAME: setBoard(chess.board()); @@ -304,11 +306,15 @@ export const Game = () => { -
+
{!started && (
{added ? ( -
Waiting
+
+
Waiting
+ +
+ ) : ( gameId === 'random' && (