Skip to content

Commit

Permalink
Create call to action card component. Add cta cards to home page for …
Browse files Browse the repository at this point in the history
…each game
  • Loading branch information
SmileyJames committed Jun 27, 2021
1 parent 1e88f36 commit e104328
Show file tree
Hide file tree
Showing 12 changed files with 85 additions and 5 deletions.
18 changes: 18 additions & 0 deletions app/src/Home.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import JoinForm from "components/join-form";
import HostForm from "components/host-form";
import NavBar from "components/navbar";
import TypedBanner from "components/typed-banner";
import CallToActionCard from "components/cta-card"

const Home = () => {
const { push } = useHistory();
Expand Down Expand Up @@ -38,6 +39,23 @@ const Home = () => {
<JoinForm onJoinGame={onJoinGame} />
</Flex>
<TypedBanner typedSentences={typedSentences}/>
<Flex justifyContent="space-around" flexDirection="row" flexWrap="wrap">
{
compendium.map(
({ name, image, description }, index) => (
<CallToActionCard
size={index === 0 ? 2 : 1}
headingText={name}
imageSrc={image.src}
imageAlt={image.alt}
bodyText={description}
onCallToAction={() => onNewGame(index)}
buttonLabel={`Start ${name}`}
/>
)
)
}
</Flex>
</>
)
}
Expand Down
4 changes: 2 additions & 2 deletions app/src/compendium.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ import HotPotato from "games/hot-potato";
import Chess from "games/chess";

const compendium = [
Chess,
TicTacToe,
Whist,
HotPotato,
Chess,
Whist,
];

export default compendium;
44 changes: 44 additions & 0 deletions app/src/components/cta-card/CallToActionCard.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import { Button, Box, Text, Card, Image, Heading, Flex } from "rebass/styled-components";

const sizeToLeftWidth = (sizeNum) => {
if (sizeNum > 1) return ["20em", "22em"];
return ["14em", "16em"];
}

const sizeToRightWidth = (sizeNum) => {
if (sizeNum > 1) return ["14em", "16em"];
return ["10em", "12em"];
}

const CallToActionCard = ({
size = 1,
imageSrc,
imageAlt,
headingText,
bodyText,
onCallToAction,
buttonLabel
}) => (
<Card m={3}>
<Flex flexDirection="row" height="100%">
<Flex width={sizeToLeftWidth(size)} backgroundColor="gray" alignItems="center" justifyContent="center" m={3}>
<Image src={imageSrc} alt={imageAlt} />
</Flex>
<Box width={sizeToRightWidth(size)} m={3} pt={2}>
<Heading>{headingText}</Heading>
<Text>{bodyText}</Text>
<Flex justifyContent="end" mt={3}>
<Button
onClick={onCallToAction}
onKeyPress={onCallToAction}
variant="primary"
>
{buttonLabel}
</Button>
</Flex>
</Box>
</Flex>
</Card>
);

export default CallToActionCard;
2 changes: 2 additions & 0 deletions app/src/components/cta-card/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
import CallToActionCard from "./CallToActionCard";
export default CallToActionCard;
Binary file added app/src/games/chess/chess.jpg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 5 additions & 1 deletion app/src/games/chess/index.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
import game from "./game";
import { Host, Guest } from "./client";
import presetTheme from '@rebass/preset'
import thumbnail from "./chess.jpg"

const name = "Chess";
const theme = presetTheme;

const Chess = { name, theme, Host, Guest, game };
const description = "Chess is a recreational and competitive board game played between two players.";
const image = { alt: "A chess board", src: thumbnail }

const Chess = { name, theme, image, description, Host, Guest, game };

export default Chess;
Binary file added app/src/games/hot-potato/hot-potato.jpg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 6 additions & 0 deletions app/src/games/hot-potato/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,18 @@ import game from "./game";
import { Host, Guest } from "./client";
import presetTheme from '@rebass/preset'
import { withPlayers } from "components/players"
import thumbnail from "./hot-potato.jpg"

const name = "Hot Potato";
const theme = presetTheme;

const description = "Pass the potato to your friends."
const image = { alt: "A potato", src: thumbnail }

const HotPotato = withPlayers({ maxPlayers: 16, minPlayers: 2 }, {
name,
description,
image,
theme,
Host,
Guest,
Expand Down
5 changes: 4 additions & 1 deletion app/src/games/tic-tac-toe/index.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
import game from "./game";
import { Host, Guest } from "./client";
import thumbnail from "./tic-tac-toe.jpg";

const name = "Tic Tac Toe";
const description = "a paper-and-pencil game for two players, X and O, who take turns marking the spaces in a 3×3 grid."
const image = { alt: "tic tac toe", src: thumbnail }

const TicTacToe = { name, Host, Guest, game };
const TicTacToe = { name, description, image, Host, Guest, game };

export default TicTacToe;
Binary file added app/src/games/tic-tac-toe/tic-tac-toe.jpg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 4 additions & 1 deletion app/src/games/whist/index.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
import { withPlayers } from "components/players";
import game from "./game";
import { Host, Guest } from "./client";
import thumbnail from "./whist.jpg";

const name = "Whist";
const description = "Whist is a classic English trick-taking card game which was widely played in the 18th and 19th centuries."
const image = { alt: "whist game", src: thumbnail }

const playersOptions = { minPlayers: 4, maxPlayers: 4 }

const Whist = withPlayers(playersOptions, { name, Host, Guest, game });
const Whist = withPlayers(playersOptions, { name, description, image, Host, Guest, game });

export default Whist;
Binary file added app/src/games/whist/whist.jpg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit e104328

Please sign in to comment.