Procházet zdrojové kódy

Implementing generationMethod on the UI

Kirk Trombley před 5 roky
rodič
revize
7b2e66fdc6

+ 12 - 1
client/src/components/util/GameCreationForm.jsx

@@ -5,6 +5,7 @@ import Loading from "./Loading";
 import Button from "./Button";
 import { createGame } from "../../domain/apiMethods";
 import Dropdown from "./Dropdown";
+import { MAP_CRUNCH, RANDOM_STREET_VIEW } from "../../domain/genMethods";
 
 const Container = styled.div`
   display: flex;
@@ -32,6 +33,7 @@ export default ({ afterCreate }) => {
   const [timer, setTimer] = useState(300);
   const [rounds, setRounds] = useState(5);
   const [onlyAmerica, setOnlyAmerica] = useState(false);
+  const [genMethod, setGenMethod] = useState(MAP_CRUNCH);
 
   if (loading) {
     return <Loading/>
@@ -39,7 +41,7 @@ export default ({ afterCreate }) => {
 
   const onCreateGame = async () => {
     setLoading(true);
-    const gameId = await createGame(timer, rounds, onlyAmerica);
+    const gameId = await createGame(timer, rounds, onlyAmerica, genMethod);
     if (afterCreate) {
       afterCreate(gameId);
     }
@@ -79,6 +81,15 @@ export default ({ afterCreate }) => {
         >
           {onlyAmerica ? "Just America" : "All Countries" }
         </Dropdown>
+        <Dropdown
+          options={{
+            "Map Crunch": MAP_CRUNCH,
+            "Random Street View": RANDOM_STREET_VIEW,
+          }}
+          onChange={setGenMethod}
+        >
+          Generator: {genMethod === MAP_CRUNCH ? "Map Crunch" : "RSV" }
+        </Dropdown>
       </DropdownContainer>
       <StartButton onClick={onCreateGame}>
         Create New Game

+ 2 - 2
client/src/domain/apiMethods.js

@@ -26,13 +26,13 @@ export const checkScore = async (point1, point2) => {
     return await res.json();
 }
 
-export const createGame = async (timer, rounds, onlyAmerica) => {
+export const createGame = async (timer, rounds, onlyAmerica, generationMethod) => {
     const res = await fetch(`${API_BASE}/game`, {
         method: "PUT",
         headers: {
             "Content-Type": "application/json",
         },
-        body: JSON.stringify({ timer, rounds, onlyAmerica }),
+        body: JSON.stringify({ timer, rounds, onlyAmerica, generationMethod }),
     });
     if (!res.ok) {
         throw Error(res.statusText);

+ 2 - 0
client/src/domain/genMethods.js

@@ -0,0 +1,2 @@
+export const MAP_CRUNCH = "MAPCRUNCH"
+export const RANDOM_STREET_VIEW = "RANDOMSTREETVIEW"