File tree Expand file tree Collapse file tree 3 files changed +32
-2
lines changed
Expand file tree Collapse file tree 3 files changed +32
-2
lines changed Original file line number Diff line number Diff line change @@ -9,6 +9,13 @@ declare global {
99const app = document . body . appendChild ( new ScrambleTable ( ) ) ;
1010globalThis . app = app ;
1111
12+ app . addEventListener (
13+ "scramble-cleared" ,
14+ ( e : CustomEvent < { displayIndex : number } > ) => {
15+ console . log ( `Scramble cleared for display index: ${ e . detail . displayIndex } ` ) ;
16+ } ,
17+ ) ;
18+
1219app . displays [ 0 ] . setScramble ( {
1320 competitorName : "Amelia Multicube" ,
1421 competitorCompetitionID : 11 ,
Original file line number Diff line number Diff line change @@ -23,7 +23,11 @@ function nextUnassigned(): string {
2323}
2424
2525export class CompetitorScrambleDisplay extends HTMLElement {
26- constructor ( private sharedState : SharedState , private displayIndex : number ) {
26+ constructor (
27+ private sharedState : SharedState ,
28+ private displayIndex : number ,
29+ private onScrambleCleared : ( ) => void ,
30+ ) {
2731 super ( ) ;
2832 }
2933
@@ -99,6 +103,7 @@ export class CompetitorScrambleDisplay extends HTMLElement {
99103 this . querySelector < HTMLButtonElement > ( ".multi .next" ) . disabled = true ;
100104 this . querySelector < HTMLButtonElement > ( ".multi .all" ) . disabled = true ;
101105 this . #hideAdditionalActions( ) ;
106+ this . onScrambleCleared ( ) ;
102107 }
103108
104109 #info: AttemptScrambleInfo | undefined ;
Original file line number Diff line number Diff line change @@ -37,6 +37,12 @@ const DEFAULT_SET_SCRAMBLER_CALLBACK = async (
3737 return prompt ( `Please enter the name of scrambler ${ displayIndex + 1 } :` ) ;
3838} ;
3939
40+ /**
41+ *
42+ * Dispatches the following events:
43+ *
44+ * - `"scramble-cleared"`
45+ */
4046export class ScrambleTable
4147 extends HTMLElement
4248 implements ScrambleJSONCacheDelegate
@@ -63,6 +69,16 @@ export class ScrambleTable
6369 this . #initializeSettings( ) ;
6470 }
6571
72+ #onScrambleCleared( displayIndex : number ) {
73+ this . dispatchEvent (
74+ new CustomEvent ( "scramble-cleared" , {
75+ detail : {
76+ displayIndex,
77+ } ,
78+ } ) ,
79+ ) ;
80+ }
81+
6682 #initializeSettings( ) {
6783 this . querySelector ( "header .settings-button" ) . addEventListener (
6884 "click" ,
@@ -131,7 +147,9 @@ export class ScrambleTable
131147 const idx = this . displays . length ;
132148 this . displays . push (
133149 this . querySelector ( "scramble-table-contents" ) . appendChild (
134- new CompetitorScrambleDisplay ( this . sharedState , idx ) ,
150+ new CompetitorScrambleDisplay ( this . sharedState , idx , ( ) => {
151+ this . #onScrambleCleared( idx ) ;
152+ } ) ,
135153 ) ,
136154 ) ;
137155 }
You can’t perform that action at this time.
0 commit comments