Skip to content

Commit

Permalink
добавляет пользование всеми возможными эндпоинтами из апи
Browse files Browse the repository at this point in the history
  • Loading branch information
semant1cs committed Nov 19, 2023
1 parent 4301a9f commit a584abc
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 10 deletions.
1 change: 0 additions & 1 deletion frontend/src/components/mapMenu/MapMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ const MapMenu: React.FC = observer(() => {
<br/>
<div className="geolocations">
<div className="geolocations__wrapper">
{console.log(mapMenuStore.currentModule?.levels_ids)}
{mapMenuStore.currentModule?.levels_ids.map((level, index) =>
<Module id={index} level={level} key={index}/>)}
</div>
Expand Down
1 change: 0 additions & 1 deletion frontend/src/components/mapMenu/UIMapMenu/Level/Module.tsx
Original file line number Diff line number Diff line change
@@ -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,
Expand Down
58 changes: 50 additions & 8 deletions frontend/src/store/mapMenuStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class MapMenuStore {
availableMaps: IMapType[] = []

modulesMap: string[] = []
availableModules: IModuleType | null = null
availableModules: string[] = []
currentModule: IModuleType | null = null

constructor() {
Expand All @@ -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()

0 comments on commit a584abc

Please sign in to comment.