From a584abc57d8ccca940e4fc6708a3bbbae7591c65 Mon Sep 17 00:00:00 2001 From: mihail323i21 Date: Sun, 19 Nov 2023 21:27:19 +0500 Subject: [PATCH] =?UTF-8?q?=D0=B4=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB=D1=8F?= =?UTF-8?q?=D0=B5=D1=82=20=D0=BF=D0=BE=D0=BB=D1=8C=D0=B7=D0=BE=D0=B2=D0=B0?= =?UTF-8?q?=D0=BD=D0=B8=D0=B5=20=D0=B2=D1=81=D0=B5=D0=BC=D0=B8=20=D0=B2?= =?UTF-8?q?=D0=BE=D0=B7=D0=BC=D0=BE=D0=B6=D0=BD=D1=8B=D0=BC=D0=B8=20=D1=8D?= =?UTF-8?q?=D0=BD=D0=B4=D0=BF=D0=BE=D0=B8=D0=BD=D1=82=D0=B0=D0=BC=D0=B8=20?= =?UTF-8?q?=D0=B8=D0=B7=20=D0=B0=D0=BF=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- frontend/src/components/mapMenu/MapMenu.tsx | 1 - .../mapMenu/UIMapMenu/Level/Module.tsx | 1 - frontend/src/store/mapMenuStore.ts | 58 ++++++++++++++++--- 3 files changed, 50 insertions(+), 10 deletions(-) diff --git a/frontend/src/components/mapMenu/MapMenu.tsx b/frontend/src/components/mapMenu/MapMenu.tsx index dd958a0..84462cc 100644 --- a/frontend/src/components/mapMenu/MapMenu.tsx +++ b/frontend/src/components/mapMenu/MapMenu.tsx @@ -32,7 +32,6 @@ const MapMenu: React.FC = observer(() => {
- {console.log(mapMenuStore.currentModule?.levels_ids)} {mapMenuStore.currentModule?.levels_ids.map((level, index) => )}
diff --git a/frontend/src/components/mapMenu/UIMapMenu/Level/Module.tsx b/frontend/src/components/mapMenu/UIMapMenu/Level/Module.tsx index 421efcf..30a4cc2 100644 --- a/frontend/src/components/mapMenu/UIMapMenu/Level/Module.tsx +++ b/frontend/src/components/mapMenu/UIMapMenu/Level/Module.tsx @@ -1,7 +1,6 @@ import React, {useState} from 'react'; import ModalWindow from "../../../../UIComponents/modalWindow/ModalWindow.tsx"; import ModalLevelBody from "./ModalLevelBody.tsx"; -import {ILevelType} from "../../../../types/LevelType.ts"; interface IGeolocationProps { id: number, diff --git a/frontend/src/store/mapMenuStore.ts b/frontend/src/store/mapMenuStore.ts index 7265e7f..6aadd9b 100644 --- a/frontend/src/store/mapMenuStore.ts +++ b/frontend/src/store/mapMenuStore.ts @@ -8,7 +8,7 @@ class MapMenuStore { availableMaps: IMapType[] = [] modulesMap: string[] = [] - availableModules: IModuleType | null = null + availableModules: string[] = [] currentModule: IModuleType | null = null constructor() { @@ -19,29 +19,71 @@ class MapMenuStore { await axios.get("http://localhost:8000/maps/").then((response) => this.availableMaps = response.data) } + createMap(id: string) { + axios.post("http://localhost:8000/maps/" + id) + } + async fetchMapById(id: string) { await axios.get("http://localhost:8000/maps/" + id).then((response) => this.mapMenu = response?.data) } + deleteMap(id: string) { + axios.delete("http://localhost:8000" + id) + } + + updateMapById(id: string, title: string, modulesIds?: string[]) { + axios.patch("http://localhost:8000/maps/" + id, { + id: id, + title: title, + modules_ids: modulesIds + }) + } + setModulesMap(newModulesMap: string[]) { this.modulesMap = newModulesMap } + setAvailableModules(modules: string[]) { + this.availableModules = modules + } + setCurrentModule(newModule: IModuleType) { this.currentModule = newModule } + async fetchModules() { + await axios.get("http://localhost:8000/modules/").then((response) => this.setAvailableModules(response.data)) + } + + async createModule(mapId: string, title: string, previousModuleId: string, nextModuleId: string, moduleId: string, levels_ids: string[]) { + axios.post("http://localhost:8000/modules/", { + map_id: mapId, + title: title, + previous_module_id: previousModuleId, + next_module_id: nextModuleId, + id: moduleId, + levels_ids: levels_ids + }) + } + async fetchModuleById(id: string) { await axios.get("http://localhost:8000/modules/" + id).then((response) => this.setCurrentModule(response.data)) } - // updateMapById(id: string) { - // axios.patch(id, { - // id: id, - // title: "Карта 1", - // modules_ids: ["3fa85f64-5717-4562-b3fc-2c963f66afa6", "3fa85f64-5717-4562-b3fc-2c963f66afa7"] - // }) - // } + async deleteModule(id: string) { + axios.delete("http://localhost:8000/modules" + id) + } + + updateModuleById(mapId: string, id: string, title?: string, previousModuleId?: string, nextModuleId?: string, levels?: string[]) { + axios.patch("http://localhost:8000/modules/" + id, { + id: id, + map_id: mapId, + title: title, + previous_module_id: previousModuleId, + next_module_id: nextModuleId, + levels_ids: levels + }) + } } export default new MapMenuStore()