1- import React , { useState } from 'react' ;
1+ import React , { useState , useEffect } from 'react' ;
22import '../styles/Modal.css' ;
33import { CuteButton } from './CuteButton' ;
44import { Chapter , UserModule } from "../dtos/ModuleDto" ;
@@ -13,6 +13,16 @@ interface ModalProps {
1313
1414const ModuleProgressSettings : React . FC < ModalProps > = ( { onClose, module, allUserModules} ) => {
1515 const [ chapters , setChapters ] = useState < Chapter [ ] > ( module . chapter ) ;
16+ const [ progress , setProgress ] = useState < number > ( 0 ) ;
17+
18+ // Berechne den Fortschritt (in %) bei jedem Ändern der Checkboxen
19+ useEffect ( ( ) => {
20+ const allBoxes = chapters . flatMap ( ch => ch . checkbox ) ;
21+ const total = allBoxes . length ;
22+ const checkedCount = allBoxes . filter ( box => box . checked ) . length ;
23+ const percent = total > 0 ? Math . round ( ( checkedCount / total ) * 100 ) : 0 ;
24+ setProgress ( percent ) ;
25+ } , [ chapters ] ) ;
1626
1727 const toggleCheckbox = ( chapterId : number , checkboxId : number ) => {
1828 setChapters ( ( prevChapters ) =>
@@ -91,6 +101,13 @@ const ModuleProgressSettings: React.FC<ModalProps> = ({onClose, module, allUserM
91101 < p className = "text-2xl font-bold text-white text-left sm:ml-3" >
92102 Lernfortschritt
93103 </ p >
104+
105+ { /* Progress-Bar */ }
106+ < div className = "progress-container sm:ml-3 mb-6" >
107+ < div className = "progress-bar" style = { { width : `${ progress } %` } } />
108+ < span className = "text-white text-sm ml-2" > { progress } %</ span >
109+ </ div >
110+
94111 { chapters . map ( ( chapter ) => (
95112 < div key = { chapter . id } >
96113 < div className = "flex gap-4 items-center mt-2 sm:ml-3 mb-4" >
@@ -99,8 +116,7 @@ const ModuleProgressSettings: React.FC<ModalProps> = ({onClose, module, allUserM
99116 </ p >
100117 < button
101118 className = "delete-btn"
102- onClick = { ( ) => {
103- } }
119+ onClick = { ( ) => deleteCheckbox ( chapter . id , - 1 ) }
104120 >
105121 x
106122 </ button >
0 commit comments