From 34ccc98a942098faefb5f4211b215ff9ccc7ad0e Mon Sep 17 00:00:00 2001 From: Alexander Neonxp Kiryukhin Date: Mon, 9 Dec 2024 01:07:15 +0300 Subject: Начальный MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- frontend/app.css | 4 ++ frontend/app.jsx | 207 +++++++++++++++++++++++++++++++++++++++++++++++++++++ frontend/index.jsx | 8 +++ 3 files changed, 219 insertions(+) create mode 100644 frontend/app.css create mode 100644 frontend/app.jsx create mode 100644 frontend/index.jsx (limited to 'frontend') diff --git a/frontend/app.css b/frontend/app.css new file mode 100644 index 0000000..2ffd64f --- /dev/null +++ b/frontend/app.css @@ -0,0 +1,4 @@ +html, body {height: 100%;padding:0;margin:0} +#app, .full { + height: 100%; +} \ No newline at end of file diff --git a/frontend/app.jsx b/frontend/app.jsx new file mode 100644 index 0000000..60bdcf4 --- /dev/null +++ b/frontend/app.jsx @@ -0,0 +1,207 @@ +import React, { useState, useEffect } from "react"; +import GlMap, { Source, Marker, Layer } from "react-map-gl/maplibre"; +import { + Flex, + Layout, + Col, + Row, + Modal, + Form, + Input, + Button, + Image, + Card, +} from "antd"; + +const { Header, Content } = Layout; + +const layout = { + labelCol: { span: 8 }, + wrapperCol: { span: 16 }, +}; + +const geostyle = { + id: "data", + type: "line", + paint: { + "line-color": "red", + "line-width": 3, + }, +}; + +const App = () => { + const [state, setState] = useState({}); + const [selected, setSelected] = useState(null); + const [guess, setGuess] = useState(null); + const [loading, setLoading] = useState(true); + const [form] = Form.useForm(); + + useEffect(() => { + fetch("/api/state") + .then((x) => x.json()) + .then(setState) + .then(() => setLoading(false)); + }, []); + + useEffect(() => { + if (guess != null) { + setState(guess.state); + } + }, [guess]); + + const onFinish = (values) => { + fetch("/api/state", { + method: "POST", + body: JSON.stringify(values), + headers: { "content-type": "application/json" }, + }) + .then((x) => x.json()) + .then(setState); + }; + + const onReset = () => { + form.resetFields(); + }; + + const onNext = () => { + setSelected(null); + setGuess(null); + setLoading(true); + fetch("/api/next", { + method: "POST", + headers: { "content-type": "application/json" }, + }) + .then((x) => x.json()) + .then(setState) + .then(() => setLoading(false)); + }; + + const onMapClick = (e) => { + if (state.current_guid) { + setSelected(e.lngLat); + } + }; + + const onGuess = () => { + setLoading(true); + fetch("/api/guess", { + method: "POST", + headers: { "content-type": "application/json" }, + body: JSON.stringify(selected), + }) + .then((x) => x.json()) + .then(setGuess) + .then(() => setLoading(false)); + }; + + return ( + <> + + + + + + {selected ? ( + + ) : null} + {guess ? ( + + + + ) : null} + + + + {state.username ? ( + +

{state.username}

+

{state.points} очков

+
+ ) : null} + + {!loading && !state.current_guid ? ( + + ) : null} + {!loading && state.current_guid ? ( + + ) : null} + {!loading && guess ? ( + <> +

{guess.name}

+ +

Расстояние: {guess.distance / 1000}км.

+ + ) : null} + {state.current_guid && !selected ? ( +

+ Нажмите на карте на точку, где по вашему + мнение находится то, что на фотографии +

+ ) : null} + {state.current_guid && selected ? ( + + ) : null} +
+

Сделал Александр Кирюхин в 2024 году

+ +
+
+
+ +

Для начала игры необходимо представиться

+
+ + + +
+
+ + ); +}; + +export default App; diff --git a/frontend/index.jsx b/frontend/index.jsx new file mode 100644 index 0000000..1153d89 --- /dev/null +++ b/frontend/index.jsx @@ -0,0 +1,8 @@ +import React from "react"; +import { createRoot } from "react-dom/client"; +import App from "./app"; + +import "./app.css"; +import "maplibre-gl/dist/maplibre-gl.css"; + +createRoot(document.getElementById("app")).render(); -- cgit v1.2.3