diff --git a/package.json b/package.json index 93538de..bfee217 100644 --- a/package.json +++ b/package.json @@ -15,6 +15,7 @@ "lodash": "^4.17.21", "mobx": "^6.3.13", "mobx-observer": "^0.1.1", + "mobx-react": "^7.2.1", "react": "^17.0.2", "react-dom": "^17.0.2", "react-scripts": "5.0.0", diff --git a/src/components/App/App.css b/src/components/App/App.css index 6baa2bf..ce3188f 100644 --- a/src/components/App/App.css +++ b/src/components/App/App.css @@ -2,6 +2,34 @@ text-align: center; } +.error { + color: red; + font-weight: bold; +} +.game { + width: 100%; + max-width: 500px; +} +h1 { + color: gold; +} + +.witch-row { + display: flex; +} + +.witch { + width: 100px; +} +.witch img { + width: 100px; +} +.witch:hover { + opacity: 0.5; + animation: App-logo-spin infinite 10s linear; +} + + .App-logo { height: 50vmin; pointer-events: none; diff --git a/src/components/App/App.tsx b/src/components/App/App.tsx index d47ded8..2bd203a 100644 --- a/src/components/App/App.tsx +++ b/src/components/App/App.tsx @@ -2,6 +2,7 @@ import './App.css'; import IntroPage from '../IntroPage/IntroPage'; import GamePage from '../GamePage/GamePage'; import apiStore, { EGameStage } from '../../store/apiStore/apiStore'; +import { observer } from 'mobx-react'; type AppProps = { onEnterGame?: () => void, diff --git a/src/components/GamePage/GamePage.tsx b/src/components/GamePage/GamePage.tsx index dd6c445..1333153 100644 --- a/src/components/GamePage/GamePage.tsx +++ b/src/components/GamePage/GamePage.tsx @@ -21,13 +21,13 @@ const GamePage: React.FC = (props) => {
Score: {apiStore.currentGame?.score}
-
Score: {apiStore.currentGame?.score}
-
+
Version: {apiStore.version}
+
{ _.map(apiStore.currentGame?.witches, (item: Witch, index: number) => { const left = item.position * 100; return ( -
+
{`witch-${index}`} clickAtWitch(item.guid)}/>
) @@ -38,7 +38,13 @@ const GamePage: React.FC = (props) => {

onExitGame()}> Стоп игра!

-
+ apiStore.tryToSetMockMode(e.target.checked) } + />
); } diff --git a/src/components/IntroPage/IntroPage.tsx b/src/components/IntroPage/IntroPage.tsx index 62e37d7..fa3ec8f 100644 --- a/src/components/IntroPage/IntroPage.tsx +++ b/src/components/IntroPage/IntroPage.tsx @@ -1,6 +1,7 @@ // @ts-ignore import witch from '../../resources/witch.svg'; import './IntroPage.css'; +import apiStore from '../../store/apiStore/apiStore'; type IntroProps = { onEnterGame: () => void, @@ -12,6 +13,7 @@ const IntroPage: React.FC = (props) => {
logo

onEnterGame()}> Начать играть!

+ {apiStore.errorState &&

{apiStore.errorState}

}
); } diff --git a/src/store/apiStore/apiStore.ts b/src/store/apiStore/apiStore.ts index b15825b..e1f348e 100644 --- a/src/store/apiStore/apiStore.ts +++ b/src/store/apiStore/apiStore.ts @@ -126,6 +126,29 @@ class ApiStore { }); } } + + tryToSetMockMode(flagEnabled: boolean) { + if (!flagEnabled) { + this.setMockMode(true); + return; + } + service.getVersion() + .then((version) => { + if (!version) { + this.setMockMode(true); + return; + } + this.setVersion(version); + if (version) { + this.setMockMode(false); + } + }) + .catch((error) => { + this.setMockMode(true); + this.setErrorState(error.message); + this.setGameStage(EGameStage.Start); + }) + } } export default new ApiStore(); diff --git a/src/store/tool.ts b/src/store/tool.ts index d39403e..842462c 100644 --- a/src/store/tool.ts +++ b/src/store/tool.ts @@ -30,7 +30,7 @@ const tool = { }) .catch((err) => { console.warn(err); - return undefined; + throw err; }); }, //endregion diff --git a/yarn.lock b/yarn.lock index 56dc3e8..d02fe76 100644 --- a/yarn.lock +++ b/yarn.lock @@ -5843,6 +5843,18 @@ mobx-observer@^0.1.1: resolved "https://registry.yarnpkg.com/mobx-observer/-/mobx-observer-0.1.1.tgz#cb46de1c26a8f4f067db126da9ef6d3e2b803510" integrity sha1-y0beHCao9PBn2xJtqe9tPiuANRA= +mobx-react-lite@^3.2.0: + version "3.2.3" + resolved "https://registry.yarnpkg.com/mobx-react-lite/-/mobx-react-lite-3.2.3.tgz#83d2b32ebf4383cd0dc0d397acbf53a8e9c66765" + integrity sha512-7exWp1FV0M9dP08H9PIeHlJqDw4IdkQVRMfLYaZFMmlbzSS6ZU6p/kx392KN+rVf81hH3IQYewvRGQ70oiwmbw== + +mobx-react@^7.2.1: + version "7.2.1" + resolved "https://registry.yarnpkg.com/mobx-react/-/mobx-react-7.2.1.tgz#e9d4c04dc63d05e1139ce773f5fee7a5b4cb7c78" + integrity sha512-LZS99KFLn75VWDXPdRJhILzVQ7qLcRjQbzkK+wVs0Qg4kWw5hOI2USp7tmu+9zP9KYsVBmKyx2k/8cTTBfsymw== + dependencies: + mobx-react-lite "^3.2.0" + mobx@^6.3.13: version "6.3.13" resolved "https://registry.yarnpkg.com/mobx/-/mobx-6.3.13.tgz#93e56a57ee72369f850cf3d6398fd36ee8ef062e"