Skip to content

Commit

Permalink
добавляет отображение вопросов в уровне
Browse files Browse the repository at this point in the history
  • Loading branch information
semant1cs committed Nov 20, 2023
1 parent 9f13959 commit afab79b
Show file tree
Hide file tree
Showing 10 changed files with 86 additions and 20 deletions.
2 changes: 1 addition & 1 deletion frontend/src/components/mapMenu/MapMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ const MapMenu: React.FC = observer(() => {
<div className="geolocations__wrapper">
{mapMenuStore.availableLevels.map((level, index) => {
return <Module id={(index + 1).toString()} key={level.id} title={level.title}
theoryUnits={level.theory_units}/>
theoryUnits={level.theoryUnits} taskUnits={level.taskUnits}/>
})}
</div>
</div>
Expand Down
30 changes: 25 additions & 5 deletions frontend/src/components/mapMenu/UIMapMenu/Level/ModalLevelBody.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,21 @@ import "./modalLevelBody.scss"
import ArrowLeft from "../UIChooseModule/ArrowLeft.tsx";
import ArrowRight from "../UIChooseModule/ArrowRight.tsx";
import {ITheoryUnitType} from "../../../../types/TheoryUnitType.ts";
import {ITaskType} from "../../../../types/TaskType.ts";

interface IModalLevelProps {
title: string,
theoryUnits?: ITheoryUnitType[]
theoryUnits?: ITheoryUnitType[],
taskUnits?: ITaskType[]
}

const ModalLevelBody: React.FC<IModalLevelProps> = ({title, theoryUnits}) => {
const ModalLevelBody: React.FC<IModalLevelProps> = ({title, theoryUnits, taskUnits}) => {
const tasks = [
{name: "theory", element: <Theory/>},
{name: "video", element: <Video/>},
{name: "test", element: <Test/>}
]

console.log(theoryUnits)

const [currentTaskIndex, setCurrentTaskIndex] = useState(0)

const renderMenuTheoryBlocks = (countTheoryBlocks: number) => {
Expand All @@ -30,6 +30,17 @@ const ModalLevelBody: React.FC<IModalLevelProps> = ({title, theoryUnits}) => {
return theoryBlocks
}

const renderMenuTaskBlocks = (countTheoryBlocks: number, countTaskBlocks: number) => {
const taskBlocks: JSX.Element[] = []

for (let i = countTheoryBlocks; i < countTaskBlocks + countTheoryBlocks; i++) {
taskBlocks.push(<div key={i} className="menu-item" onClick={() => {
setCurrentTaskIndex(i)
}}>{tasks[2].element}</div>)
}
return taskBlocks
}

return (
<div>
<div className="header-modal">
Expand All @@ -45,7 +56,8 @@ const ModalLevelBody: React.FC<IModalLevelProps> = ({title, theoryUnits}) => {
</div>

{theoryUnits && theoryUnits.length !== 0
? <div className="menu">{renderMenuTheoryBlocks(theoryUnits!.length)}</div>
? <div
className="menu">{renderMenuTheoryBlocks(theoryUnits!.length)}{renderMenuTaskBlocks(theoryUnits!.length, taskUnits!.length)}</div>
: ""}

{theoryUnits![currentTaskIndex] !== undefined &&
Expand All @@ -55,6 +67,14 @@ const ModalLevelBody: React.FC<IModalLevelProps> = ({title, theoryUnits}) => {
</div>
)
}

{taskUnits![currentTaskIndex] !== undefined &&
(<div className="text-info">
<div className="level-title">{taskUnits![currentTaskIndex].questions[0].question}</div>
{/*<div className="level-body">{taskUnits![currentTaskIndex].questions[0].possibleAnswers.map((answer) => answer.answer)}</div>*/}
</div>
)
}
</div>
);
};
Expand Down
10 changes: 7 additions & 3 deletions frontend/src/components/mapMenu/UIMapMenu/Level/Module.tsx
Original file line number Diff line number Diff line change
@@ -1,23 +1,27 @@
import React, {useState} from 'react';
import ModalWindow from "../../../../UIComponents/modalWindow/ModalWindow.tsx";
import ModalLevelBody from "./ModalLevelBody.tsx";
import {ITheoryUnitType} from "../../../../types/TheoryUnitType.ts";
import {ITaskType} from "../../../../types/TaskType.ts";

interface IModuleProps {
id: string,
title: string,
theoryUnits?: string[]
theoryUnits?: ITheoryUnitType[],
taskUnits?: ITaskType[]
}

const Module: React.FC<IModuleProps> = ({id, title, theoryUnits}) => {
const Module: React.FC<IModuleProps> = ({id, title, theoryUnits, taskUnits}) => {
const [isOpenModalWindow, setOpenModalWindow] = useState(false)
const classNameGeolocation = "geolocation-" + id

return (
<div onClick={() => setOpenModalWindow(!isOpenModalWindow)} className={classNameGeolocation}>

{isOpenModalWindow
? <ModalWindow
onClose={() => setOpenModalWindow(!isOpenModalWindow)}
body={<ModalLevelBody key={id} title={title} theoryUnits={theoryUnits}/>}
body={<ModalLevelBody key={id} title={title} theoryUnits={theoryUnits} taskUnits={taskUnits}/>}
/>
: ""}

Expand Down
15 changes: 12 additions & 3 deletions frontend/src/store/mapMenuStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ 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.ts";
import {ILevelType} from "../types/LevelType/LevelType.ts";
import {IFetchLevelType} from "../types/LevelType/FetchLevelType.ts";

class MapMenuStore {
mapMenu: IMapType | null = null
Expand Down Expand Up @@ -57,8 +58,16 @@ class MapMenuStore {
this.availableModules = modules
}

setAvailableLevels(levels: ILevelType[]) {
this.availableLevels = levels
setAvailableLevels(levels: IFetchLevelType[]) {
this.availableLevels = levels.map((level) => {
return {
id: level.id,
title: level.title,
body: level.body,
theoryUnits: level.theory_units,
taskUnits: level.task_units
}
})
}

setCurrentModule(newModule: IModuleType) {
Expand Down
5 changes: 5 additions & 0 deletions frontend/src/types/AnswerType.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export interface IAnswerType {
id: string,
questionId: string,
answer: string
}
6 changes: 0 additions & 6 deletions frontend/src/types/LevelType.ts

This file was deleted.

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

export interface IFetchLevelType {
id: string,
title: string,
body?: string,
theory_units?: ITheoryUnitType[]
task_units?: ITaskType[]
}
10 changes: 10 additions & 0 deletions frontend/src/types/LevelType/LevelType.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import {ITheoryUnitType} from "../TheoryUnitType.ts";
import {ITaskType} from "../TaskType.ts";

export interface ILevelType {
id: string,
title: string,
body?: string,
theoryUnits?: ITheoryUnitType[]
taskUnits?: ITaskType[]
}
9 changes: 9 additions & 0 deletions frontend/src/types/QuestionType.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import {IAnswerType} from "./AnswerType.ts";

export interface IQuestionType {
id: string
possibleAnswers: IAnswerType[]
question: string
taskId: string
type: string
}
9 changes: 7 additions & 2 deletions frontend/src/types/TaskType.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
import {IQuestionType} from "./QuestionType.ts";

export interface ITaskType {
id: string,
name: string,
body: string
levelId: string,
questions: IQuestionType[],
requiresReview: boolean,
scoreReward: number,
type: string
}

0 comments on commit afab79b

Please sign in to comment.