Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Url/react helmet #37

Merged
merged 2 commits into from
Mar 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions chess/package-lock.json

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

1 change: 1 addition & 0 deletions chess/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
"react": "^18.2.0",
"react-chessboard": "^4.5.0",
"react-dom": "^18.2.0",
"react-helmet": "^6.1.0",
"react-router-dom": "^6.22.3",
"react-scripts": "5.0.1",
"web-vitals": "^2.1.4"
Expand Down
133 changes: 73 additions & 60 deletions chess/src/pages/home/Home.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
} from "@chakra-ui/react";
import Cover from "../../data/pages/home/knight-chess.webp";
import { CreateRoom } from "../../utils/Room";
import { Helmet } from "react-helmet";

function PlayCard() {
const [showUrl, setShowUrl] = useState(false);
Expand Down Expand Up @@ -56,66 +57,78 @@ function PlayCard() {
};

return (
<Flex
width="100vw"
height="100vh"
justifyContent="center"
alignItems="center"
backgroundColor={"wheat"}
>
<Box w="500px" p={4} boxShadow="md" borderRadius="md" bg="white">
<VStack spacing={4}>
<Text fontSize="3xl" fontWeight="bold">
Select Game Mode:
</Text>
<Image
src={Cover}
boxSize="150px"
objectFit="cover"
alt="Chess"
transform="scaleX(-1)"
/>
<Button colorScheme="teal" onClick={showToast}>
Play vs CPU
</Button>
<Button
colorScheme="orange"
onClick={generateRoomUrl}
isDisabled={isLoading}
>
{isLoading ? <Spinner size="sm" /> : "Play vs a Friend"}
</Button>
{showUrl && (
<VStack spacing={2}>
{isLoading ? (
<Spinner size="md" />
) : (
<>
<Input
value={uniqueUrl}
isReadOnly
placeholder="Unique URL"
width="auto"
/>
<Button onClick={onCopy}>
{hasCopied ? "Copied" : "Copy URL"}
</Button>
<Text>Share the URL to play with your friend! :) </Text>
</>
)}
</VStack>
)}
<Box as="footer" width="full" padding="4" textAlign="center">
<Text>
Made with <span role="img" aria-label="heart">❤️</span> by
<Link href="https://github.com/jcari-dev" isExternal color="teal.500" marginLeft="1">
Jorge Caridad
</Link>
</Text>
</Box>
</VStack>
</Box>
</Flex>
<Helmet>
<meta name="description" content="Home Page - Welcome to Chess Arena!" />
<Flex
width="100vw"
height="100vh"
justifyContent="center"
alignItems="center"
backgroundColor={"wheat"}
>
<Box w="500px" p={4} boxShadow="md" borderRadius="md" bg="white">
<VStack spacing={4}>
<Text fontSize="3xl" fontWeight="bold">
Select Game Mode:
</Text>
<Image
src={Cover}
boxSize="150px"
objectFit="cover"
alt="Chess"
transform="scaleX(-1)"
/>
<Button colorScheme="teal" onClick={showToast}>
Play vs CPU
</Button>
<Button
colorScheme="orange"
onClick={generateRoomUrl}
isDisabled={isLoading}
>
{isLoading ? <Spinner size="sm" /> : "Play vs a Friend"}
</Button>
{showUrl && (
<VStack spacing={2}>
{isLoading ? (
<Spinner size="md" />
) : (
<>
<Input
value={uniqueUrl}
isReadOnly
placeholder="Unique URL"
width="auto"
/>
<Button onClick={onCopy}>
{hasCopied ? "Copied" : "Copy URL"}
</Button>
<Text>Share the URL to play with your friend! :) </Text>
</>
)}
</VStack>
)}
<Box as="footer" width="full" padding="4" textAlign="center">
<Text>
Made with{" "}
<span role="img" aria-label="heart">
❤️
</span>{" "}
by
<Link
href="https://github.com/jcari-dev"
isExternal
color="teal.500"
marginLeft="1"
>
Jorge Caridad
</Link>
</Text>
</Box>
</VStack>
</Box>
</Flex>
</Helmet>
);
}

Expand Down
63 changes: 35 additions & 28 deletions chess/src/pages/room/Room.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import axios from "axios";
import { JoinRoom } from "../../utils/Room";
import ChessBoard from "../../components/main/board/Board";
import endpoints from "../../utils/Endpoints";
import { Helmet } from "react-helmet";

function Room() {
const { roomId } = useParams();
Expand Down Expand Up @@ -55,36 +56,42 @@ function Room() {

return (
<div>
{isLoading ? (
<Center height="100vh">
<Box
textAlign="center"
padding="20px"
boxShadow="lg"
borderRadius="lg"
>
<Spinner size="xl" marginBottom="4" />
<Text fontSize="lg">Waiting for all players to join...</Text>
</Box>
</Center>
) : (
<div>
<ChessBoard
userId={userId}
otherPlayerId={otherPlayerId}
roomId={roomId}
/>
<Box display="flex" justifyContent="center">
<HStack spacing={4}>
<Tag colorScheme="blue">Your ID: {userId}</Tag>
<Helmet>
<meta
name="description"
content={`Let's play together, join my room now!`}
/>
{isLoading ? (
<Center height="100vh">
<Box
textAlign="center"
padding="20px"
boxShadow="lg"
borderRadius="lg"
>
<Spinner size="xl" marginBottom="4" />
<Text fontSize="lg">Waiting for all players to join...</Text>
</Box>
</Center>
) : (
<div>
<ChessBoard
userId={userId}
otherPlayerId={otherPlayerId}
roomId={roomId}
/>
<Box display="flex" justifyContent="center">
<HStack spacing={4}>
<Tag colorScheme="blue">Your ID: {userId}</Tag>

<Tag colorScheme="green">Room ID: {roomId}</Tag>
<Tag colorScheme="green">Room ID: {roomId}</Tag>

<Tag colorScheme="red">Opponent's ID: {otherPlayerId}</Tag>
</HStack>
</Box>
</div>
)}
<Tag colorScheme="red">Opponent's ID: {otherPlayerId}</Tag>
</HStack>
</Box>
</div>
)}
</Helmet>
</div>
);
}
Expand Down