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 6ffff66 commit c8180bd
Show file tree
Hide file tree
Showing 10 changed files with 64 additions and 37 deletions.
1 change: 1 addition & 0 deletions frontend/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Montserrat:wght@500&family=Oswald&display=swap"
rel="stylesheet">
<link rel="shortcut icon" href="#">
</head>
<body>
<div id="root">
Expand Down
29 changes: 18 additions & 11 deletions frontend/src/components/mapMenu/MapMenu.tsx
Original file line number Diff line number Diff line change
@@ -1,31 +1,38 @@
import React, {useEffect} from 'react';
import CustomButton from "../../UIComponents/customButton/CustomButton.tsx";
import authStore from "../../store/authStore.ts";
import {useNavigate} from "react-router-dom";
import Coins from "./UIMapMenu/Coins.tsx";
import './../../styles/mapMenu.scss'
import ChooseModuleWindow from "./UIMapMenu/ChooseModuleWindow.tsx";
import UserProfile from "./UIMapMenu/UserProfile.tsx";
import {GeolocationType} from "../../types/GeolocationType.ts";
import StarUnit from "./UIMapMenu/Level/StarUnit.tsx";
import mapMenuStore from "../../store/mapMenuStore.ts";
import {ILevelType} from "../../types/LevelType.ts";

const MapMenu: React.FC = () => {
const navigate = useNavigate()

useEffect(() => {
if (!authStore.isUserAuthorized)
navigate("/")

mapMenuStore.fetchAvailableMaps().then(() => {
mapMenuStore.fetchMapById(mapMenuStore.availableMaps[0].id).then(() => {
mapMenuStore.setModulesMap(mapMenuStore?.mapMenu?.modules_ids)
console.log(mapMenuStore.modulesMap.join(" "))
})
})
}, [navigate])

const onHandleSignOut = () => {
authStore.logOutUser().then()
navigate('/')
}
// const onHandleSignOut = () => {
// authStore.logOutUser().then()
// navigate('/')
// }

const geolocations: GeolocationType[] = [
const geolocations: ILevelType[] = [
{
id: 1,
level: {
id: "1",
levels: {
levelName: "Уровень 1",
title: "Собери помидорки",
menu: [{
Expand All @@ -35,7 +42,7 @@ const MapMenu: React.FC = () => {
}
},
{
id: 2,
id: "2",
level: {
levelName: "Уровень 2",
title: "Собери не помидорки",
Expand All @@ -46,7 +53,7 @@ const MapMenu: React.FC = () => {
}
},
{
id: 3,
id: "3",
level: {
levelName: "Уровень 3",
title: "Начни текст",
Expand Down
6 changes: 3 additions & 3 deletions frontend/src/routes/AppRouter.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import React from 'react';
import {Navigate, Route, Routes, useLocation} from "react-router-dom";
import {RouteType} from "../types/RouteType.ts";
import {IRouteType} from "../types/RouteType.ts";
import WelcomePage from "../components/welcomePage/WelcomePage.tsx";
import Authentication from "../components/authentication/Authentication.tsx";
import MapMenu from "../components/mapMenu/MapMenu.tsx";
import authStore from "../store/authStore.ts";
import {observer} from "mobx-react-lite";

const AppRouter: React.FC = observer(() => {
const publicRoutes: RouteType[] = [
const publicRoutes: IRouteType[] = [
{
id: 1,
element: <WelcomePage/>,
Expand All @@ -21,7 +21,7 @@ const AppRouter: React.FC = observer(() => {
}
]

const privateRoutes: RouteType[] = [
const privateRoutes: IRouteType[] = [
{
id: 2,
element: <Authentication/>,
Expand Down
26 changes: 17 additions & 9 deletions frontend/src/store/mapMenuStore.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
import {makeAutoObservable} from "mobx";
import axios from "axios";
import {IModuleType} from "../types/ModuleType.ts";

class MapMenuStore {
mapMenu: object | null = null
titleMap: string = ""
idMap: string = ""
idsModules: string[] = []

availableMaps: string[] = []
currentMap: string = ""
mapMenu: IModuleType[] = []
availableMaps: { id: string }[] = []

constructor() {
makeAutoObservable(this)
Expand All @@ -18,9 +14,21 @@ class MapMenuStore {
await axios.get("http://localhost:8000/maps/").then((response) => this.availableMaps = response.data)
}

fetchMapById(id: string) {
axios.get("http://localhost:8000/maps/" + id).then((response) => this.mapMenu = response.data)
async fetchMapById(id: string) {
await axios.get("http://localhost:8000/maps/" + id).then((response) => this.mapMenu = response.data)
}

// setModulesMap(newModulesMap: IModuleType[]) {
// this.modulesMap = newModulesMap
// }

// updateMapById(id: string) {
// axios.patch(id, {
// id: id,
// title: "Карта 1",
// modules_ids: ["3fa85f64-5717-4562-b3fc-2c963f66afa6", "3fa85f64-5717-4562-b3fc-2c963f66afa7"]
// })
// }
}

export default new MapMenuStore()
6 changes: 0 additions & 6 deletions frontend/src/types/GeolocationType.ts

This file was deleted.

13 changes: 8 additions & 5 deletions frontend/src/types/LevelType.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import {TaskType} from "./TaskType.ts";
import {ITaskType} from "./TaskType.ts";

export type LevelType = {
levelName: string,
title: string
menu: TaskType[]
export interface ILevelType {
id: string,
levels: {
levelName: string,
title: string
menu: ITaskType[]
}[]
}
7 changes: 7 additions & 0 deletions frontend/src/types/MapType.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import {IModuleType} from "./ModuleType.ts";

export interface IMapType {
id: string,
title: string,
modules_ids: IModuleType[]
}
8 changes: 8 additions & 0 deletions frontend/src/types/ModuleType.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import {ILevelType} from "./LevelType.ts";

export interface IModuleType {
mapId: string,
title: string,
moduleId: string,
modules_ids: ILevelType[]
}
3 changes: 1 addition & 2 deletions frontend/src/types/RouteType.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import {ReactNode} from "react";

interface RouteType {
export interface IRouteType {
id: number
path: string,
element: ReactNode
}

export type {RouteType}
2 changes: 1 addition & 1 deletion frontend/src/types/TaskType.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export type TaskType = {
export interface ITaskType {
taskName: string,
body: string
}

0 comments on commit c8180bd

Please sign in to comment.