@@ -17,6 +17,17 @@ export function RoleSheet({
1717 position,
1818 scorePoints
1919} : RoleSheetProps ) : JSX . Element {
20+ const [ pointsScored , setPointsScored ] = useState ( false ) ;
21+
22+ function onSubmitCheckboxes ( e ) {
23+ e . preventDefault ( ) ;
24+ // Only count checkboxes within this specific form for this role
25+ const checkboxes = e . target . querySelectorAll ( `input[type="checkbox"][id^="${ role } -"]:checked` ) ;
26+ const amount = checkboxes . length ;
27+ scorePoints ( role , amount ) ;
28+ setPointsScored ( true ) ;
29+ }
30+
2031 return < div className = "role" >
2132 < hr />
2233 < label className = "role-label" >
@@ -31,9 +42,20 @@ export function RoleSheet({
3142 </ label >
3243 < EarnPointsForRole role = { role } scorePoints = { scorePoints } />
3344 < div >
34- { role == "Typing" && position == "Typing" && roles [ role ] . todos . map ( s => < div key = { s } > { s } </ div > ) }
35- { role == "Talking" && position == "Talking" && roles [ role ] . todos . map ( s => < div key = { s } > { s } </ div > ) }
36- { role == "Observing" && position == "Observing" && roles [ role ] . todos . map ( s => < div key = { s } > { s } </ div > ) }
45+ < form onSubmit = { onSubmitCheckboxes } >
46+ { role == position && roles [ role ] . todos . map ( ( s , index ) => < div key = { s } >
47+ < input type = "checkbox" id = { `${ role } -${ index } ` } className = "earn-points-checkbox" style = { { float : "left" , display : "block" , marginTop : "6px" , width : "9%" , minHeight : "20px" } } />
48+ < div style = { { marginLeft : "32px" , margin : "4px" , padding : "4px" } } > { s } </ div >
49+ </ div > ) }
50+
51+ { ! pointsScored && (
52+ < button
53+ className = "rpgui-button add-points-button"
54+ aria-label = { "Earn Points" } >
55+ < p > Earn</ p >
56+ </ button >
57+ ) }
58+ </ form >
3759 </ div >
3860 { /*
3961 some_function({role}) returns string (or list of strings) to display here....
0 commit comments