Эх сурвалжийг харах

Refactor all API/enum constants into single module

Kirk Trombley 4 жил өмнө
parent
commit
a7607b5254

+ 1 - 1
client/src/App.jsx

@@ -14,7 +14,7 @@ import {
   POST_ROUND,
   PRE_GAME,
   PRE_ROUND,
-} from "./domain/gameStates";
+} from "./domain/constants";
 import { dispatch, useGameState } from "./domain/gameStore";
 import Loading from "./components/util/Loading";
 

+ 1 - 1
client/src/components/screens/GamePanel/GamePanel.jsx

@@ -1,4 +1,4 @@
-import { FROZEN, RACE } from "../../../domain/ruleSets";
+import { FROZEN, RACE } from "../../../domain/constants";
 import { useGameConfig } from "../../../hooks/useGameInfo";
 import usePreventNavigation from "../../../hooks/usePreventNavigation";
 import Loading from "../../util/Loading";

+ 1 - 1
client/src/components/screens/Lobby/Lobby.jsx

@@ -14,7 +14,7 @@ import {
   FROZEN,
   COUNTRY_RACE,
   RACE,
-} from "../../../domain/ruleSets";
+} from "../../../domain/constants";
 
 export const GameInfo = () => {
   const {

+ 7 - 6
client/src/components/util/GameCreationForm/GameCreationForm.jsx

@@ -1,18 +1,19 @@
 import ms from "pretty-ms";
 import { useCallback, useState } from "react";
 import { createGame } from "../../../domain/apiMethods";
-import { RANDOM_STREET_VIEW, URBAN } from "../../../domain/genMethods";
 import {
+  adapt4To5,
+  COUNTRY_RACE,
   FROZEN,
   NORMAL,
-  TIME_BANK,
   RACE,
-  COUNTRY_RACE,
-  adapt4To5,
-} from "../../../domain/ruleSets";
+  RANDOM_STREET_VIEW,
+  TIME_BANK,
+  URBAN,
+} from "../../../domain/constants";
 import useCountryLookup from "../../../hooks/useCountryLookup";
 import Loading from "../Loading";
-import { Dropdown, DropdownGroup, Item, CountryDropdown } from "./Dropdown";
+import { CountryDropdown, Dropdown, DropdownGroup, Item } from "./Dropdown";
 import ErrorModal from "./ErrorModal";
 import styles from "./GameCreationForm.module.css";
 

+ 13 - 0
client/src/domain/ruleSets.js → client/src/domain/constants.js

@@ -1,3 +1,16 @@
+// Game States
+export const PRE_GAME = "PREGAME"; // Game is not yet started
+export const PRE_ROUND = "PREROUND"; // Game is started or joined, but not playing yet
+export const IN_ROUND = "INROUND"; // Actively playing
+export const POST_ROUND = "POSTROUND"; // Round has finished
+export const POST_GAME = "POSTGAME"; // Game has finished
+export const ERROR = "ERROR"; // Error state
+
+// Generation Methods
+export const RANDOM_STREET_VIEW = "RANDOMSTREETVIEW";
+export const URBAN = "URBAN";
+
+// Game Config Options
 export const NORMAL = "NORMAL";
 export const TIME_BANK = "TIMEBANK";
 export const FROZEN = "FROZEN";

+ 0 - 6
client/src/domain/gameStates.js

@@ -1,6 +0,0 @@
-export const PRE_GAME = "PREGAME"; // Game is not yet started
-export const PRE_ROUND = "PREROUND"; // Game is started or joined, but not playing yet
-export const IN_ROUND = "INROUND"; // Actively playing
-export const POST_ROUND = "POSTROUND"; // Round has finished
-export const POST_GAME = "POSTGAME"; // Game has finished
-export const ERROR = "ERROR"; // Error state

+ 1 - 1
client/src/domain/gameStore.js

@@ -11,7 +11,7 @@ import {
   POST_ROUND,
   PRE_GAME,
   PRE_ROUND,
-} from "./gameStates";
+} from "./constants";
 import {
   clearGameInfoFromLocalStorage,
   clearRoundInfoFromLocalStorage,

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

@@ -1,2 +0,0 @@
-export const RANDOM_STREET_VIEW = "RANDOMSTREETVIEW";
-export const URBAN = "URBAN";

+ 4 - 6
client/src/tests/GameCreationForm.test.js

@@ -1,15 +1,13 @@
-import React from "react";
 import { shallow } from "enzyme";
+import React from "react";
 import GameCreationForm from "../components/util/GameCreationForm";
-import { URBAN } from "../domain/genMethods";
-import { FROZEN } from "../domain/ruleSets";
+import { createGame } from "../domain/apiMethods";
+import { FROZEN, URBAN } from "../domain/constants";
+import useCountryLookup from "../hooks/useCountryLookup";
 
 jest.mock("../domain/apiMethods");
 jest.mock("../hooks/useCountryLookup");
 
-import { createGame } from "../domain/apiMethods";
-import useCountryLookup from "../hooks/useCountryLookup";
-
 describe("GameCreationForm", () => {
   it("renders", () => {
     useCountryLookup.mockReturnValue("country-lookup");

+ 1 - 1
client/src/tests/GamePanel.test.js

@@ -1,6 +1,6 @@
 import React from "react";
 import { shallow } from "enzyme";
-import { DISTANCE, FROZEN, NORMAL, RACE } from "../domain/ruleSets";
+import { DISTANCE, FROZEN, NORMAL, RACE } from "../domain/constants";
 import GamePanel from "../components/screens/GamePanel";
 
 jest.mock("../hooks/usePreventNavigation");

+ 1 - 1
client/src/tests/Lobby.test.js

@@ -8,7 +8,7 @@ import {
   NORMAL,
   RACE,
   TIME_BANK,
-} from "../domain/ruleSets";
+} from "../domain/constants";
 
 jest.mock("iso-3166-1");
 jest.mock("../domain/gameStore");

+ 2 - 1
client/src/tests/gameStore.test.js

@@ -1,3 +1,5 @@
+import { IN_ROUND, POST_GAME, PRE_ROUND } from "../domain/constants";
+
 process.env.REACT_APP_MONITOR_STORE = "true";
 
 jest.mock("../store");
@@ -10,7 +12,6 @@ import {
   sendGuess,
   sendTimeout,
 } from "../domain/apiMethods";
-import { IN_ROUND, POST_GAME, PRE_ROUND } from "../domain/gameStates";
 import {
   dispatch,
   useGameId,