@@ -178,42 +178,50 @@ def admin_checkbox_change(e, key):
178178
179179@ui .page ("/admin" )
180180def admin_page ():
181- with ui .column ().classes ("w-full max-w-xl mx-auto p-4" ):
181+ with ui .column ().classes ("w-full max-w-xl mx-auto p-4" ) as container :
182182 ui .label ("Admin Panel (Seed Phrases)" ).classes ("text-h4 text-center" )
183-
184- # Create checkboxes for each seed phrase if not already created.
185- for r in range (5 ):
186- for c in range (5 ):
187- key = (r , c )
188- phrase = board [r ][c ]
189- if key not in admin_checkboxes :
190- def on_admin_checkbox_change (e , key = key ):
191- if e .value :
192- clicked_tiles .add (key )
193- else :
194- clicked_tiles .discard (key )
195- sync_board_state ()
196- update_admin_visibility ()
197- left_chk = ui .checkbox (phrase , value = (key in clicked_tiles ), on_change = on_admin_checkbox_change )
198- right_chk = ui .checkbox (phrase , value = (key in clicked_tiles ), on_change = on_admin_checkbox_change )
199- admin_checkboxes [key ] = {"left" : left_chk , "right" : right_chk }
200-
201-
202- left_chk .on ("change" , on_admin_checkbox_change )
203- right_chk .on ("change" , on_admin_checkbox_change )
204-
205- # with ui.row():
206- # with ui.column().classes("w-1/2"):
207- # ui.label("Uncalled").classes("text-h5 text-center")
208- # for key in sorted(admin_checkboxes.keys(), key=lambda k: (k[0], k[1])):
209- # # Simply calling the widget makes sure it gets rendered in this column.
210- # admin_checkboxes[key]["left"]
211- # with ui.column().classes("w-1/2"):
212- # ui.label("Called").classes("text-h5 text-center")
213- # for key in sorted(admin_checkboxes.keys(), key=lambda k: (k[0], k[1])):
214- # admin_checkboxes[key]["right"]
215-
216-
183+ panel = ui .column () # container for the checkboxes row
184+
185+ def build_admin_panel ():
186+ panel .clear () # clear previous panel content
187+ with panel : # add new content as children of panel
188+ with ui .row ():
189+ with ui .column ().classes ("w-1/2" ):
190+ ui .label ("Uncalled" ).classes ("text-h5 text-center" )
191+ # Create left (uncalled) checkboxes inside this column.
192+ for r in range (5 ):
193+ for c in range (5 ):
194+ key = (r , c )
195+ phrase = board [r ][c ]
196+ def on_admin_checkbox_change (e , key = key ):
197+ if e .value :
198+ clicked_tiles .add (key )
199+ else :
200+ clicked_tiles .discard (key )
201+ sync_board_state ()
202+ update_admin_visibility ()
203+ build_admin_panel () # re-render admin panel after change
204+ left_chk = ui .checkbox (phrase , value = (key in clicked_tiles ), on_change = on_admin_checkbox_change )
205+ admin_checkboxes .setdefault (key , {})["left" ] = left_chk
206+ with ui .column ().classes ("w-1/2" ):
207+ ui .label ("Called" ).classes ("text-h5 text-center" )
208+ # Create right (called) checkboxes inside this column.
209+ for r in range (5 ):
210+ for c in range (5 ):
211+ key = (r , c )
212+ phrase = board [r ][c ]
213+ def on_admin_checkbox_change (e , key = key ):
214+ if e .value :
215+ clicked_tiles .add (key )
216+ else :
217+ clicked_tiles .discard (key )
218+ sync_board_state ()
219+ update_admin_visibility ()
220+ build_admin_panel () # re-render admin panel after change
221+ right_chk = ui .checkbox (phrase , value = (key in clicked_tiles ), on_change = on_admin_checkbox_change )
222+ admin_checkboxes .setdefault (key , {})["right" ] = right_chk
223+
224+ build_admin_panel ()
217225 ui .timer (1 , update_admin_visibility )
218226
219227ui .run (port = 8080 , title = "Commit Bingo" , dark = False )
0 commit comments