@@ -20,6 +20,7 @@ import type { ToastManager } from './lit-toast';
20
20
import baseStyles from './styles/base' ;
21
21
import type { ConfigMapData } from './types' ;
22
22
import './comment-editor' ;
23
+ import { when } from 'lit/directives/when.js' ;
23
24
import { ofetch } from 'ofetch' ;
24
25
import type { CommentEditor } from './comment-editor' ;
25
26
import { cleanHtml } from './utils/html' ;
@@ -150,13 +151,9 @@ export class BaseForm extends LitElement {
150
151
151
152
renderAccountInfo ( ) {
152
153
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>
160
157
<span class= "form-account-name text-base text-text-1 font-semibold" >
161
158
${ this . currentUser ?. spec . displayName || this . currentUser ?. metadata . name }
162
159
</ span>
@@ -193,9 +190,11 @@ export class BaseForm extends LitElement {
193
190
return html `
194
191
<for m class= "form w-full flex flex-col gap-4" @submit = "${ this . onSubmit } " >
195
192
<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" >
199
198
<input
200
199
name= "displayName"
201
200
value = ${ this . customAccount . displayName }
@@ -220,28 +219,29 @@ export class BaseForm extends LitElement {
220
219
class= "input"
221
220
/ >
222
221
<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
+ ) }
226
225
227
226
<div class= "form__footer" >
228
227
${ 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
232
232
@click = ${ this . handleOpenLoginPage }
233
233
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"
234
234
type = "butto n"
235
235
tabindex= "-1"
236
236
>
237
237
${ msg ( 'Login' ) }
238
- </ butto n> `
239
- : ''
240
- }
238
+ </ butto n>
239
+ `
240
+ ) }
241
241
<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 `
245
245
<div class= "form-captcha gap-2 flex items-center" >
246
246
<img
247
247
@click = ${ this . handleFetchCaptcha }
@@ -256,20 +256,20 @@ export class BaseForm extends LitElement {
256
256
class= "input "
257
257
/ >
258
258
</ div>
259
- `
260
- : ''
261
- }
259
+ `
260
+ ) }
262
261
263
262
<butto n
264
263
.disabled = ${ this . submitting }
265
264
type= "submit"
266
265
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"
267
266
>
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
+ ) }
273
273
${ msg ( 'Submit' ) }
274
274
</ butto n>
275
275
</ div>
0 commit comments