diff --git a/frontend/src/components/mapMenu/EmployeeMap.tsx b/frontend/src/components/mapMenu/EmployeeMap.tsx index 9634029..416901a 100644 --- a/frontend/src/components/mapMenu/EmployeeMap.tsx +++ b/frontend/src/components/mapMenu/EmployeeMap.tsx @@ -6,6 +6,7 @@ import UserProfile from "./UIMapMenu/UserProfile/UserProfile.tsx"; import Level from "./UIMapMenu/Level/Level.tsx"; import {IUserType} from "../../types/UserType.ts"; import {observer} from "mobx-react-lite"; +import moduleMenuStore from "../../store/moduleMenuStore.ts"; interface IEmployeeMap { user?: IUserType, @@ -16,7 +17,7 @@ const EmployeeMap: React.FC = observer(({user, formattedDate}) => return (
- +
diff --git a/frontend/src/components/mapMenu/MapMenu.tsx b/frontend/src/components/mapMenu/MapMenu.tsx index 39c7e1b..a8e2440 100644 --- a/frontend/src/components/mapMenu/MapMenu.tsx +++ b/frontend/src/components/mapMenu/MapMenu.tsx @@ -8,6 +8,8 @@ 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() @@ -24,7 +26,7 @@ const MapMenu: React.FC = observer(() => { } }) - mapMenuStore.setAllUsers(response.data) + superUserStore.setAllUsers(response.data) if (user) { @@ -40,8 +42,8 @@ const MapMenu: React.FC = observer(() => { mapMenuStore.fetchAvailableMaps().then(() => { mapMenuStore.fetchMapById(mapMenuStore.availableMaps[0].id).then(() => { - mapMenuStore.fetchModules().then(() => { - mapMenuStore.fetchModuleById(mapMenuStore.availableModules[0].id).then(() => { + moduleMenuStore.fetchModules().then(() => { + moduleMenuStore.fetchModuleById(moduleMenuStore.availableModules[0].id).then(() => { mapMenuStore.fetchLevels().then(() => { }).catch(() => alert("Нет доступных уровней для данного модуля")) @@ -53,8 +55,8 @@ const MapMenu: React.FC = observer(() => { return (
- {!user?.is_superuser - ? + {user?.is_superuser + ? : }
diff --git a/frontend/src/store/mapMenuStore.ts b/frontend/src/store/mapMenuStore.ts index 68ac160..b35ea16 100644 --- a/frontend/src/store/mapMenuStore.ts +++ b/frontend/src/store/mapMenuStore.ts @@ -1,23 +1,17 @@ import {makeAutoObservable} from "mobx"; import axios from "axios"; import {IMapType} from "../types/MapType.ts"; -import {IModuleType} from "../types/ModuleType.ts"; import {ILevelType} from "../types/LevelType/LevelType.ts"; import {IFetchLevelType} from "../types/LevelType/FetchLevelType.ts"; -import {IUserType} from "../types/UserType.ts"; +import moduleMenuStore from "./moduleMenuStore.ts"; class MapMenuStore { mapMenu: IMapType | null = null availableMaps: IMapType[] = [] currentMapId: string | null = null - currentModuleId: string | null = null currentLevelId: string | null = null - modulesMap: string[] = [] - availableModules: IModuleType[] = [] - currentModule: IModuleType | null = null - availableLevels: ILevelType[] = [] constructor() { @@ -51,13 +45,6 @@ class MapMenuStore { }) } - setModulesMap(newModulesMap: string[]) { - this.modulesMap = newModulesMap - } - - setAvailableModules(modules: IModuleType[]) { - this.availableModules = modules - } setAvailableLevels(levels: IFetchLevelType[]) { this.availableLevels = levels.map((level) => { @@ -71,94 +58,55 @@ class MapMenuStore { }) } - setCurrentModule(newModule: IModuleType) { - this.currentModule = newModule - } - - async fetchModules() { - await axios.get("http://localhost:8000/maps/" + this.currentMapId + "/modules/") - .then((response) => this.setAvailableModules(response.data)) - } - - async createModule(mapId: string, title: string, previousModuleId: string, nextModuleId: string) { - axios.post("http://localhost:8000/maps/" + mapId + "/modules/", { - map_id: mapId, - title: title, - previous_module_id: previousModuleId, - next_module_id: nextModuleId, - }) - } - - async fetchModuleById(id: string) { - await axios.get("http://localhost:8000/maps/" + this.currentMapId + "/modules/" + id).then((response) => { - this.setCurrentModule(response.data) - this.currentModuleId = response.data.id - }) - } async fetchLevels() { - await axios.get("http://localhost:8000/maps/" + this.currentMapId + "/modules/" + this.currentModuleId + "/levels/") + await axios.get("http://localhost:8000/maps/" + this.currentMapId + "/modules/" + moduleMenuStore.currentModuleId + "/levels/") .then((response) => this.setAvailableLevels(response.data)) } - async fetchLevelById(id: string) { - await axios.get("http://localhost:8000/maps/" + this.currentMapId + "/modules/" + this.currentModuleId + "/levels/" + id).then((response) => { - this.currentLevelId = response.data - }) - } - - 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 - }) - } - - createTheoryUnit() { - axios.post("http://localhost:8000/maps/" + this.currentMapId + "/modules/" + this.currentModuleId + "/levels/" + this.currentLevelId + "/theory", { - title: "Заголовок 1", - content: "Контент" - }) - } - - createTaskUnit() { - axios.post("http://localhost:8000/maps/" + this.currentMapId + "/modules/" + this.currentModuleId + "/levels/" + this.currentLevelId + "/tasks", { - type: "test", - score_reward: 100, - requires_review: false - }) - } - - addQuestionToTaskUnit() { - axios.post("http://localhost:8000/maps/" + this.currentMapId + "/modules/" + this.currentModuleId - + "/levels/" + this.currentLevelId + "/tasks/" + "b12de86e-fcd9-4761-89f0-b80d9583822d", - { - type: "singlechoice", - question: "Кто такой вопрос?", - possible_answers: [ - { - answer: "Я", - is_correct: false - }, - { - answer: "Не я", - is_correct: true - }, - { - answer: "Не ты", - is_correct: false - } - ] - }) - } + // async fetchLevelById(id: string) { + // await axios.get("http://localhost:8000/maps/" + this.currentMapId + "/modules/" + this.currentModuleId + "/levels/" + id).then((response) => { + // this.currentLevelId = response.data + // }) + // } + + // createTheoryUnit() { + // axios.post("http://localhost:8000/maps/" + this.currentMapId + "/modules/" + this.currentModuleId + "/levels/" + this.currentLevelId + "/theory", { + // title: "Заголовок 1", + // content: "Контент" + // }) + // } + + // createTaskUnit() { + // axios.post("http://localhost:8000/maps/" + this.currentMapId + "/modules/" + this.currentModuleId + "/levels/" + this.currentLevelId + "/tasks", { + // type: "test", + // score_reward: 100, + // requires_review: false + // }) + // } + + // addQuestionToTaskUnit() { + // axios.post("http://localhost:8000/maps/" + this.currentMapId + "/modules/" + this.currentModuleId + // + "/levels/" + this.currentLevelId + "/tasks/" + "b12de86e-fcd9-4761-89f0-b80d9583822d", + // { + // type: "singlechoice", + // question: "Кто такой вопрос?", + // possible_answers: [ + // { + // answer: "Я", + // is_correct: false + // }, + // { + // answer: "Не я", + // is_correct: true + // }, + // { + // answer: "Не ты", + // is_correct: false + // } + // ] + // }) + // } } export default new MapMenuStore() diff --git a/frontend/src/store/moduleMenuStore.ts b/frontend/src/store/moduleMenuStore.ts new file mode 100644 index 0000000..b6c4672 --- /dev/null +++ b/frontend/src/store/moduleMenuStore.ts @@ -0,0 +1,64 @@ +import {makeAutoObservable} from "mobx"; +import {IModuleType} from "../types/ModuleType.ts"; +import axios from "axios"; +import mapMenuStore from "./mapMenuStore.ts"; + +class ModuleMenuStore { + currentModuleId: string | null = null + modulesMap: string[] = [] + availableModules: IModuleType[] = [] + currentModule: IModuleType | null = null + constructor() { + makeAutoObservable(this) + } + + setModulesMap(newModulesMap: string[]) { + this.modulesMap = newModulesMap + } + + setAvailableModules(modules: IModuleType[]) { + this.availableModules = modules + } + + setCurrentModule(newModule: IModuleType) { + this.currentModule = newModule + } + + async fetchModules() { + await axios.get("http://localhost:8000/maps/" + mapMenuStore.currentMapId + "/modules/") + .then((response) => this.setAvailableModules(response.data)) + } + + async createModule(mapId: string, title: string, previousModuleId: string, nextModuleId: string) { + axios.post("http://localhost:8000/maps/" + mapId + "/modules/", { + map_id: mapId, + title: title, + previous_module_id: previousModuleId, + next_module_id: nextModuleId, + }) + } + + async fetchModuleById(id: string) { + await axios.get("http://localhost:8000/maps/" + mapMenuStore.currentMapId + "/modules/" + id).then((response) => { + this.setCurrentModule(response.data) + this.currentModuleId = response.data.id + }) + } + + 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 ModuleMenuStore() diff --git a/frontend/src/store/superUserStore.ts b/frontend/src/store/superUserStore.ts index a86d3aa..fd0d8d7 100644 --- a/frontend/src/store/superUserStore.ts +++ b/frontend/src/store/superUserStore.ts @@ -3,12 +3,17 @@ import {IUserType} from "../types/UserType.ts"; class SuperUserStore { + allUsers: IUserType[] = [] + constructor() { makeAutoObservable(this) } - allUsers: IUserType = [] - + setAllUsers(fetchedUsers: IUserType[]) { + this.allUsers = fetchedUsers + } + + } export default new SuperUserStore()