Skip to content

Commit

Permalink
добавляет изменения выбор карты по индексу
Browse files Browse the repository at this point in the history
  • Loading branch information
semant1cs committed Nov 28, 2023
1 parent d6c89f0 commit 180e8aa
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 23 deletions.
16 changes: 15 additions & 1 deletion frontend/src/components/mapMenu/EmployeeMap.tsx
Original file line number Diff line number Diff line change
@@ -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";
Expand All @@ -14,6 +14,20 @@ interface IEmployeeMap {
}

const EmployeeMap: React.FC<IEmployeeMap> = 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 (
<div className="employee-interface">
<Coins coins={100} additionalClassname="coins"/>
Expand Down
14 changes: 0 additions & 14 deletions frontend/src/components/mapMenu/MapMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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 (
Expand Down
21 changes: 18 additions & 3 deletions frontend/src/components/mapMenu/SuperUserMap.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand All @@ -12,8 +14,17 @@ interface ISuperUserMap {
const SuperUserMap: React.FC<ISuperUserMap> = 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 (
<div>
<select>
Expand All @@ -26,14 +37,18 @@ const SuperUserMap: React.FC<ISuperUserMap> = observer(() => {
handleOnClick={() => mapMenuStore.createMap(mapMenuStore.newNameMap)}/>

<select>
{mapMenuStore.availableMaps?.map((map) =>
{mapMenuStore.availableMaps?.map((map, index) =>
<option key={map.id} value={map.title}
onClick={() => mapMenuStore.selectMap(map)}>{map.title}</option>)}
onClick={() => handleOnClickOptionMap(map, index)}>{map.title}</option>)}
</select>

<CustomButton text="Удалить выбранную карту"
handleOnClick={() => mapMenuStore.deleteMap(mapMenuStore.mapMenu?.id)}/>

<select>
{moduleMenuStore.availableModules.map((module) =>
<option key={module.id} value={module.title}>{module.title}</option>)}
</select>
</div>
);
});
Expand Down
5 changes: 1 addition & 4 deletions frontend/src/store/authStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}

Expand Down
8 changes: 7 additions & 1 deletion frontend/src/store/mapMenuStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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[] = []
Expand Down Expand Up @@ -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
}
Expand Down

0 comments on commit 180e8aa

Please sign in to comment.