11import { Component } from './component' ;
22import { getLoading , htmlToDom } from '../services/dom.ts' ;
33import { buildForInput } from '../wysiwyg-tinymce/config' ;
4+ import { Tabs } from "./tabs" ;
45
56export interface CommentReplyEvent extends Event {
67 detail : {
@@ -21,7 +22,8 @@ export class PageComments extends Component {
2122 private pageId : number ;
2223 private container : HTMLElement ;
2324 private commentCountBar : HTMLElement ;
24- private commentsTitle : HTMLElement ;
25+ private activeTab : HTMLElement ;
26+ private archivedTab : HTMLElement ;
2527 private addButtonContainer : HTMLElement ;
2628 private archiveContainer : HTMLElement ;
2729 private replyToRow : HTMLElement ;
@@ -37,6 +39,7 @@ export class PageComments extends Component {
3739 private wysiwygEditor : any = null ;
3840 private createdText : string ;
3941 private countText : string ;
42+ private archivedCountText : string ;
4043 private parentId : number | null = null ;
4144 private contentReference : string = '' ;
4245 private formReplyText : string = '' ;
@@ -48,7 +51,8 @@ export class PageComments extends Component {
4851 // Element references
4952 this . container = this . $refs . commentContainer ;
5053 this . commentCountBar = this . $refs . commentCountBar ;
51- this . commentsTitle = this . $refs . commentsTitle ;
54+ this . activeTab = this . $refs . activeTab ;
55+ this . archivedTab = this . $refs . archivedTab ;
5256 this . addButtonContainer = this . $refs . addButtonContainer ;
5357 this . archiveContainer = this . $refs . archiveContainer ;
5458 this . replyToRow = this . $refs . replyToRow ;
@@ -67,6 +71,7 @@ export class PageComments extends Component {
6771 // Translations
6872 this . createdText = this . $opts . createdText ;
6973 this . countText = this . $opts . countText ;
74+ this . archivedCountText = this . $opts . archivedCountText ;
7075
7176 this . formReplyText = this . formReplyLink ?. textContent || '' ;
7277
@@ -85,10 +90,12 @@ export class PageComments extends Component {
8590
8691 this . elem . addEventListener ( 'page-comment-archive' , ( event : ArchiveEvent ) => {
8792 this . archiveContainer . append ( event . detail . new_thread_dom ) ;
93+ setTimeout ( ( ) => this . updateCount ( ) , 1 ) ;
8894 } ) ;
8995
9096 this . elem . addEventListener ( 'page-comment-unarchive' , ( event : ArchiveEvent ) => {
91- this . container . append ( event . detail . new_thread_dom )
97+ this . container . append ( event . detail . new_thread_dom ) ;
98+ setTimeout ( ( ) => this . updateCount ( ) , 1 ) ;
9299 } ) ;
93100
94101 if ( this . form ) {
@@ -136,8 +143,10 @@ export class PageComments extends Component {
136143 }
137144
138145 protected updateCount ( ) : void {
139- const count = this . getCommentCount ( ) ;
140- this . commentsTitle . textContent = window . $trans . choice ( this . countText , count ) ;
146+ const activeCount = this . getActiveThreadCount ( ) ;
147+ this . activeTab . textContent = window . $trans . choice ( this . countText , activeCount ) ;
148+ const archivedCount = this . getArchivedThreadCount ( ) ;
149+ this . archivedTab . textContent = window . $trans . choice ( this . archivedCountText , archivedCount ) ;
141150 }
142151
143152 protected resetForm ( ) : void {
@@ -155,12 +164,18 @@ export class PageComments extends Component {
155164 this . addButtonContainer . toggleAttribute ( 'hidden' , true ) ;
156165 this . formContainer . scrollIntoView ( { behavior : 'smooth' , block : 'nearest' } ) ;
157166 this . loadEditor ( ) ;
167+
168+ // Ensure the active comments tab is displaying
169+ const tabs = window . $components . firstOnElement ( this . elem , 'tabs' ) ;
170+ if ( tabs instanceof Tabs ) {
171+ tabs . show ( 'comment-tab-panel-active' ) ;
172+ }
158173 }
159174
160175 protected hideForm ( ) : void {
161176 this . resetForm ( ) ;
162177 this . formContainer . toggleAttribute ( 'hidden' , true ) ;
163- if ( this . getCommentCount ( ) > 0 ) {
178+ if ( this . getActiveThreadCount ( ) > 0 ) {
164179 this . elem . append ( this . addButtonContainer ) ;
165180 } else {
166181 this . commentCountBar . append ( this . addButtonContainer ) ;
@@ -198,8 +213,12 @@ export class PageComments extends Component {
198213 }
199214 }
200215
201- protected getCommentCount ( ) : number {
202- return this . container . querySelectorAll ( '[component="page-comment"]' ) . length ;
216+ protected getActiveThreadCount ( ) : number {
217+ return this . container . querySelectorAll ( ':scope > .comment-branch:not([hidden])' ) . length ;
218+ }
219+
220+ protected getArchivedThreadCount ( ) : number {
221+ return this . archiveContainer . querySelectorAll ( ':scope > .comment-branch' ) . length ;
203222 }
204223
205224 protected setReply ( commentLocalId , commentElement ) : void {
0 commit comments