Skip to content

Commit 62b8485

Browse files
committed
wip
1 parent 131448a commit 62b8485

2 files changed

Lines changed: 22 additions & 9 deletions

File tree

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

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -33,20 +33,27 @@ interface GroupSelectorProps {
3333

3434
const GroupSelector: FC<GroupSelectorProps> = (props) => {
3535
const groups = [...(props.groups || []), {id: undefined, name: "Все студенты"}]
36+
const selectedGroup = groups.find(g => g.id === props.selectedGroupId)
3637

3738
const [isDialogOpen, setIsDialogOpen] = useState(false);
3839
const [formState, setFormState] = useState<{
3940
name: string,
4041
memberIds: string[]
4142
}>({
42-
name: "",
43-
memberIds: []
43+
name: selectedGroup?.name || "",
44+
memberIds: selectedGroup?.studentsIds || []
4445
});
46+
47+
useEffect(() => {
48+
setFormState({
49+
name: selectedGroup?.name || "",
50+
memberIds: selectedGroup?.studentsIds || []
51+
})
52+
}, [props.selectedGroupId])
53+
4554
const [isSubmitting, setIsSubmitting] = useState(false);
4655
const [isError, setIsError] = useState(false);
4756

48-
const selectedGroup = groups.find(g => g.id === props.selectedGroupId)
49-
5057
const studentsWithoutGroup = useMemo(() => {
5158
const studentsInGroups = groups.flatMap(g => g.studentsIds)
5259
return props.courseStudents.filter((cm) => !studentsInGroups.includes(cm.userId))
@@ -105,7 +112,8 @@ const GroupSelector: FC<GroupSelectorProps> = (props) => {
105112
<Grid container xs={12} spacing={1}>
106113
<Grid item xs={12}>
107114
<Autocomplete
108-
freeSolo
115+
freeSolo={props.selectedGroupId !== undefined}
116+
disableClearable={props.selectedGroupId === undefined}
109117
fullWidth
110118
options={[...groups]}
111119
getOptionLabel={(option) => typeof option === 'string' ? option : option?.name || "Все студенты"}
@@ -114,6 +122,11 @@ const GroupSelector: FC<GroupSelectorProps> = (props) => {
114122
if (typeof newGroup === 'string') return
115123
props.onGroupIdChange(newGroup?.id)
116124
}}
125+
onInputChange={(_, newInputValue, reason) => {
126+
if (reason === 'input' && props.selectedGroupId !== undefined) {
127+
setFormState(prevState => ({...prevState, name: newInputValue}))
128+
}
129+
}}
117130
renderInput={(params) => (
118131
<TextField
119132
{...params}
@@ -124,8 +137,8 @@ const GroupSelector: FC<GroupSelectorProps> = (props) => {
124137
)}
125138
/>
126139
</Grid>
127-
{selectedGroup && <Grid item xs={12}>
128-
<Stack direction={"column"}>
140+
{props.selectedGroupId && selectedGroup && <Grid item xs={12}>
141+
<Stack direction={"column"} spacing={1}>
129142
<Autocomplete
130143
multiple
131144
fullWidth
@@ -174,7 +187,7 @@ const GroupSelector: FC<GroupSelectorProps> = (props) => {
174187
<Button
175188
onClick={handleSubmitEdit}
176189
color="primary"
177-
variant="contained"
190+
variant="outlined"
178191
disabled={isSubmitting || !formState.name.trim() || formState.memberIds.length === 0}
179192
>
180193
{isSubmitting ? <CircularProgress size={24}/> : selectedGroup ? "Сохранить" : "Создать"}

hwproj.front/src/components/Homeworks/CourseHomeworkExperimental.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -413,7 +413,7 @@ const CourseHomeworkEditor: FC<{
413413
confirmationText={''}
414414
/>
415415
</CardContent>}
416-
{page === "group" && <CardContent style={{minHeight: 500}}>
416+
{page === "group" && <CardContent style={{minHeight: 500, width: '100%'}}>
417417
<GroupSelector
418418
courseId={courseId}
419419
courseStudents={courseStudents}

0 commit comments

Comments
 (0)