Moved join screen to a modal
This commit is contained in:
parent
bcf9f94c24
commit
5c0272fc2d
@ -5,7 +5,6 @@ import { HashRouter as Router, Switch, Route } from "react-router-dom";
|
|||||||
import theme from "./theme.js";
|
import theme from "./theme.js";
|
||||||
import Home from "./routes/Home";
|
import Home from "./routes/Home";
|
||||||
import Game from "./routes/Game";
|
import Game from "./routes/Game";
|
||||||
import Join from "./routes/Join";
|
|
||||||
import About from "./routes/About";
|
import About from "./routes/About";
|
||||||
import FAQ from "./routes/FAQ";
|
import FAQ from "./routes/FAQ";
|
||||||
|
|
||||||
@ -20,9 +19,6 @@ function App() {
|
|||||||
<Route path="/faq">
|
<Route path="/faq">
|
||||||
<FAQ />
|
<FAQ />
|
||||||
</Route>
|
</Route>
|
||||||
<Route path="/join">
|
|
||||||
<Join />
|
|
||||||
</Route>
|
|
||||||
<Route path="/game/:id">
|
<Route path="/game/:id">
|
||||||
<Game />
|
<Game />
|
||||||
</Route>
|
</Route>
|
||||||
|
@ -2,7 +2,7 @@ import React from "react";
|
|||||||
import Modal from "react-modal";
|
import Modal from "react-modal";
|
||||||
import { useThemeUI, Close } from "theme-ui";
|
import { useThemeUI, Close } from "theme-ui";
|
||||||
|
|
||||||
function StyledModal({ isOpen, onRequestClose, children }) {
|
function StyledModal({ isOpen, onRequestClose, children, ...props }) {
|
||||||
const { theme } = useThemeUI();
|
const { theme } = useThemeUI();
|
||||||
|
|
||||||
return (
|
return (
|
||||||
@ -22,6 +22,7 @@ function StyledModal({ isOpen, onRequestClose, children }) {
|
|||||||
maxHeight: "100%",
|
maxHeight: "100%",
|
||||||
},
|
},
|
||||||
}}
|
}}
|
||||||
|
{...props}
|
||||||
>
|
>
|
||||||
{children}
|
{children}
|
||||||
<Close
|
<Close
|
||||||
|
@ -1,10 +1,10 @@
|
|||||||
import React, { useState } from "react";
|
import React, { useState, useRef } from "react";
|
||||||
import { Box, Label, Input, Button, Flex } from "theme-ui";
|
import { Box, Label, Input, Button, Flex } from "theme-ui";
|
||||||
import { useHistory } from "react-router-dom";
|
import { useHistory } from "react-router-dom";
|
||||||
|
|
||||||
import Footer from "../components/Footer";
|
import Modal from "../components/Modal";
|
||||||
|
|
||||||
function Join() {
|
function JoinModal({ isOpen, onRequestClose }) {
|
||||||
let history = useHistory();
|
let history = useHistory();
|
||||||
const [gameId, setGameId] = useState("");
|
const [gameId, setGameId] = useState("");
|
||||||
|
|
||||||
@ -17,14 +17,16 @@ function Join() {
|
|||||||
history.push(`/game/${gameId}`);
|
history.push(`/game/${gameId}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const inputRef = useRef();
|
||||||
|
function focusInput() {
|
||||||
|
inputRef.current && inputRef.current.focus();
|
||||||
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Flex
|
<Modal
|
||||||
sx={{
|
isOpen={isOpen}
|
||||||
flexDirection: "column",
|
onRequestClose={onRequestClose}
|
||||||
justifyContent: "space-between",
|
onAfterOpen={focusInput}
|
||||||
minHeight: "100%",
|
|
||||||
alignItems: "center",
|
|
||||||
}}
|
|
||||||
>
|
>
|
||||||
<Flex
|
<Flex
|
||||||
sx={{
|
sx={{
|
||||||
@ -33,7 +35,7 @@ function Join() {
|
|||||||
maxWidth: "300px",
|
maxWidth: "300px",
|
||||||
flexGrow: 1,
|
flexGrow: 1,
|
||||||
}}
|
}}
|
||||||
mb={2}
|
m={2}
|
||||||
>
|
>
|
||||||
<Box as="form" onSubmit={handleSubmit}>
|
<Box as="form" onSubmit={handleSubmit}>
|
||||||
<Label htmlFor="id">Let me see your identification</Label>
|
<Label htmlFor="id">Let me see your identification</Label>
|
||||||
@ -44,13 +46,13 @@ function Join() {
|
|||||||
name="id"
|
name="id"
|
||||||
value={gameId || ""}
|
value={gameId || ""}
|
||||||
onChange={handleChange}
|
onChange={handleChange}
|
||||||
|
ref={inputRef}
|
||||||
/>
|
/>
|
||||||
<Button disabled={!gameId}>Join › (ノ◕ヮ◕)ノ*:・゚✧</Button>
|
<Button disabled={!gameId}>Join › (ノ◕ヮ◕)ノ*:・゚✧</Button>
|
||||||
</Box>
|
</Box>
|
||||||
</Flex>
|
</Flex>
|
||||||
<Footer />
|
</Modal>
|
||||||
</Flex>
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
export default Join;
|
export default JoinModal;
|
@ -1,10 +1,12 @@
|
|||||||
import React from "react";
|
import React, { useState } from "react";
|
||||||
import { Flex, Button, Image, Text } from "theme-ui";
|
import { Flex, Button, Image, Text } from "theme-ui";
|
||||||
import shortid from "shortid";
|
import shortid from "shortid";
|
||||||
import { useHistory } from "react-router-dom";
|
import { useHistory } from "react-router-dom";
|
||||||
|
|
||||||
import Footer from "../components/Footer";
|
import Footer from "../components/Footer";
|
||||||
|
|
||||||
|
import JoinModal from "../modals/JoinModal";
|
||||||
|
|
||||||
import owlington from "../images/Owlington.png";
|
import owlington from "../images/Owlington.png";
|
||||||
|
|
||||||
function Home() {
|
function Home() {
|
||||||
@ -13,9 +15,7 @@ function Home() {
|
|||||||
history.push(`/game/${shortid.generate()}`);
|
history.push(`/game/${shortid.generate()}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
function handleJoinGame() {
|
const [isJoinModalOpen, setIsJoinModalOpen] = useState(false);
|
||||||
history.push("/join");
|
|
||||||
}
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Flex
|
<Flex
|
||||||
@ -42,12 +42,16 @@ function Home() {
|
|||||||
<Button m={2} onClick={handleStartGame}>
|
<Button m={2} onClick={handleStartGame}>
|
||||||
Start Game
|
Start Game
|
||||||
</Button>
|
</Button>
|
||||||
<Button m={2} onClick={handleJoinGame}>
|
<Button m={2} onClick={() => setIsJoinModalOpen(true)}>
|
||||||
Join Game
|
Join Game
|
||||||
</Button>
|
</Button>
|
||||||
<Text variant="caption" as="p" sx={{ textAlign: "center" }}>
|
<Text variant="caption" as="p" sx={{ textAlign: "center" }}>
|
||||||
Alpha v0.8.0
|
Alpha v0.8.0
|
||||||
</Text>
|
</Text>
|
||||||
|
<JoinModal
|
||||||
|
isOpen={isJoinModalOpen}
|
||||||
|
onRequestClose={() => setIsJoinModalOpen(false)}
|
||||||
|
/>
|
||||||
</Flex>
|
</Flex>
|
||||||
<Footer />
|
<Footer />
|
||||||
</Flex>
|
</Flex>
|
||||||
|
Loading…
Reference in New Issue
Block a user