Skip to content

Commit a93daa0

Browse files
committed
StudentStats: прогресс бар загрузки
1 parent 723f915 commit a93daa0

File tree

2 files changed

+12
-11
lines changed

2 files changed

+12
-11
lines changed

hwproj.front/src/components/Courses/Course.tsx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ const Course: React.FC = () => {
8888
studentSolutions: [],
8989
showQrCode: false
9090
})
91-
const [studentSolutions, setStudentSolutions] = useState<StatisticsCourseMatesModel[]>([])
91+
const [studentSolutions, setStudentSolutions] = useState<StatisticsCourseMatesModel[] | undefined>(undefined)
9292
const [courseFilesState, setCourseFilesState] = useState<ICourseFilesState>({
9393
processingFilesState: {},
9494
courseFiles: []
@@ -126,7 +126,7 @@ const Course: React.FC = () => {
126126
}
127127
}));
128128
}
129-
129+
130130
const stopProcessing = (homeworkId: number) => {
131131
if (intervalsRef.current[homeworkId]) {
132132
const {interval, timeout} = intervalsRef.current[homeworkId];
@@ -312,7 +312,7 @@ const Course: React.FC = () => {
312312
ApiSingleton.statisticsApi.statisticsGetCourseStatistics(+courseId!)
313313
.then(res => setStudentSolutions(res))
314314
}, [courseId])
315-
315+
316316
useEffect(() => changeTab(tab || "homeworks"), [tab, courseId, isFound])
317317

318318
const joinCourse = async () => {
@@ -323,7 +323,7 @@ const Course: React.FC = () => {
323323
const {tabValue} = pageState
324324
const searchedHomeworkId = searchParams.get("homeworkId")
325325

326-
const unratedSolutionsCount = studentSolutions
326+
const unratedSolutionsCount = (studentSolutions || [])
327327
.flatMap(x => x.homeworks)
328328
.flatMap(x => x!.tasks)
329329
.filter(t => t!.solution!.slice(-1)[0]?.state === 0) //last solution
@@ -492,7 +492,7 @@ const Course: React.FC = () => {
492492
homeworks={courseHomeworks}
493493
courseFilesInfo={courseFilesState.courseFiles}
494494
isMentor={isCourseMentor}
495-
studentSolutions={studentSolutions}
495+
studentSolutions={studentSolutions || []}
496496
isStudentAccepted={isAcceptedStudent}
497497
selectedHomeworkId={searchedHomeworkId == null ? undefined : +searchedHomeworkId}
498498
userId={userId!}

hwproj.front/src/components/Courses/StudentStats.tsx

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import React, {useEffect, useState} from "react";
22
import {CourseViewModel, HomeworkViewModel, StatisticsCourseMatesModel} from "@/api";
33
import {useNavigate, useParams} from 'react-router-dom';
4-
import {Table, TableBody, TableCell, TableContainer, TableHead, TableRow} from "@material-ui/core";
4+
import {LinearProgress, Table, TableBody, TableCell, TableContainer, TableHead, TableRow} from "@material-ui/core";
55
import StudentStatsCell from "../Tasks/StudentStatsCell";
66
import {Alert, Button, Chip, Typography} from "@mui/material";
77
import {grey} from "@material-ui/core/colors";
@@ -15,7 +15,7 @@ interface IStudentStatsProps {
1515
homeworks: HomeworkViewModel[];
1616
isMentor: boolean;
1717
userId: string;
18-
solutions: StatisticsCourseMatesModel[];
18+
solutions: StatisticsCourseMatesModel[] | undefined;
1919
}
2020

2121
interface IStudentStatsState {
@@ -55,7 +55,7 @@ const StudentStats: React.FC<IStudentStatsProps> = (props) => {
5555

5656
const homeworks = props.homeworks.filter(h => h.tasks && h.tasks.length > 0)
5757
const solutions = searched
58-
? props.solutions.filter(cm => (cm.surname + " " + cm.name).toLowerCase().includes(searched.toLowerCase()))
58+
? props.solutions?.filter(cm => (cm.surname + " " + cm.name).toLowerCase().includes(searched.toLowerCase()))
5959
: props.solutions
6060

6161
const borderStyle = `1px solid ${greyBorder}`
@@ -100,7 +100,8 @@ const StudentStats: React.FC<IStudentStatsProps> = (props) => {
100100

101101
return (
102102
<div>
103-
{solutions.length === 0 && <Alert severity="info">
103+
{props.solutions === undefined && <LinearProgress/>}
104+
{props.solutions && props.solutions.length === 0 && <Alert severity="info">
104105
На курс пока ещё никто не записался
105106
</Alert>}
106107
{searched &&
@@ -146,7 +147,7 @@ const StudentStats: React.FC<IStudentStatsProps> = (props) => {
146147
<TableRow>
147148
<TableCell style={{zIndex: 10}}
148149
component="td">
149-
{solutions.length > 0 &&
150+
{solutions && solutions.length > 0 &&
150151
<Button startIcon={<ShowChartIcon/>} color="primary"
151152
style={{backgroundColor: 'transparent'}} size='medium'
152153
onClick={handleClick}>
@@ -190,7 +191,7 @@ const StudentStats: React.FC<IStudentStatsProps> = (props) => {
190191
</TableRow>
191192
</TableHead>
192193
<TableBody>
193-
{solutions.map((cm, index) => {
194+
{solutions && solutions.map((cm, index) => {
194195
const homeworksSum = notTests
195196
.flatMap(homework =>
196197
solutions

0 commit comments

Comments
 (0)