Skip to content

Commit fa9607e

Browse files
committed
refactor: union creation of selected group
1 parent 328b65e commit fa9607e

1 file changed

Lines changed: 9 additions & 10 deletions

File tree

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

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,16 @@ const GroupSelector: FC<GroupSelectorProps> = (props) => {
4444
const [isSubmitting, setIsSubmitting] = useState(false);
4545
const [isError, setIsError] = useState(false);
4646

47+
const selectedGroup = useMemo(() =>
48+
groups.find(g => g.id === props.selectedGroupId),
49+
[groups, props.selectedGroupId]);
50+
51+
const studentsWithousGroup = useMemo(() => {
52+
const studentsInGroups = groups.flatMap(g => g.studentsIds)
53+
return props.courseStudents.filter((cm) => !studentsInGroups.includes(cm.userId))
54+
}, [groups, props.courseStudents]);
55+
4756
const handleOpenEditDialog = () => {
48-
const selectedGroup = groups.find(g => g.id === props.selectedGroupId);
4957
setFormState({
5058
name: selectedGroup?.name || "",
5159
memberIds: selectedGroup?.studentsIds || []
@@ -62,8 +70,6 @@ const GroupSelector: FC<GroupSelectorProps> = (props) => {
6270
const handleSubmitEdit = async () => {
6371
setIsSubmitting(true);
6472
try {
65-
const selectedGroup = groups.find(g => g.id === props.selectedGroupId);
66-
6773
if (selectedGroup) {
6874
await ApiSingleton.courseGroupsApi.courseGroupsUpdateCourseGroup(
6975
props.courseId,
@@ -96,13 +102,6 @@ const GroupSelector: FC<GroupSelectorProps> = (props) => {
96102
}
97103
}
98104

99-
const studentsWithousGroup = useMemo(() => {
100-
const studentsInGroups = groups.flatMap(g => g.studentsIds)
101-
return props.courseStudents.filter((cm) => !studentsInGroups.includes(cm.userId))
102-
}, [groups, props.courseStudents]);
103-
104-
const selectedGroup = groups.find(g => g.id === props.selectedGroupId);
105-
106105
return (
107106
<Grid item xs={12} style={{marginBottom: "15px", marginTop: 1}}>
108107
{props.choiceDisabled ? (

0 commit comments

Comments
 (0)