Skip to content

Commit

Permalink
improve responsiveness of archive warning
Browse files Browse the repository at this point in the history
  • Loading branch information
ChlodAlejandro committed Nov 1, 2022
1 parent 5567f8d commit 8f4f29b
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
6 changes: 5 additions & 1 deletion src/ui/root/DeputyContributionSurveyRow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ export enum DeputyContributionSurveyRowState {
* (f) a list of revisions related to this page (as DeputyContributionSurveyRowRevision classes)
* (g) closing comments
*/
export default class DeputyContributionSurveyRow implements DeputyUIElement {
export default class DeputyContributionSurveyRow extends EventTarget implements DeputyUIElement {

static readonly menuOptionIcon: Record<ContributionSurveyRowStatus, false | string> = {
[ ContributionSurveyRowStatus.Unfinished ]: false,
Expand Down Expand Up @@ -336,6 +336,7 @@ export default class DeputyContributionSurveyRow implements DeputyUIElement {
originalWikitext: string,
section: DeputyContributionSurveySection
) {
super();
this.row = row;
this.originalElement = originalElement;
this.originalWikitext = originalWikitext;
Expand Down Expand Up @@ -431,6 +432,8 @@ export default class DeputyContributionSurveyRow implements DeputyUIElement {
this.commentsField.setNotices( [] );
}

// Emit "update" event
this.dispatchEvent( new CustomEvent( 'update' ) );
}

/**
Expand Down Expand Up @@ -819,6 +822,7 @@ export default class DeputyContributionSurveyRow implements DeputyUIElement {
*/
close(): void {
this.state = DeputyContributionSurveyRowState.Closed;

window.deputy.comms.removeEventListener(
'pageStatusRequest',
this.statusRequestResponder
Expand Down
16 changes: 15 additions & 1 deletion src/ui/root/DeputyContributionSurveySection.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -551,6 +551,9 @@ export default class DeputyContributionSurveySection implements DeputyUIElement
label: mw.msg( 'deputy.session.section.closeWarning' )
} );
closingWarning.toggle( false );
const updateClosingWarning = ( () => {
closingWarning.toggle( this.rows.some( ( row ) => !row.completed ) );
} );

const closingCommentsField = new OO.ui.FieldLayout( this.closingComments, {
align: 'top',
Expand All @@ -570,8 +573,19 @@ export default class DeputyContributionSurveySection implements DeputyUIElement
this.closingCheckbox.on( 'change', ( v: boolean ) => {
this.closed = v;
closingCommentsField.toggle( v );
closingWarning.toggle( v && this.rows.some( ( row ) => !row.completed ) );
this.toggleClosingComments( v );

if ( v ) {
updateClosingWarning();
this.rows.forEach( ( row ) => {
row.addEventListener( 'update', updateClosingWarning );
} );
} else {
closingWarning.toggle( false );
this.rows.forEach( ( row ) => {
row.removeEventListener( 'update', updateClosingWarning );
} );
}
} );
this.closingComments.on( 'change', ( v: string ) => {
this.comments = v;
Expand Down

0 comments on commit 8f4f29b

Please sign in to comment.