1- import { FC , useEffect , useMemo , useState } from "react" ;
1+ import { FC , useMemo , useState } from "react" ;
22import {
33 Grid ,
44 TextField ,
@@ -23,6 +23,7 @@ import { Group, AccountDataDto } from "@/api";
2323interface GroupSelectorProps {
2424 courseId : number ,
2525 courseStudents : AccountDataDto [ ] ,
26+ groups : Group [ ] ,
2627 onGroupIdChange : ( groupId ?: number ) => void ,
2728 onGroupsUpdate : ( ) => void ,
2829 selectedGroupId ?: number ,
@@ -31,8 +32,7 @@ interface GroupSelectorProps {
3132}
3233
3334const GroupSelector : FC < GroupSelectorProps > = ( props ) => {
34- const [ groups , setGroups ] = useState < Group [ ] > ( [ ] ) ;
35- const [ groupsLoading , setGroupsLoading ] = useState ( false ) ;
35+ const groups = props . groups || [ ] ;
3636 const [ isDialogOpen , setIsDialogOpen ] = useState ( false ) ;
3737 const [ formState , setFormState ] = useState < {
3838 name : string ,
@@ -44,22 +44,6 @@ const GroupSelector: FC<GroupSelectorProps> = (props) => {
4444 const [ isSubmitting , setIsSubmitting ] = useState ( false ) ;
4545 const [ isError , setIsError ] = useState ( false ) ;
4646
47- const loadGroups = async ( ) => {
48- setGroupsLoading ( true )
49- try {
50- const courseGroups = await ApiSingleton . courseGroupsApi . courseGroupsGetAllCourseGroupsWithNames ( props . courseId ) ;
51- setGroups ( courseGroups ) ;
52- } catch ( error ) {
53- console . error ( 'Failed to load groups:' , error ) ;
54- setIsError ( true ) ;
55- } finally {
56- setGroupsLoading ( false ) ;
57- }
58- }
59- useEffect ( ( ) => {
60- loadGroups ( ) ;
61- } , [ props . courseId ] ) ;
62-
6347 const handleOpenEditDialog = ( ) => {
6448 const selectedGroup = groups . find ( g => g . id === props . selectedGroupId ) ;
6549 setFormState ( {
@@ -89,7 +73,6 @@ const GroupSelector: FC<GroupSelectorProps> = (props) => {
8973 groupMates : formState . memberIds . map ( studentId => ( { studentId } ) ) ,
9074 }
9175 ) ;
92- await loadGroups ( ) ;
9376 props . onGroupsUpdate ( ) ;
9477 } else {
9578 if ( ! formState . name . trim ( ) || formState . memberIds . length === 0 ) {
@@ -101,7 +84,6 @@ const GroupSelector: FC<GroupSelectorProps> = (props) => {
10184 groupMatesIds : formState . memberIds ,
10285 courseId : props . courseId ,
10386 } ) ;
104- await loadGroups ( ) ;
10587 props . onGroupsUpdate ( ) ;
10688 props . onGroupIdChange ( groupId ) ;
10789 }
@@ -154,7 +136,6 @@ const GroupSelector: FC<GroupSelectorProps> = (props) => {
154136 onChange = { ( _ , newGroup ) => {
155137 props . onGroupIdChange ( newGroup ?. id )
156138 } }
157- loading = { groupsLoading }
158139 renderInput = { ( params ) => (
159140 < TextField
160141 { ...params }
0 commit comments