@@ -20,6 +20,7 @@ import type { ToastManager } from './lit-toast';
2020import baseStyles from './styles/base' ;
2121import type { ConfigMapData } from './types' ;
2222import './comment-editor' ;
23+ import { when } from 'lit/directives/when.js' ;
2324import { ofetch } from 'ofetch' ;
2425import type { CommentEditor } from './comment-editor' ;
2526import { cleanHtml } from './utils/html' ;
@@ -150,13 +151,9 @@ export class BaseForm extends LitElement {
150151
151152 renderAccountInfo ( ) {
152153 return html `<div class= "form-account flex items-center gap-2" >
153- <div class= "form-account-avatar avatar" >
154- ${
155- this . currentUser ?. spec . avatar
156- ? html `<img src= ${ this . currentUser . spec . avatar } class= "size-full object-cover" / > `
157- : ''
158- }
159- </ div>
154+ <div class= "form-account-avatar avatar" >
155+ ${ when ( this . currentUser ?. spec . avatar , ( ) => html `<img src= ${ this . currentUser ?. spec . avatar || '' } class= "size-full object-cover" / > ` ) }
156+ </ div>
160157 <span class= "form-account-name text-base text-text-1 font-semibold" >
161158 ${ this . currentUser ?. spec . displayName || this . currentUser ?. metadata . name }
162159 </ span>
@@ -193,9 +190,11 @@ export class BaseForm extends LitElement {
193190 return html `
194191 <for m class= "form w-full flex flex-col gap-4" @submit = "${ this . onSubmit } " >
195192 <comment- edito r ${ ref ( this . editorRef ) } .placeholder = ${ this . configMapData ?. editor ?. placeholder } > </ comment- edito r>
196- ${
197- ! this . currentUser && this . allowAnonymousComments
198- ? html `<div class= "form-inputs grid grid-cols-1 md:grid-cols-4 gap-2 items-center" >
193+
194+ ${ when (
195+ ! this . currentUser && this . allowAnonymousComments ,
196+ ( ) => html `
197+ <div class= "form-inputs grid grid-cols-1 md:grid-cols-4 gap-2 items-center" >
199198 <input
200199 name= "displayName"
201200 value = ${ this . customAccount . displayName }
@@ -220,28 +219,29 @@ export class BaseForm extends LitElement {
220219 class= "input"
221220 / >
222221 <a tabindex= "-1" href = ${ this . loginUrl } rel= "nofollow" class= "for m- login- link text- text-3 hover: text- text-1 text- xs transition- all select- none"> ${ msg ( '(Or login)' ) } </ a>
223- </ div> `
224- : ''
225- }
222+ </ div>
223+ `
224+ ) }
226225
227226 <div class= "form__footer" >
228227 ${ this . currentUser ? this . renderAccountInfo ( ) : '' }
229- ${
230- ! this . currentUser && ! this . allowAnonymousComments
231- ? html `<butto n
228+ ${ when (
229+ ! this . currentUser && ! this . allowAnonymousComments ,
230+ ( ) => html `
231+ <butto n
232232 @click = ${ this . handleOpenLoginPage }
233233 class= "form-login text-xs text-text-3 hover:text-text-1 px-3 transition-all py-2 rounded-base border border-muted-3 opacity-100 hover:border-muted-4 hover:opacity-70 border-solid"
234234 type = "butto n"
235235 tabindex= "-1"
236236 >
237237 ${ msg ( 'Login' ) }
238- </ butto n> `
239- : ''
240- }
238+ </ butto n>
239+ `
240+ ) }
241241 <div class= "form-actions justify-end flex gap-2 flex-wrap items-center" >
242- ${
243- this . showCaptcha && this . captcha
244- ? html `
242+ ${ when (
243+ this . showCaptcha && this . captcha ,
244+ ( ) => html `
245245 <div class= "form-captcha gap-2 flex items-center" >
246246 <img
247247 @click = ${ this . handleFetchCaptcha }
@@ -256,20 +256,20 @@ export class BaseForm extends LitElement {
256256 class= "input "
257257 / >
258258 </ div>
259- `
260- : ''
261- }
259+ `
260+ ) }
262261
263262 <butto n
264263 .disabled = ${ this . submitting }
265264 type= "submit"
266265 class= "for m- submit outline-none focus: shadow- input h-12 text- sm inline-flex bor der bor der- primary-1 bor der- solid items- center justify- center gap-2 bg- primary-1 text- white px-3 rounded- base hover: opacity-80 transition- all"
267266 >
268- ${
269- this . submitting
270- ? html `<icon- loading> </ icon- loading> `
271- : html `<i class= "i-mingcute-send-line size-5" aria-hidden = "true"> </ i> `
272- }
267+ ${ when (
268+ this . submitting ,
269+ ( ) => html `<icon- loading> </ icon- loading> ` ,
270+ ( ) =>
271+ html `<i class= "i-mingcute-send-line size-5" aria-hidden = "true"> </ i> `
272+ ) }
273273 ${ msg ( 'Submit' ) }
274274 </ butto n>
275275 </ div>
0 commit comments