diff --git a/frontend/src/components/mapMenu/EmployeeMap.tsx b/frontend/src/components/mapMenu/EmployeeMap.tsx index 416901a..cf2201c 100644 --- a/frontend/src/components/mapMenu/EmployeeMap.tsx +++ b/frontend/src/components/mapMenu/EmployeeMap.tsx @@ -1,4 +1,4 @@ -import React from 'react'; +import React, {useEffect} from 'react'; import Coins from "./UIMapMenu/Coins.tsx"; import ChooseModuleWindow from "./UIMapMenu/ChooseModuleWindow.tsx"; import mapMenuStore from "../../store/mapMenuStore.ts"; @@ -14,6 +14,20 @@ interface IEmployeeMap { } const EmployeeMap: React.FC = observer(({user, formattedDate}) => { + useEffect(() => { + mapMenuStore.fetchAvailableMaps().then(() => { + mapMenuStore.fetchMapById(mapMenuStore.availableMaps[0].id).then(() => { + moduleMenuStore.fetchModules().then(() => { + moduleMenuStore.fetchModuleById(moduleMenuStore.availableModules[0].id).then(() => { + mapMenuStore.fetchLevels().then(() => { + + }).catch(() => alert("Нет доступных уровней для данного модуля")) + }) + }).catch(() => alert("Нет доступных модулей для данной карты")) + }) + }).catch(() => alert("Нет доступных карт для данного пользователя")) + }, []); + return (
diff --git a/frontend/src/components/mapMenu/MapMenu.tsx b/frontend/src/components/mapMenu/MapMenu.tsx index a37e511..d5248ca 100644 --- a/frontend/src/components/mapMenu/MapMenu.tsx +++ b/frontend/src/components/mapMenu/MapMenu.tsx @@ -2,14 +2,12 @@ import React, {useEffect, useState} from 'react'; import authStore from "../../store/authStore.ts"; import {useNavigate} from "react-router-dom"; import './../../styles/mapMenu.scss' -import mapMenuStore from "../../store/mapMenuStore.ts"; import {observer} from "mobx-react-lite"; import {IUserType} from "../../types/UserType.ts"; import axios from "axios"; import EmployeeMap from "./EmployeeMap.tsx"; import SuperUserMap from "./SuperUserMap.tsx"; import superUserStore from "../../store/superUserStore.ts"; -import moduleMenuStore from "../../store/moduleMenuStore.ts"; const MapMenu: React.FC = observer(() => { const navigate = useNavigate() @@ -39,18 +37,6 @@ const MapMenu: React.FC = observer(() => { useEffect(() => { if (!authStore.isUserAuthorized) navigate("/") - - mapMenuStore.fetchAvailableMaps().then(() => { - mapMenuStore.fetchMapById(mapMenuStore.availableMaps[0].id).then(() => { - moduleMenuStore.fetchModules().then(() => { - moduleMenuStore.fetchModuleById(moduleMenuStore.availableModules[0].id).then(() => { - mapMenuStore.fetchLevels().then(() => { - - }).catch(() => alert("Нет доступных уровней для данного модуля")) - }) - }).catch(() => alert("Нет доступных модулей для данной карты")) - }) - }).catch(() => alert("Нет доступных карт для данного пользователя")) }, [navigate]) return ( diff --git a/frontend/src/components/mapMenu/SuperUserMap.tsx b/frontend/src/components/mapMenu/SuperUserMap.tsx index 5866c79..65f07ea 100644 --- a/frontend/src/components/mapMenu/SuperUserMap.tsx +++ b/frontend/src/components/mapMenu/SuperUserMap.tsx @@ -4,6 +4,8 @@ import mapMenuStore from "../../store/mapMenuStore.ts"; import CustomInput from "../../UIComponents/customInput/CustomInput.tsx"; import {observer} from "mobx-react-lite"; import superUserStore from "../../store/superUserStore.ts"; +import moduleMenuStore from "../../store/moduleMenuStore.ts"; +import {IMapType} from "../../types/MapType.ts"; interface ISuperUserMap { @@ -12,8 +14,17 @@ interface ISuperUserMap { const SuperUserMap: React.FC = observer(() => { useEffect(() => { - + mapMenuStore.fetchAvailableMaps() + .then(() => mapMenuStore.fetchMapById(mapMenuStore.availableMaps[mapMenuStore.currentMapIndex].id) + .then(() => moduleMenuStore.fetchModules())) }, []); + + function handleOnClickOptionMap(map: IMapType, indexMap: number) { + mapMenuStore.selectMap(map) + mapMenuStore.changeCurrentMapIndex(indexMap) + } + + return (
- {mapMenuStore.availableMaps?.map((map) => + {mapMenuStore.availableMaps?.map((map, index) => )} + onClick={() => handleOnClickOptionMap(map, index)}>{map.title})} mapMenuStore.deleteMap(mapMenuStore.mapMenu?.id)}/> +
); }); diff --git a/frontend/src/store/authStore.ts b/frontend/src/store/authStore.ts index d075c68..244b344 100644 --- a/frontend/src/store/authStore.ts +++ b/frontend/src/store/authStore.ts @@ -54,10 +54,7 @@ class AuthStore { 'Content-Type': 'application/x-www-form-urlencoded' }, withCredentials: true }) - .then((response) => { - console.log(response) - this.signInUser() - }) + .then(() => this.signInUser()) .catch((reason) => alert(reason)) } diff --git a/frontend/src/store/mapMenuStore.ts b/frontend/src/store/mapMenuStore.ts index 577b55a..476da58 100644 --- a/frontend/src/store/mapMenuStore.ts +++ b/frontend/src/store/mapMenuStore.ts @@ -9,8 +9,9 @@ class MapMenuStore { // Доступное всем пользователям mapMenu: IMapType | null = null availableMaps: IMapType[] = [] - currentMapId: string | null = null + currentMapIndex: number = 0 + currentLevelId: string | null = null availableLevels: ILevelType[] = [] @@ -115,6 +116,11 @@ class MapMenuStore { this.newNameMap = newName } + changeCurrentMapIndex(newIndex: number) { + this.currentMapIndex = newIndex + this.fetchMapById(this.availableMaps[this.currentMapIndex].id).then(() => moduleMenuStore.fetchModules()) + } + selectMap(newMap: IMapType) { this.mapMenu = newMap }