@@ -18,6 +18,8 @@ import DeputyPageMenu, { DeputyPageMenuOption } from './DeputyPageMenu';
18
18
import deputyPageAnalysisOptions from './DeputyPageAnalysisOptions' ;
19
19
import deputyPageTools from './DeputyPageTools' ;
20
20
import error from '../../util/error' ;
21
+ import { DeputyPageToolbarState } from './DeputyPageToolbarState' ;
22
+ import log from '../../util/log' ;
21
23
22
24
export interface DeputyPageToolbarOptions extends Omit < DeputyPageStatusResponseMessage , 'type' > {
23
25
/**
@@ -59,6 +61,8 @@ export default class DeputyPageToolbar implements DeputyUIElement {
59
61
*/
60
62
revision ?: number ;
61
63
64
+ state = DeputyPageToolbarState . Open ;
65
+
62
66
readonly instanceId = generateId ( ) ;
63
67
readonly revisionStatusUpdateListener = this . onRevisionStatusUpdate . bind ( this ) ;
64
68
@@ -73,6 +77,7 @@ export default class DeputyPageToolbar implements DeputyUIElement {
73
77
this . revision = options . revision ?? mw . config . get ( 'wgRevisionId' ) ;
74
78
}
75
79
80
+ this . state = window . deputy . config . cci . toolbarInitialState . get ( ) ;
76
81
this . runAsyncJobs ( ) ;
77
82
}
78
83
@@ -389,17 +394,80 @@ export default class DeputyPageToolbar implements DeputyUIElement {
389
394
</ div > ;
390
395
}
391
396
397
+ /**
398
+ * Rends the page toolbar actions and main section, if the dropdown is open.
399
+ */
400
+ renderOpen ( ) : JSX . Element [ ] {
401
+ return [
402
+ < div class = "dp-pageToolbar-actions" >
403
+ < div
404
+ class = "dp-pageToolbar-close"
405
+ role = "button"
406
+ title = { mw . msg ( 'deputy.session.page.close' ) }
407
+ onClick = { ( ) => this . setState ( DeputyPageToolbarState . Hidden ) }
408
+ />
409
+ < div
410
+ class = "dp-pageToolbar-collapse"
411
+ role = "button"
412
+ title = { mw . msg ( 'deputy.session.page.collapse' ) }
413
+ onClick = { ( ) => this . setState ( DeputyPageToolbarState . Collapsed ) }
414
+ />
415
+ </ div > ,
416
+ < div class = "dp-pageToolbar-main" >
417
+ { this . renderStatusDropdown ( ) }
418
+ { this . renderCaseInfo ( ) }
419
+ { this . renderRevisionInfo ( ) }
420
+ { this . revisionNavigationSection =
421
+ this . renderRevisionNavigationButtons ( ) as HTMLElement }
422
+ { this . renderMenus ( ) }
423
+ </ div >
424
+ ] ;
425
+ }
426
+
427
+ /**
428
+ * Renders the collapsed toolbar button.
429
+ *
430
+ * @return The render button, to be included in the main toolbar.
431
+ */
432
+ renderCollapsed ( ) : JSX . Element {
433
+ return < div
434
+ class = "dp-pageToolbar-collapsed"
435
+ role = "button"
436
+ title = { mw . msg ( 'deputy.session.page.expand' ) }
437
+ onClick = { ( ) => this . setState ( DeputyPageToolbarState . Open ) }
438
+ /> ;
439
+ }
440
+
392
441
/**
393
442
* @inheritDoc
394
443
*/
395
444
render ( ) : HTMLElement {
445
+ console . log ( this . state ) ;
446
+ if ( this . state === DeputyPageToolbarState . Hidden ) {
447
+ const portletLink = mw . util . addPortletLink (
448
+ 'p-tb' ,
449
+ '#' ,
450
+ mw . msg ( 'deputy.session.page.open' ) ,
451
+ 'pt-dp-pt' ,
452
+ mw . msg ( 'deputy.session.page.open.tooltip' )
453
+ ) ;
454
+ portletLink . querySelector ( 'a' ) . addEventListener ( 'click' , ( event ) => {
455
+ event . preventDefault ( ) ;
456
+ this . setState ( DeputyPageToolbarState . Open ) ;
457
+ return false ;
458
+ } ) ;
459
+ // Placeholder element
460
+ return this . element = < div class = "deputy" /> as HTMLElement ;
461
+ } else {
462
+ const toolbar = document . getElementById ( 'pt-dp-pt' ) ;
463
+ if ( toolbar ) {
464
+ removeElement ( toolbar ) ;
465
+ }
466
+ }
467
+
396
468
return this . element = < div class = "deputy dp-pageToolbar" >
397
- { this . renderStatusDropdown ( ) }
398
- { this . renderCaseInfo ( ) }
399
- { this . renderRevisionInfo ( ) }
400
- { this . revisionNavigationSection =
401
- this . renderRevisionNavigationButtons ( ) as HTMLElement }
402
- { this . renderMenus ( ) }
469
+ { this . state === DeputyPageToolbarState . Open && this . renderOpen ( ) }
470
+ { this . state === DeputyPageToolbarState . Collapsed && this . renderCollapsed ( ) }
403
471
</ div > as HTMLElement ;
404
472
}
405
473
@@ -415,6 +483,20 @@ export default class DeputyPageToolbar implements DeputyUIElement {
415
483
this . nextRevisionButton ?. setDisabled ( disabled ) ;
416
484
}
417
485
486
+ /**
487
+ * Sets the display state of the toolbar. This will also set the
488
+ * initial state configuration option for the user.
489
+ *
490
+ * @param state
491
+ */
492
+ setState ( state : DeputyPageToolbarState ) {
493
+ this . state = state ;
494
+ window . deputy . config . cci . toolbarInitialState . set ( state ) ;
495
+ window . deputy . config . save ( ) ;
496
+
497
+ swapElements ( this . element , this . render ( ) ) ;
498
+ }
499
+
418
500
/**
419
501
* Performs cleanup and removes the element from the DOM.
420
502
*/
0 commit comments