@@ -20,10 +20,10 @@ 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' ;
26- import './base-tooltip' ;
2727
2828export class BaseForm extends LitElement {
2929 @consume ( { context : baseUrlContext } )
@@ -154,14 +154,11 @@ export class BaseForm extends LitElement {
154154
155155 renderAccountInfo ( ) {
156156 return html `<div class= "form-account flex items-center gap-2" >
157- ${
158- this . currentUser ?. spec . avatar
159- ? html `
160- <div class= "form-account-avatar avatar" >
161- <img src= ${ this . currentUser . spec . avatar } class= "size-full object-cover" / >
162- </ div> `
163- : ''
164- }
157+ ${ when (
158+ this . currentUser ?. spec . avatar ,
159+ ( ) => html `<div class= "form-account-avatar avatar" > <img src= ${ this . currentUser ?. spec . avatar || '' } class= "size-full object-cover" / > </ div>
160+ `
161+ ) }
165162 <span class= "form-account-name text-base text-text-1 font-semibold" >
166163 ${ this . currentUser ?. spec . displayName || this . currentUser ?. metadata . name }
167164 </ span>
@@ -198,9 +195,11 @@ export class BaseForm extends LitElement {
198195 return html `
199196 <for m class= "form w-full flex flex-col gap-4" @submit = "${ this . onSubmit } " >
200197 <comment- edito r ${ ref ( this . editorRef ) } .placeholder = ${ this . configMapData ?. editor ?. placeholder } > </ comment- edito r>
201- ${
202- ! this . currentUser && this . allowAnonymousComments
203- ? html `<div class= "form-inputs grid grid-cols-1 md:grid-cols-4 gap-2 items-center" >
198+
199+ ${ when (
200+ ! this . currentUser && this . allowAnonymousComments ,
201+ ( ) => html `
202+ <div class= "form-inputs grid grid-cols-1 md:grid-cols-4 gap-2 items-center" >
204203 <input
205204 name= "displayName"
206205 value = ${ this . customAccount . displayName }
@@ -225,45 +224,41 @@ export class BaseForm extends LitElement {
225224 class= "input"
226225 / >
227226 <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>
228- </ div> `
229- : ''
230- }
227+ </ div>
228+ `
229+ ) }
231230
232231 <div class= "form__footer" >
233232 ${ this . currentUser ? this . renderAccountInfo ( ) : '' }
234- ${
235- ! this . currentUser && ! this . allowAnonymousComments
236- ? html `<butto n
233+ ${ when (
234+ ! this . currentUser && ! this . allowAnonymousComments ,
235+ ( ) => html `
236+ <butto n
237237 @click = ${ this . handleOpenLoginPage }
238238 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"
239239 type = "butto n"
240240 tabindex= "-1"
241241 >
242242 ${ msg ( 'Login' ) }
243- </ butto n> `
244- : ''
245- }
243+ </ butto n>
244+ `
245+ ) }
246246 <div class= "form-actions justify-end flex gap-3 flex-wrap items-center" >
247-
248- ${
247+ ${ when (
249248 ! this . hidePrivateCheckbox &&
250- this . configMapData ?. basic . enablePrivateComment
251- ? html `
252- <div class= "flex items-center gap-2" >
253- <input id= "hidden" name = "hidden" type= "checkbox" / >
254- <label for = "hidden" class = "text- xs select- none text- text-3 hover: text- text-1 transition- all"> ${ msg ( 'Private' ) } </ label>
255- <base- to oltip content= ${ this . currentUser ? msg ( 'Currently logged in. After selecting the private option, comments will only be visible to yourself and the site administrator.' ) : msg ( 'You are currently anonymous. After selecting the private option, the comment will only be visible to the site administrator.' ) } >
256- <i class= "i-mingcute:information-line size-3.5 text-text-3 block" > </ i>
257- </ base- to oltip>
258- </ div>
259- `
260- : ''
261- }
262-
263-
264- ${
265- this . showCaptcha && this . captcha
266- ? html `
249+ this . configMapData ?. basic . enablePrivateComment ,
250+ ( ) => html `<div class= "flex items-center gap-2" >
251+ <input id= "hidden" name = "hidden" type= "checkbox" / >
252+ <label for = "hidden" class = "text- xs select- none text- text-3 hover: text- text-1 transition- all"> ${ msg ( 'Private' ) } </ label>
253+ <base- to oltip content= ${ this . currentUser ? msg ( 'Currently logged in. After selecting the private option, comments will only be visible to yourself and the site administrator.' ) : msg ( 'You are currently anonymous. After selecting the private option, the comment will only be visible to the site administrator.' ) } >
254+ <i class= "i-mingcute:information-line size-3.5 text-text-3 block" > </ i>
255+ </ base- to oltip>
256+ </ div> `
257+ ) }
258+
259+ ${ when (
260+ this . showCaptcha && this . captcha ,
261+ ( ) => html `
267262 <div class= "form-captcha gap-2 flex items-center" >
268263 <img
269264 @click = ${ this . handleFetchCaptcha }
@@ -278,20 +273,20 @@ export class BaseForm extends LitElement {
278273 class= "input "
279274 / >
280275 </ div>
281- `
282- : ''
283- }
276+ `
277+ ) }
284278
285279 <butto n
286280 .disabled = ${ this . submitting }
287281 type= "submit"
288282 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"
289283 >
290- ${
291- this . submitting
292- ? html `<icon- loading> </ icon- loading> `
293- : html `<i class= "i-mingcute-send-line size-5" aria-hidden = "true"> </ i> `
294- }
284+ ${ when (
285+ this . submitting ,
286+ ( ) => html `<icon- loading> </ icon- loading> ` ,
287+ ( ) =>
288+ html `<i class= "i-mingcute-send-line size-5" aria-hidden = "true"> </ i> `
289+ ) }
295290 ${ msg ( 'Submit' ) }
296291 </ butto n>
297292 </ div>
0 commit comments