@@ -7,7 +7,7 @@ import { createRef, type Ref, ref } from 'lit/directives/ref.js';
77import {
88 allowAnonymousCommentsContext ,
99 baseUrlContext ,
10- captchaEnabledContext ,
10+ configMapDataContext ,
1111 currentUserContext ,
1212 groupContext ,
1313 kindContext ,
@@ -20,6 +20,7 @@ import { msg } from '@lit/localize';
2020import type { ToastManager } from './lit-toast' ;
2121import baseStyles from './styles/base' ;
2222import varStyles from './styles/var' ;
23+ import type { ConfigMapData } from './types' ;
2324
2425export class BaseForm extends LitElement {
2526 @consume ( { context : baseUrlContext } )
@@ -30,13 +31,13 @@ export class BaseForm extends LitElement {
3031 @state ( )
3132 currentUser : User | undefined ;
3233
33- @consume ( { context : allowAnonymousCommentsContext , subscribe : true } )
34+ @consume ( { context : configMapDataContext } )
3435 @state ( )
35- allowAnonymousComments = false ;
36+ configMapData : ConfigMapData | undefined ;
3637
37- @consume ( { context : captchaEnabledContext , subscribe : true } )
38+ @consume ( { context : allowAnonymousCommentsContext , subscribe : true } )
3839 @state ( )
39- captchaEnabled = false ;
40+ allowAnonymousComments = false ;
4041
4142 @consume ( { context : groupContext } )
4243 @state ( )
@@ -78,18 +79,22 @@ export class BaseForm extends LitElement {
7879 . join ( '-' )
7980 . replaceAll ( / - + / g, '-' ) } `;
8081
81- return `/login?redirect_uri=${ encodeURIComponent ( window . location . pathname + parentDomId ) } ` ;
82+ return `/login?redirect_uri=${ encodeURIComponent (
83+ window . location . pathname + parentDomId
84+ ) } `;
8285 }
8386
8487 get showCaptcha ( ) {
8588 return (
86- this . captchaEnabled && ! this . currentUser && this . allowAnonymousComments
89+ this . configMapData ?. security . captcha . anonymousCommentCaptcha &&
90+ ! this . currentUser &&
91+ this . allowAnonymousComments
8792 ) ;
8893 }
8994
9095 override updated ( changedProperties : Map < string , unknown > ) {
9196 if (
92- changedProperties . has ( 'captchaEnabled ' ) ||
97+ changedProperties . has ( 'configMapData ' ) ||
9398 changedProperties . has ( 'currentUser' ) ||
9499 changedProperties . has ( 'allowAnonymousComments' )
95100 ) {
@@ -138,9 +143,19 @@ export class BaseForm extends LitElement {
138143
139144 renderAccountInfo ( ) {
140145 return html `<div class= "form__account-info" >
141- ${ this . currentUser ?. spec . avatar ? html `<img src= ${ this . currentUser . spec . avatar } / > ` : '' }
142- <span> ${ this . currentUser ?. spec . displayName || this . currentUser ?. metadata . name } </ span>
143- <butto n @click = ${ this . handleLogout } type= "button" class = "form__button--logout" >
146+ ${
147+ this . currentUser ?. spec . avatar
148+ ? html `<img src= ${ this . currentUser . spec . avatar } / > `
149+ : ''
150+ }
151+ <span>
152+ ${ this . currentUser ?. spec . displayName || this . currentUser ?. metadata . name }
153+ </ span>
154+ <butto n
155+ @click = ${ this . handleLogout }
156+ type= "button"
157+ class = "form__button--logout"
158+ >
144159 ${ msg ( 'Logout' ) }
145160 </ butto n>
146161 </ div> ` ;
@@ -235,7 +250,7 @@ export class BaseForm extends LitElement {
235250 }
236251 <div class= "form__actions" >
237252 ${
238- this . showCaptcha
253+ this . showCaptcha && this . captcha
239254 ? html `
240255 <div class= "form__action--captcha" >
241256 <input
@@ -255,7 +270,11 @@ export class BaseForm extends LitElement {
255270 }
256271
257272 <emoji- butto n @emoji-select = ${ this . onEmojiSelect } > </ emoji- butto n>
258- <butto n .disabled = ${ this . submitting } type= "submit" class= "for m__butto n- - submit">
273+ <butto n
274+ .disabled = ${ this . submitting }
275+ type= "submit"
276+ class= "for m__butto n- - submit"
277+ >
259278 ${
260279 this . submitting
261280 ? html ` <icon- loading> </ icon- loading> `
@@ -369,11 +388,7 @@ export class BaseForm extends LitElement {
369388 outline : 0 ;
370389 padding : 0.4em 0.75em ;
371390 width : 100% ;
372- transition :
373- background 0.2s ,
374- border 0.2s ,
375- box-shadow 0.2s ,
376- color 0.2s ;
391+ transition : background 0.2s , border 0.2s , box-shadow 0.2s , color 0.2s ;
377392 }
378393
379394 input : focus ,
0 commit comments