Skip to content

Commit

Permalink
добавляет монетки
Browse files Browse the repository at this point in the history
  • Loading branch information
semant1cs committed Dec 17, 2023
1 parent 6ad4412 commit 209765d
Show file tree
Hide file tree
Showing 7 changed files with 108 additions and 44 deletions.
1 change: 1 addition & 0 deletions frontend/src/components/authentication/AuthForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ const AuthForm: React.FC = observer(() => {

const onHandleSubmit = useCallback((data: { login: string, password: string }) => {
authStore.signIn(data.login, data.password).then(() => navigateTo('/map'))
authStore.setUser(data.login)
}, [])

return (
Expand Down
84 changes: 65 additions & 19 deletions frontend/src/components/mapMenu/EmployeeMap/EmployeeMap.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, {useEffect} from 'react';
import React, {useEffect, useState} from 'react';

import Coins from "../UIMapMenu/Coins.tsx";
import ChooseModuleWindow from "../UIMapMenu/ChooseModuleWindow.tsx";
Expand All @@ -11,9 +11,11 @@ import {observer} from "mobx-react-lite";

import moduleMenuStore from "../../../store/moduleMenuStore.ts";
import mapMenuStore from "../../../store/mapMenuStore.ts"
import levelStore from "../../../store/levelStore.ts";

import {IUserType} from "../../../types/UserType.ts";
import levelStore from "../../../store/levelStore.ts";
import axios from "axios";
import Starfield from "react-starfield";


interface IEmployeeMap {
Expand All @@ -23,37 +25,81 @@ interface IEmployeeMap {
}

const EmployeeMap: React.FC<IEmployeeMap> = observer(({user, formattedDate, logOut}) => {
const [isLoading, setIsLoading] = useState<boolean>(true)
const [employee, setEmployee] = useState(null)

useEffect(() => {
// console.log(user)
axios.get("http://localhost:8000/employees").then((r) => {
r.data.map((employee) => {
if (user?.id === employee.user.id) {
setEmployee(employee)
setIsLoading(false)
}
})
})
}, []);

useEffect(() => {
mapMenuStore.fetchAvailableMaps().then(() => {
mapMenuStore.fetchMapById(mapMenuStore.availableMaps[0].id).then(() => {
moduleMenuStore.fetchModules().then(() => {
moduleMenuStore.fetchModuleById(moduleMenuStore.availableModules[0].id).then(() => {
levelStore.fetchLevels().then(() => {

}).catch(() => alert("Нет доступных уровней для данного модуля"))
})
})
}).catch(() => alert("Нет доступных модулей для данной карты"))
})
}).catch(() => alert("Нет доступных карт для данного пользователя"))
}, []);

return (
<div className="employee-interface">
<Coins coins={100} additionalClassname="coins"/>
<ChooseModuleWindow moduleName={moduleMenuStore.choosedModule?.title.toUpperCase()}/>
<UserProfile logOut={logOut} user={user} formattedDate={formattedDate}/>
<CustomProgressBar className="progress-bar-wrapper" progress={54}/>
<div className="geolocations">
<div className="geolocations__wrapper">
{levelStore.availableLevels.map((level, index) => {
return <Level
id={(index + 1).toString()}
level={level}
/>
})}
isLoading ? (
<Starfield
starCount={1000}
starColor={[255, 255, 255]}
speedFactor={0.05}
backgroundColor="black"
/>
)
:
(
<div className="employee-interface">
<Starfield
starCount={1000}
starColor={[255, 255, 255]}
speedFactor={0.05}
backgroundColor="black"
/>
<Coins
coins={employee ? employee.coins : 0}
additionalClassname="coins"
/>
<ChooseModuleWindow
moduleName={moduleMenuStore.choosedModule?.title.toUpperCase()}
/>
<UserProfile
logOut={logOut}
user={user}
formattedDate={formattedDate}
/>
<CustomProgressBar
className="progress-bar-wrapper"
progress={54}
/>
<div className="geolocations">
<div className="geolocations__wrapper">
{levelStore.availableLevels.map((level, index) => {
return <Level
key={level.id}
id={(index + 1).toString()}
level={level}
/>
})}
</div>
</div>
</div>
</div>
</div>
)
);
});

Expand Down
36 changes: 20 additions & 16 deletions frontend/src/components/mapMenu/MapMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,13 @@ const MapMenu: React.FC = observer(() => {
const navigate = useNavigate()

const [user, setUser] = useState<IUserType>()
const [formattedDate, setFormattedDate] = useState("")
const [formattedDate, setFormattedDate] = useState<string>("")
const [isLoading, setIsLoading] = useState<boolean>(true)

useEffect(() => {
axios.get("http://localhost:8000/users/").then((response) => {
response.data.map((user: IUserType) => {
if (user.username === authStore.userLogin) {
if (user.email === authStore.nickname) {
setUser(user)
}
})
Expand All @@ -36,6 +37,7 @@ const MapMenu: React.FC = observer(() => {
const date = new Date(Date.parse(user!.registered_at))
setFormattedDate(`${date.getDay()}.${date.getMonth()}.${date.getUTCFullYear()}`)
}
setIsLoading(false)
})
}, [])

Expand All @@ -52,20 +54,22 @@ const MapMenu: React.FC = observer(() => {

return (
<div>
<Starfield
starCount={1000}
starColor={[255, 255, 255]}
speedFactor={0.05}
backgroundColor="black"
/>
{
user?.is_superuser
? <SuperUserMap/>
: <EmployeeMap
logOut={handleOnLogOut}
user={user}
formattedDate={formattedDate}
/>
{isLoading
? <Starfield
starCount={1000}
starColor={[255, 255, 255]}
speedFactor={0.05}
backgroundColor="black"
/>
: (
user?.is_superuser
? <SuperUserMap/>
: <EmployeeMap
logOut={handleOnLogOut}
user={user}
formattedDate={formattedDate}
/>
)
}
</div>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ const CreateUnit: React.FC<IPropTypes> =
currentUnitId,
availableUnits
}) => {
let btnText = ""
let btnText: string

if (unitName === "map") {
btnText = "Удалить выбранную карту"
Expand All @@ -48,6 +48,7 @@ const CreateUnit: React.FC<IPropTypes> =
<option
key={unit.id}
value={unit.title}
// @ts-ignore: Unreachable code error
onClick={() => handleOnClickOptionUnit(unit, index)}
>
{unit.title}
Expand Down
19 changes: 14 additions & 5 deletions frontend/src/components/mapMenu/UIMapMenu/Level/ModalLevelBody.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,21 @@ interface IModalLevelProps {
const ModalLevelBody: React.FC<IModalLevelProps> = observer(({level}) => {
const bodyHeader = renderBodyHeader()


const menuItems: IMenuItemType[] = [
{
type: "theory",
length: level?.theoryUnits.length,
length: level.theoryUnits ? level.theoryUnits.length : 0,
item: level?.theoryUnits
},
{
length: level?.taskUnits.length,
length: level.taskUnits ? level?.taskUnits.length : 0,
type: "tests",
item: level?.taskUnits
},
{
type: "task",
length: level.taskUnits ? level?.taskUnits.length : 0,
item: level?.taskUnits
}
]

Expand Down Expand Up @@ -101,18 +105,23 @@ const ModalLevelBody: React.FC<IModalLevelProps> = observer(({level}) => {
</form>
</div>
)
case ("task"):
return (
<div>
{unit.title}
{unit.content}
</div>
)
default:
return (<div>Блок пуст</div>)
}
}

function renderTasks(menuItems?: IMenuItemType[], theoryUnits?: ITheoryUnitType[], taskUnits?: ITaskType[]) {
console.log(levelStore.chosenTaskIndex)
if (menuItems && levelStore.chosenTaskIndex <= menuItems[0].length)
return renderChosenTask(theoryUnits[levelStore.chosenTaskIndex - 1], "theory")
if (menuItems && levelStore.chosenTaskIndex <= menuItems[0].length + menuItems[1].length)
return renderChosenTask(taskUnits[levelStore.chosenTaskIndex - menuItems[0].length - 1], "test")

}

return (
Expand Down
8 changes: 5 additions & 3 deletions frontend/src/store/authStore.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
import {makeAutoObservable} from "mobx";
import axios from "axios";


class AuthStore {
isUserAuthorized: boolean = false

// userRole: string | null = null
nickname: string | null = null

constructor() {
makeAutoObservable(this)
}

setUser(nickname: string) {
this.nickname = nickname
}

async signIn(login: string, password: string) {
await axios.post("http://localhost:8000/auth/login", {
username: login,
Expand Down
1 change: 1 addition & 0 deletions frontend/src/types/UserType.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
export interface IUserType {
username: string,
email: string,
id: string,
registered_at: string,
is_superuser: boolean
}

0 comments on commit 209765d

Please sign in to comment.