@@ -2,7 +2,6 @@ import DeputyCasePage, { ContributionSurveyHeading } from '../wiki/DeputyCasePag
2
2
import DeputyCCISessionStartLink from '../ui/root/DeputyCCISessionStartLink' ;
3
3
import removeElement from '../util/removeElement' ;
4
4
import unwrapWidget from '../util/unwrapWidget' ;
5
- import sectionHeadingName from '../wiki/util/sectionHeadingName' ;
6
5
import {
7
6
DeputyMessageEvent ,
8
7
DeputySessionRequestMessage ,
@@ -13,9 +12,9 @@ import DeputyContributionSurveySection from '../ui/root/DeputyContributionSurvey
13
12
import { SessionInformation } from './DeputySession' ;
14
13
import { ArrayOrNot } from '../types' ;
15
14
import DeputyMessageWidget from '../ui/shared/DeputyMessageWidget' ;
16
- import sectionHeadingId from '../wiki/util/sectionHeadingId' ;
17
15
import last from '../util/last' ;
18
16
import findNextSiblingElement from '../util/findNextSiblingElement' ;
17
+ import normalizeWikiHeading from '../wiki/util/normalizeWikiHeading' ;
19
18
20
19
/**
21
20
* The DeputyRootSession. Instantiated only when:
@@ -43,9 +42,10 @@ export default class DeputyRootSession {
43
42
44
43
casePage . findContributionSurveyHeadings ( )
45
44
. forEach ( ( heading : ContributionSurveyHeading ) => {
46
- const link = DeputyCCISessionStartLink ( heading , casePage ) ;
45
+ const normalizedHeading = normalizeWikiHeading ( heading ) ;
46
+ const link = DeputyCCISessionStartLink ( normalizedHeading , casePage ) ;
47
47
startLink . push ( link as HTMLElement ) ;
48
- heading . appendChild ( link ) ;
48
+ normalizedHeading . root . appendChild ( link ) ;
49
49
} ) ;
50
50
51
51
window . deputy . comms . addEventListener ( 'sessionStarted' , ( ) => {
@@ -68,7 +68,7 @@ export default class DeputyRootSession {
68
68
await mw . loader . using (
69
69
[ 'oojs-ui-core' , 'oojs-ui.styles.icons-content' ] ,
70
70
( ) => {
71
- const firstHeading = casePage . findFirstContributionSurveyHeading ( ) ;
71
+ const firstHeading = casePage . findFirstContributionSurveyHeadingElement ( ) ;
72
72
if ( firstHeading ) {
73
73
const stopButton = new OO . ui . ButtonWidget ( {
74
74
label : mw . msg ( 'deputy.session.otherActive.button' ) ,
@@ -108,9 +108,9 @@ export default class DeputyRootSession {
108
108
window . deputy . session . init ( ) ;
109
109
} ) ;
110
110
111
- casePage . normalizeSectionHeading (
111
+ normalizeWikiHeading (
112
112
firstHeading
113
- ) . insertAdjacentElement (
113
+ ) . root . insertAdjacentElement (
114
114
'beforebegin' ,
115
115
unwrapWidget ( messageBox )
116
116
) ;
@@ -136,8 +136,8 @@ export default class DeputyRootSession {
136
136
const lastActiveSection =
137
137
DeputyRootSession . findFirstLastActiveSection ( casePage ) ;
138
138
const firstSection =
139
- casePage . normalizeSectionHeading (
140
- casePage . findFirstContributionSurveyHeading ( )
139
+ normalizeWikiHeading (
140
+ casePage . findFirstContributionSurveyHeadingElement ( )
141
141
) ;
142
142
143
143
// Insert element directly into widget (not as text, or else event
@@ -165,10 +165,10 @@ export default class DeputyRootSession {
165
165
'deputy.session.continue.help' :
166
166
'deputy.session.continue.help.fromStart' ,
167
167
lastActiveSection ?
168
- sectionHeadingName ( lastActiveSection ) :
168
+ normalizeWikiHeading ( lastActiveSection ) . title :
169
169
casePage . lastActiveSections [ 0 ]
170
170
. replace ( / _ / g, ' ' ) ,
171
- sectionHeadingName ( firstSection )
171
+ firstSection . title
172
172
) ,
173
173
actions : [ continueButton ] ,
174
174
closable : true
@@ -183,7 +183,7 @@ export default class DeputyRootSession {
183
183
DeputyRootSession . continueSession ( casePage ) ;
184
184
} else {
185
185
DeputyRootSession . continueSession ( casePage , [
186
- sectionHeadingId ( firstSection )
186
+ firstSection . id
187
187
] ) ;
188
188
}
189
189
window . deputy . comms . removeEventListener (
@@ -192,7 +192,7 @@ export default class DeputyRootSession {
192
192
) ;
193
193
} ) ;
194
194
195
- firstSection . insertAdjacentElement (
195
+ firstSection . root . insertAdjacentElement (
196
196
'beforebegin' ,
197
197
unwrapWidget ( messageBox )
198
198
) ;
@@ -221,7 +221,7 @@ export default class DeputyRootSession {
221
221
[ 'oojs-ui-core' , 'oojs-ui.styles.icons-content' ] ,
222
222
( ) => {
223
223
const firstHeading =
224
- casePage . findFirstContributionSurveyHeading ( ) ;
224
+ casePage . findFirstContributionSurveyHeadingElement ( ) ;
225
225
if ( firstHeading ) {
226
226
const messageBox = DeputyMessageWidget ( {
227
227
classes : [
@@ -232,9 +232,9 @@ export default class DeputyRootSession {
232
232
message : mw . msg ( 'deputy.session.tabActive.help' ) ,
233
233
closable : true
234
234
} ) ;
235
- casePage . normalizeSectionHeading (
235
+ normalizeWikiHeading (
236
236
firstHeading
237
- ) . insertAdjacentElement (
237
+ ) . root . insertAdjacentElement (
238
238
'beforebegin' ,
239
239
unwrapWidget ( messageBox )
240
240
) ;
@@ -264,7 +264,7 @@ export default class DeputyRootSession {
264
264
const csHeadings = casePage . findContributionSurveyHeadings ( ) ;
265
265
for ( const lastActiveSection of casePage . lastActiveSections ) {
266
266
for ( const heading of csHeadings ) {
267
- if ( sectionHeadingId ( heading ) === lastActiveSection ) {
267
+ if ( normalizeWikiHeading ( heading ) . id === lastActiveSection ) {
268
268
return heading ;
269
269
}
270
270
}
@@ -284,7 +284,7 @@ export default class DeputyRootSession {
284
284
_casePage ?: DeputyCasePage
285
285
) : Promise < void > {
286
286
const sectionIds = ( Array . isArray ( section ) ? section : [ section ] ) . map (
287
- ( _section ) => sectionHeadingId ( _section )
287
+ ( _section ) => normalizeWikiHeading ( _section ) . id
288
288
) ;
289
289
// Save session to storage
290
290
const casePage = _casePage ?? await DeputyCasePage . build ( ) ;
@@ -438,7 +438,7 @@ export default class DeputyRootSession {
438
438
439
439
const activeSectionPromises = [ ] ;
440
440
for ( const heading of this . casePage . findContributionSurveyHeadings ( ) ) {
441
- const headingId = sectionHeadingId ( heading ) ;
441
+ const headingId = normalizeWikiHeading ( heading ) . id ;
442
442
443
443
if ( this . session . caseSections . indexOf ( headingId ) !== - 1 ) {
444
444
activeSectionPromises . push (
@@ -509,8 +509,8 @@ export default class DeputyRootSession {
509
509
* @param heading
510
510
*/
511
511
addSectionOverlay ( casePage : DeputyCasePage , heading : ContributionSurveyHeading ) : void {
512
- const normalizedHeading = casePage . normalizeSectionHeading ( heading ) ;
513
- const section = casePage . getContributionSurveySection ( normalizedHeading ) ;
512
+ const normalizedHeading = normalizeWikiHeading ( heading ) . root ;
513
+ const section = casePage . getContributionSurveySection ( normalizedHeading as HTMLElement ) ;
514
514
const list = section . find (
515
515
( v ) => v instanceof HTMLElement && v . tagName === 'UL'
516
516
) as HTMLUListElement ;
@@ -582,7 +582,7 @@ export default class DeputyRootSession {
582
582
return false ;
583
583
}
584
584
585
- const sectionId = sectionHeadingId ( heading ) ;
585
+ const sectionId = normalizeWikiHeading ( heading ) . id ;
586
586
this . sections . push ( el ) ;
587
587
const lastActiveSession = this . session . caseSections . indexOf ( sectionId ) ;
588
588
if ( lastActiveSession === - 1 ) {
@@ -591,11 +591,7 @@ export default class DeputyRootSession {
591
591
}
592
592
await casePage . addActiveSection ( sectionId ) ;
593
593
594
- if ( heading . parentElement . classList . contains ( 'mw-heading' ) ) {
595
- heading . parentElement . insertAdjacentElement ( 'afterend' , el . render ( ) ) ;
596
- } else {
597
- heading . insertAdjacentElement ( 'afterend' , el . render ( ) ) ;
598
- }
594
+ normalizeWikiHeading ( heading ) . root . insertAdjacentElement ( 'afterend' , el . render ( ) ) ;
599
595
await el . loadData ( ) ;
600
596
mw . hook ( 'deputy.load.cci.session' ) . fire ( ) ;
601
597
@@ -628,9 +624,9 @@ export default class DeputyRootSession {
628
624
const casePage = e0 instanceof DeputyContributionSurveySection ?
629
625
e0 . casePage : e0 ;
630
626
const heading = e0 instanceof DeputyContributionSurveySection ?
631
- e0 . heading : e1 ;
627
+ e0 . heading : normalizeWikiHeading ( e1 ) ;
632
628
633
- const sectionId = sectionHeadingId ( heading ) ;
629
+ const sectionId = heading . id ;
634
630
const sectionListIndex = this . sections . indexOf ( el ) ;
635
631
if ( el != null && sectionListIndex !== - 1 ) {
636
632
this . sections . splice ( sectionListIndex , 1 ) ;
@@ -647,7 +643,7 @@ export default class DeputyRootSession {
647
643
} else {
648
644
await DeputyRootSession . setSession ( this . session ) ;
649
645
await casePage . removeActiveSection ( sectionId ) ;
650
- this . addSectionOverlay ( casePage , heading ) ;
646
+ this . addSectionOverlay ( casePage , heading . h ) ;
651
647
}
652
648
}
653
649
}
0 commit comments