From 84ddf9ed9cd40acc3efe02912a00471978476f78 Mon Sep 17 00:00:00 2001 From: Matevz Date: Fri, 3 Jan 2025 23:06:06 +0100 Subject: [PATCH] #PrivateLobbies - added copy invite link. --- .../_subcomponents/SetUpCard/SetUpCard.tsx | 127 +++++++++++------- 1 file changed, 82 insertions(+), 45 deletions(-) diff --git a/src/app/_components/Lobby/_subcomponents/SetUpCard/SetUpCard.tsx b/src/app/_components/Lobby/_subcomponents/SetUpCard/SetUpCard.tsx index 28f58abb..74af1e71 100644 --- a/src/app/_components/Lobby/_subcomponents/SetUpCard/SetUpCard.tsx +++ b/src/app/_components/Lobby/_subcomponents/SetUpCard/SetUpCard.tsx @@ -5,7 +5,7 @@ import { Typography, TextField, Button, - Box, CardActions, Link, FormControl, + Box, CardActions, Link, FormControl, Tooltip, } from '@mui/material'; import { useGame } from '@/app/_contexts/Game.context'; import { useRouter } from 'next/navigation' @@ -19,8 +19,10 @@ const SetUpCard: React.FC = ({ }) => { const { lobbyState, connectedPlayer, sendLobbyMessage } = useGame(); const [deckLink, setDeckLink] = useState(''); + const [showTooltip, setShowTooltip] = useState(false); const opponentUser = lobbyState ? lobbyState.users.find((u: ILobbyUserProps) => u.id !== connectedPlayer) : null; - const currentUser = lobbyState ? lobbyState.users.find((u: ILobbyUserProps) => u.id === connectedPlayer) : null; + const connectedUser = lobbyState ? lobbyState.users.find((u: ILobbyUserProps) => u.id === connectedPlayer) : null; + // Extract the player from the URL query params const router = useRouter(); @@ -34,6 +36,15 @@ const SetUpCard: React.FC = ({ const deckData = deckLink ? await fetchDeckData(deckLink) : null; sendLobbyMessage(['changeDeck',deckData]) } + const handleCopyLink = () => { + navigator.clipboard.writeText(lobbyState.connectionLink) + .then(() => { + setShowTooltip(true); + // Hide the tooltip after 1 second + setTimeout(() => setShowTooltip(false), 1000); + }) + .catch(err => console.error('Failed to copy link', err)); + }; // ------------------------STYLES------------------------// const styles = { @@ -117,8 +128,9 @@ const SetUpCard: React.FC = ({ Set Up + {!opponentUser ? ( - // If opponent is null, show "Waiting for an opponent" UI + // If opponent is null, show "Waiting for an opponent" UI @@ -126,16 +138,28 @@ const SetUpCard: React.FC = ({ - - + + + + ) : ( - // If opponent is not null + // If opponent is not null <> {readyStatus && opponentUser.ready && owner ? ( - - /* Both are ready */ + // Both are ready <> @@ -156,47 +180,60 @@ const SetUpCard: React.FC = ({ ) : ( - - /* Not both ready — show toggle-ready button */ - - - - + // Not both ready — show toggle-ready button + !connectedUser.deck ? ( + Please import a deck + ) : ( + + + + + ) )} )} - {lobbyState && lobbyState.privacy === 'Private' && <> - - - SWUDB - {' '} - or{' '} - - SW-Unlimited-DB - {' '} - Deck Link{' '} - - (use the URL or 'Deck Link' button) - - - ) => - setDeckLink(e.target.value) - } - /> - - } + + {lobbyState && lobbyState.privacy === 'Private' && ( + <> + + + SWUDB + {' '} + or{' '} + + SW-Unlimited-DB + {' '} + Deck Link{' '} + + (use the URL or 'Deck Link' button) + + + ) => setDeckLink(e.target.value)} + /> + + + )} - ); + ) }; export default SetUpCard;