From 8f3c3249a728f030469f599e04f051405e323348 Mon Sep 17 00:00:00 2001 From: Leonard Techel Date: Wed, 6 Jul 2022 17:51:56 +0200 Subject: [PATCH] feat: Remove possibility to pause the game from the user-facing app --- app/lang-compiled/de.json | 24 --------- app/lang/de.json | 16 ------ app/src/app/pages/IndexPage.tsx | 32 ------------ .../__snapshots__/IndexPage.test.tsx.snap | 21 +------- .../common/components/PausedHeroMessage.tsx | 49 ++++--------------- .../PausedHeroMessage.test.tsx.snap | 21 +------- app/src/common/hooks/api/useUpdateClock.ts | 42 ---------------- app/src/mocks/handlers.ts | 12 ----- backend/dpt_app/trails/api.py | 14 ------ backend/dpt_app/trails/tests.py | 28 ----------- docs/ABC-DPT.v1.yaml | 47 ------------------ 11 files changed, 12 insertions(+), 294 deletions(-) delete mode 100644 app/src/common/hooks/api/useUpdateClock.ts diff --git a/app/lang-compiled/de.json b/app/lang-compiled/de.json index 52cf084..7165ccd 100644 --- a/app/lang-compiled/de.json +++ b/app/lang-compiled/de.json @@ -23,12 +23,6 @@ "value": "Sende Nachricht" } ], - "3eJT2C": [ - { - "type": 0, - "value": "Das Spiel ist pausiert. Du kannst es aber für alle fortsetzen." - } - ], "7vghdx": [ { "type": 0, @@ -107,12 +101,6 @@ "value": "QR-Code nicht ausführen" } ], - "R14Oy/": [ - { - "type": 0, - "value": "Spiel für alle fortsetzen" - } - ], "R6ODBn": [ { "type": 0, @@ -219,12 +207,6 @@ "value": "Bewegungspunkte" } ], - "gyakmc": [ - { - "type": 0, - "value": "Spiel für alle fortsetzen" - } - ], "h1UmHT": [ { "type": 0, @@ -279,12 +261,6 @@ "value": "Scanner" } ], - "vcAwuf": [ - { - "type": 0, - "value": "Spiel für alle pausieren" - } - ], "xlGZnG": [ { "type": 0, diff --git a/app/lang/de.json b/app/lang/de.json index 21fb143..8f5d472 100644 --- a/app/lang/de.json +++ b/app/lang/de.json @@ -15,10 +15,6 @@ "defaultMessage": "Sende Nachricht", "description": "qr code action label" }, - "3eJT2C": { - "defaultMessage": "Das Spiel ist pausiert. Du kannst es aber für alle fortsetzen.", - "description": "game paused message description" - }, "7vghdx": { "defaultMessage": "Aktionen anzeigen", "description": "appbar menu toggle" @@ -71,10 +67,6 @@ "defaultMessage": "QR-Code nicht ausführen", "description": "app bar close button of the confirm qr code action page" }, - "R14Oy/": { - "defaultMessage": "Spiel für alle fortsetzen", - "description": "appbar menu item continue game" - }, "R6ODBn": { "defaultMessage": "QR-Code scannen", "description": "scanner page title" @@ -131,10 +123,6 @@ "defaultMessage": "Bewegungspunkte", "description": "parameter label" }, - "gyakmc": { - "defaultMessage": "Spiel für alle fortsetzen", - "description": "game paused message continue button label" - }, "h1UmHT": { "defaultMessage": "Spiel pausiert", "description": "game paused message title" @@ -171,10 +159,6 @@ "defaultMessage": "Scanner", "description": "main nav scanner page item label" }, - "vcAwuf": { - "defaultMessage": "Spiel für alle pausieren", - "description": "appbar menu item pause game" - }, "xlGZnG": { "defaultMessage": "Spiel-Code", "description": "start code page game id input label" diff --git a/app/src/app/pages/IndexPage.tsx b/app/src/app/pages/IndexPage.tsx index b4e7bb9..9b76804 100644 --- a/app/src/app/pages/IndexPage.tsx +++ b/app/src/app/pages/IndexPage.tsx @@ -20,9 +20,7 @@ import useCharacter from "../../common/hooks/useCharacter"; import useClock from "../../common/hooks/api/useClock"; import useLeaveGame from "../../common/hooks/useLeaveGame"; import usePwaInstaller from "../../common/hooks/usePwaInstaller"; -import useUpdateClock from "../../common/hooks/api/useUpdateClock"; -import ButtonProgressIndicator from "../../common/components/ButtonProgressIndicator"; import ChooseCharacterHeroMessage from "../../common/components/ChooseCharacterHeroMessage"; import GameOverHeroMessage from "../../common/components/GameOverHeroMessage"; import PausedHeroMessage from "../../common/components/PausedHeroMessage"; @@ -46,7 +44,6 @@ const IndexPage = (props: IndexPageProps) => { const appBarMenuAnchorEl = React.useRef(null); const [appBarMenuIsOpen, setAppBarMenuIsOpen] = React.useState(false); - const [updateClockIsLoading, updateClock] = useUpdateClock(); const leaveGame = useLeaveGame(); const onLeaveGame = () => { @@ -107,35 +104,6 @@ const IndexPage = (props: IndexPageProps) => { open={appBarMenuIsOpen} onClose={() => setAppBarMenuIsOpen(false)} > - {isPaused ? ( - { - await updateClock("running"); - setAppBarMenuIsOpen(false); - }} - > - - {updateClockIsLoading && } - - ) : ( - { - await updateClock("paused"); - setAppBarMenuIsOpen(false); - }} - > - - {updateClockIsLoading && } - - )}
Spiel pausiert -

- Das Spiel ist pausiert. Du kannst es aber für alle fortsetzen. -

-
- -
diff --git a/app/src/common/components/PausedHeroMessage.tsx b/app/src/common/components/PausedHeroMessage.tsx index e44f4d0..b406548 100644 --- a/app/src/common/components/PausedHeroMessage.tsx +++ b/app/src/common/components/PausedHeroMessage.tsx @@ -1,46 +1,17 @@ -import { Box, Button } from "@mui/material"; import { FormattedMessage } from "react-intl"; import * as React from "react"; -import ButtonProgressIndicator from "./ButtonProgressIndicator"; import HeroMessage from "./HeroMessage"; -import useUpdateClock from "../hooks/api/useUpdateClock"; -const PausedHeroMessage = () => { - const [isLoading, updateClock] = useUpdateClock(); - - return ( - - } - description={ - - } - after={ - - - - } - /> - ); -}; +const PausedHeroMessage = () => ( + + } + /> +); export default PausedHeroMessage; diff --git a/app/src/common/components/__snapshots__/PausedHeroMessage.test.tsx.snap b/app/src/common/components/__snapshots__/PausedHeroMessage.test.tsx.snap index d510c9d..86ecff7 100644 --- a/app/src/common/components/__snapshots__/PausedHeroMessage.test.tsx.snap +++ b/app/src/common/components/__snapshots__/PausedHeroMessage.test.tsx.snap @@ -2,7 +2,7 @@ exports[`renders correctly 1`] = `
Spiel pausiert -

- Das Spiel ist pausiert. Du kannst es aber für alle fortsetzen. -

-
- -
`; diff --git a/app/src/common/hooks/api/useUpdateClock.ts b/app/src/common/hooks/api/useUpdateClock.ts deleted file mode 100644 index 8884ecd..0000000 --- a/app/src/common/hooks/api/useUpdateClock.ts +++ /dev/null @@ -1,42 +0,0 @@ -import { ClockState } from "../../types/Clock"; -import config from "../../../config"; -import useApiUrl from "./useApiUrl"; -import useCallApi from "./useCallApi"; -import useClock from "./useClock"; - -/** - * A React hook that creates a method to update the clock state - * - * @returns An array with the loading state at pos 0 and the api method at pos 1 - */ -const useUpdateClock = (): [ - boolean, - (state: ClockState) => Promise -] => { - const { mutate } = useClock(); - const url = useApiUrl((gameId) => config.apiEndpoints.clock(gameId)); - const [isLoading, callApi] = useCallApi(url); - - const updateClock = async (state: ClockState) => { - try { - const res = await callApi({ - method: "POST", - body: JSON.stringify({ - data: { - type: "clock", - id: "clock", - attributes: { - state, - }, - }, - }), - }); - mutate(); - return res; - } catch (err) {} - }; - - return [isLoading, updateClock]; -}; - -export default useUpdateClock; diff --git a/app/src/mocks/handlers.ts b/app/src/mocks/handlers.ts index db6567f..0ac8368 100644 --- a/app/src/mocks/handlers.ts +++ b/app/src/mocks/handlers.ts @@ -1,22 +1,10 @@ import { rest } from "msw"; import { ClockApiResponse } from "../common/hooks/api/useClock"; -import { ClockState } from "../common/types/Clock"; - -let clockState: ClockState = "running"; export const handlers = [ rest.get("/games/:gameId/clock", (req, res, ctx) => { const clockRes: ClockApiResponse = require("./data/clock.json"); - clockRes.data.attributes.state = clockState; - return res(ctx.json(clockRes)); - }), - rest.post("/games/:gameId/clock", (req, res, ctx) => { - clockState = - JSON.parse(req.body as string).data.attributes.state || "running"; - - const clockRes: ClockApiResponse = require("./data/clock.json"); - clockRes.data.attributes.state = clockState; return res(ctx.json(clockRes)); }), diff --git a/backend/dpt_app/trails/api.py b/backend/dpt_app/trails/api.py index c4cb69a..eacd721 100644 --- a/backend/dpt_app/trails/api.py +++ b/backend/dpt_app/trails/api.py @@ -187,20 +187,6 @@ def get_clock(request: HttpRequest, gameId: str): return serialize_clock(request.game) -@api.post("games/{str:gameId}/clock", response=ClockSchema, url_name="clock") -@wrap_get_game -@wrap_get_player -def post_clock(request: HttpRequest, gameId: str, payload: ClockSchema): - if payload.data.attributes.state == "running": - request.game.clock_state = ClockType.RUNNING - elif payload.data.attributes.state == "paused": - request.game.clock_state = ClockType.STOPPED - - request.game.save() - - return serialize_clock(request.game) - - def serialize_player(player: Player): character = None if player.character: diff --git a/backend/dpt_app/trails/tests.py b/backend/dpt_app/trails/tests.py index 603fc9b..09bc6a1 100644 --- a/backend/dpt_app/trails/tests.py +++ b/backend/dpt_app/trails/tests.py @@ -323,34 +323,6 @@ def test_get(self): } }) - def test_post(self): - self.assertEqual(self.game.clock_state, ClockType.STOPPED) - - url = reverse("api-1.0.0:clock", args=(self.game.slug,)) - res = self.client.post(url, HTTP_AUTHORIZATION=self.player.bearer, content_type="application/json", data={ - "data": { - "type": "clock", - "attributes": { - "state": "running" - } - } - }) - self.assertEqual(res.status_code, 200) - self.assertEqual(res.json(), { - "data": { - "type": "clock", - "id": "1", - "attributes": { - "state": "running", - "speed": 1.0 - } - } - }) - - self.game.refresh_from_db() - - self.assertEqual(self.game.clock_state, ClockType.RUNNING) - class PlayerApiTest(GameTestCase): def test_put(self): diff --git a/docs/ABC-DPT.v1.yaml b/docs/ABC-DPT.v1.yaml index b92b2f2..aa5ca66 100644 --- a/docs/ABC-DPT.v1.yaml +++ b/docs/ABC-DPT.v1.yaml @@ -35,53 +35,6 @@ paths: speed: 1 operationId: get-clock description: Get the current server game clock state. - post: - summary: Update game clock state - operationId: post-clock - responses: - "200": - description: OK - content: - application/vnd.api+json: - schema: - type: object - properties: - data: - $ref: "#/components/schemas/Clock" - examples: - example: - value: - data: - type: clock - id: clock - attributes: - state: paused - description: Update the current server game clock state. - requestBody: - content: - application/vnd.api+json: - schema: - type: object - properties: - data: - $ref: "#/components/schemas/Clock" - examples: - pause: - value: - data: - type: clock - id: clock - attributes: - state: paused - change speed: - value: - data: - type: clock - id: clock - attributes: - speed: "0.75" - tags: - - App parameters: - schema: type: string