@@ -2,7 +2,6 @@ import DeputyCasePage, { ContributionSurveyHeading } from '../wiki/DeputyCasePag
22import DeputyCCISessionStartLink from '../ui/root/DeputyCCISessionStartLink' ;
33import removeElement from '../util/removeElement' ;
44import unwrapWidget from '../util/unwrapWidget' ;
5- import sectionHeadingName from '../wiki/util/sectionHeadingName' ;
65import {
76 DeputyMessageEvent ,
87 DeputySessionRequestMessage ,
@@ -13,9 +12,9 @@ import DeputyContributionSurveySection from '../ui/root/DeputyContributionSurvey
1312import { SessionInformation } from './DeputySession' ;
1413import { ArrayOrNot } from '../types' ;
1514import DeputyMessageWidget from '../ui/shared/DeputyMessageWidget' ;
16- import sectionHeadingId from '../wiki/util/sectionHeadingId' ;
1715import last from '../util/last' ;
1816import findNextSiblingElement from '../util/findNextSiblingElement' ;
17+ import normalizeWikiHeading from '../wiki/util/normalizeWikiHeading' ;
1918
2019/**
2120 * The DeputyRootSession. Instantiated only when:
@@ -43,9 +42,10 @@ export default class DeputyRootSession {
4342
4443 casePage . findContributionSurveyHeadings ( )
4544 . forEach ( ( heading : ContributionSurveyHeading ) => {
46- const link = DeputyCCISessionStartLink ( heading , casePage ) ;
45+ const normalizedHeading = normalizeWikiHeading ( heading ) ;
46+ const link = DeputyCCISessionStartLink ( normalizedHeading , casePage ) ;
4747 startLink . push ( link as HTMLElement ) ;
48- heading . appendChild ( link ) ;
48+ normalizedHeading . root . appendChild ( link ) ;
4949 } ) ;
5050
5151 window . deputy . comms . addEventListener ( 'sessionStarted' , ( ) => {
@@ -68,7 +68,7 @@ export default class DeputyRootSession {
6868 await mw . loader . using (
6969 [ 'oojs-ui-core' , 'oojs-ui.styles.icons-content' ] ,
7070 ( ) => {
71- const firstHeading = casePage . findFirstContributionSurveyHeading ( ) ;
71+ const firstHeading = casePage . findFirstContributionSurveyHeadingElement ( ) ;
7272 if ( firstHeading ) {
7373 const stopButton = new OO . ui . ButtonWidget ( {
7474 label : mw . msg ( 'deputy.session.otherActive.button' ) ,
@@ -108,9 +108,9 @@ export default class DeputyRootSession {
108108 window . deputy . session . init ( ) ;
109109 } ) ;
110110
111- casePage . normalizeSectionHeading (
111+ normalizeWikiHeading (
112112 firstHeading
113- ) . insertAdjacentElement (
113+ ) . root . insertAdjacentElement (
114114 'beforebegin' ,
115115 unwrapWidget ( messageBox )
116116 ) ;
@@ -136,8 +136,8 @@ export default class DeputyRootSession {
136136 const lastActiveSection =
137137 DeputyRootSession . findFirstLastActiveSection ( casePage ) ;
138138 const firstSection =
139- casePage . normalizeSectionHeading (
140- casePage . findFirstContributionSurveyHeading ( )
139+ normalizeWikiHeading (
140+ casePage . findFirstContributionSurveyHeadingElement ( )
141141 ) ;
142142
143143 // Insert element directly into widget (not as text, or else event
@@ -165,10 +165,10 @@ export default class DeputyRootSession {
165165 'deputy.session.continue.help' :
166166 'deputy.session.continue.help.fromStart' ,
167167 lastActiveSection ?
168- sectionHeadingName ( lastActiveSection ) :
168+ normalizeWikiHeading ( lastActiveSection ) . title :
169169 casePage . lastActiveSections [ 0 ]
170170 . replace ( / _ / g, ' ' ) ,
171- sectionHeadingName ( firstSection )
171+ firstSection . title
172172 ) ,
173173 actions : [ continueButton ] ,
174174 closable : true
@@ -183,7 +183,7 @@ export default class DeputyRootSession {
183183 DeputyRootSession . continueSession ( casePage ) ;
184184 } else {
185185 DeputyRootSession . continueSession ( casePage , [
186- sectionHeadingId ( firstSection )
186+ firstSection . id
187187 ] ) ;
188188 }
189189 window . deputy . comms . removeEventListener (
@@ -192,7 +192,7 @@ export default class DeputyRootSession {
192192 ) ;
193193 } ) ;
194194
195- firstSection . insertAdjacentElement (
195+ firstSection . root . insertAdjacentElement (
196196 'beforebegin' ,
197197 unwrapWidget ( messageBox )
198198 ) ;
@@ -221,7 +221,7 @@ export default class DeputyRootSession {
221221 [ 'oojs-ui-core' , 'oojs-ui.styles.icons-content' ] ,
222222 ( ) => {
223223 const firstHeading =
224- casePage . findFirstContributionSurveyHeading ( ) ;
224+ casePage . findFirstContributionSurveyHeadingElement ( ) ;
225225 if ( firstHeading ) {
226226 const messageBox = DeputyMessageWidget ( {
227227 classes : [
@@ -232,9 +232,9 @@ export default class DeputyRootSession {
232232 message : mw . msg ( 'deputy.session.tabActive.help' ) ,
233233 closable : true
234234 } ) ;
235- casePage . normalizeSectionHeading (
235+ normalizeWikiHeading (
236236 firstHeading
237- ) . insertAdjacentElement (
237+ ) . root . insertAdjacentElement (
238238 'beforebegin' ,
239239 unwrapWidget ( messageBox )
240240 ) ;
@@ -264,7 +264,7 @@ export default class DeputyRootSession {
264264 const csHeadings = casePage . findContributionSurveyHeadings ( ) ;
265265 for ( const lastActiveSection of casePage . lastActiveSections ) {
266266 for ( const heading of csHeadings ) {
267- if ( sectionHeadingId ( heading ) === lastActiveSection ) {
267+ if ( normalizeWikiHeading ( heading ) . id === lastActiveSection ) {
268268 return heading ;
269269 }
270270 }
@@ -284,7 +284,7 @@ export default class DeputyRootSession {
284284 _casePage ?: DeputyCasePage
285285 ) : Promise < void > {
286286 const sectionIds = ( Array . isArray ( section ) ? section : [ section ] ) . map (
287- ( _section ) => sectionHeadingId ( _section )
287+ ( _section ) => normalizeWikiHeading ( _section ) . id
288288 ) ;
289289 // Save session to storage
290290 const casePage = _casePage ?? await DeputyCasePage . build ( ) ;
@@ -438,7 +438,7 @@ export default class DeputyRootSession {
438438
439439 const activeSectionPromises = [ ] ;
440440 for ( const heading of this . casePage . findContributionSurveyHeadings ( ) ) {
441- const headingId = sectionHeadingId ( heading ) ;
441+ const headingId = normalizeWikiHeading ( heading ) . id ;
442442
443443 if ( this . session . caseSections . indexOf ( headingId ) !== - 1 ) {
444444 activeSectionPromises . push (
@@ -509,8 +509,8 @@ export default class DeputyRootSession {
509509 * @param heading
510510 */
511511 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 ) ;
514514 const list = section . find (
515515 ( v ) => v instanceof HTMLElement && v . tagName === 'UL'
516516 ) as HTMLUListElement ;
@@ -582,7 +582,7 @@ export default class DeputyRootSession {
582582 return false ;
583583 }
584584
585- const sectionId = sectionHeadingId ( heading ) ;
585+ const sectionId = normalizeWikiHeading ( heading ) . id ;
586586 this . sections . push ( el ) ;
587587 const lastActiveSession = this . session . caseSections . indexOf ( sectionId ) ;
588588 if ( lastActiveSession === - 1 ) {
@@ -591,11 +591,7 @@ export default class DeputyRootSession {
591591 }
592592 await casePage . addActiveSection ( sectionId ) ;
593593
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 ( ) ) ;
599595 await el . loadData ( ) ;
600596 mw . hook ( 'deputy.load.cci.session' ) . fire ( ) ;
601597
@@ -628,9 +624,9 @@ export default class DeputyRootSession {
628624 const casePage = e0 instanceof DeputyContributionSurveySection ?
629625 e0 . casePage : e0 ;
630626 const heading = e0 instanceof DeputyContributionSurveySection ?
631- e0 . heading : e1 ;
627+ e0 . heading : normalizeWikiHeading ( e1 ) ;
632628
633- const sectionId = sectionHeadingId ( heading ) ;
629+ const sectionId = heading . id ;
634630 const sectionListIndex = this . sections . indexOf ( el ) ;
635631 if ( el != null && sectionListIndex !== - 1 ) {
636632 this . sections . splice ( sectionListIndex , 1 ) ;
@@ -647,7 +643,7 @@ export default class DeputyRootSession {
647643 } else {
648644 await DeputyRootSession . setSession ( this . session ) ;
649645 await casePage . removeActiveSection ( sectionId ) ;
650- this . addSectionOverlay ( casePage , heading ) ;
646+ this . addSectionOverlay ( casePage , heading . h ) ;
651647 }
652648 }
653649 }
0 commit comments