Skip to content

Commit f2dcc7d

Browse files
committed
refactor: remove excess api calls (groups in stats)
1 parent 686f6f6 commit f2dcc7d

3 files changed

Lines changed: 7 additions & 16 deletions

File tree

hwproj.front/src/components/Common/GroupSelector.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ const GroupSelector: FC<GroupSelectorProps> = (props) => {
158158
renderInput={(params) => (
159159
<TextField
160160
{...params}
161-
label="Группа (не обязательно)"
161+
label="Группа (необязательно)"
162162
placeholder="Выберите группу"
163163
variant="outlined"
164164
/>

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -417,6 +417,7 @@ const Course: React.FC = () => {
417417
isMentor={isCourseMentor}
418418
course={courseState.course}
419419
solutions={studentSolutions}
420+
groups={groups}
420421
/>
421422
</Grid>
422423
</Grid>}

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

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ interface IStudentStatsProps {
1919
isMentor: boolean;
2020
userId: string;
2121
solutions: StatisticsCourseMatesModel[] | undefined;
22+
groups: Group[];
2223
}
2324

2425
interface IStudentStatsState {
@@ -144,19 +145,6 @@ const StudentStats: React.FC<IStudentStatsProps> = (props) => {
144145
.forEach(x => bestTaskSolutions.set(x.taskId!, x.studentId!))
145146
}
146147

147-
const [groups, setGroups] = useState<Group[]>([]);
148-
useEffect(() => {
149-
const loadGroups = async () => {
150-
try {
151-
const courseGroups = await ApiSingleton.courseGroupsApi.courseGroupsGetAllCourseGroupsWithNames(+courseId!);
152-
setGroups(courseGroups);
153-
} catch (error) {
154-
console.error('Failed to load groups:', error);
155-
}
156-
};
157-
loadGroups();
158-
}, [courseId]);
159-
160148
return (
161149
<div>
162150
{props.solutions === undefined && <LinearProgress/>}
@@ -270,7 +258,7 @@ const StudentStats: React.FC<IStudentStatsProps> = (props) => {
270258
.reduce((sum, rating) => sum + rating, 0)
271259
const homeworksMaxSum = notTests
272260
.filter(h => !h.tags!.includes(BonusTag) &&
273-
(groups.find(g => g.id === h.groupId)?.studentsIds?.includes(cm.id!) || !h.groupId))
261+
(props.groups.find(g => g.id === h.groupId)?.studentsIds?.includes(cm.id!) || !h.groupId))
274262
.flatMap(homework => homework.tasks)
275263
.reduce((sum, task) => {
276264
return sum + (task!.tags!.includes(BonusTag) ? 0 : (task!.maxRating || 0));
@@ -372,7 +360,9 @@ const StudentStats: React.FC<IStudentStatsProps> = (props) => {
372360
{homeworks.map((homework, idx) =>
373361
homework.tasks!.map((task, i) => {
374362
const additionalStyles = i === 0 && homeworkStyles(homeworks, idx)
375-
const isDisabled = homework.groupId ? !groups.find(g => g.id === homework.groupId)?.studentsIds?.includes(cm.id!) : false
363+
const isDisabled = homework.groupId
364+
? !props.groups.find(g => g.id === homework.groupId)?.studentsIds?.includes(cm.id!)
365+
: false
376366
return <StudentStatsCell
377367
key={`${cm.id}-${homework.id}-${task.id}`}
378368
solutions={cm.homeworks

0 commit comments

Comments
 (0)