@@ -376,67 +376,33 @@ function CommentInput({
376376} ) {
377377 const { t } = useTranslation ( ) ;
378378 const [ content , setContent ] = useState ( "" ) ;
379- const [ guestName , setGuestName ] = useState ( "" ) ;
380- const [ guestEmail , setGuestEmail ] = useState ( "" ) ;
381- const [ guestWebsite , setGuestWebsite ] = useState ( "" ) ;
382379 const [ error , setError ] = useState ( "" ) ;
383380 const { showAlert, AlertUI } = useAlert ( ) ;
384381 const profile = useContext ( ProfileContext ) ;
385382 const [ , setLocation ] = useLocation ( ) ;
386- const config = useContext ( ClientConfigContext ) ;
387- // guest comments enabled by default; admin can disable via client config `comment.guest.enabled=false`
388- const rawGuest = config . get ( 'comment.guest.enabled' ) ;
389- const guestEnabled = rawGuest !== false && rawGuest !== 'false' ;
390383 function errorHumanize ( error : string ) {
391384 if ( error === "Unauthorized" ) return t ( "login.required" ) ;
392385 else if ( error === "Content is required" ) return t ( "comment.empty" ) ;
393- else if ( error === "Guest name is required" ) return t ( "comment.guest_name_required" ) ;
394386 return error ;
395387 }
396388 function submit ( ) {
397- if ( profile ) {
398- client . comment
399- . create ( parseInt ( id ) , { content } )
400- . then ( ( { error } ) => {
401- if ( error ) {
402- setError ( errorHumanize ( error . value as string ) ) ;
403- } else {
404- setContent ( "" ) ;
405- setError ( "" ) ;
406- showAlert ( t ( "comment.success" ) , ( ) => {
407- onRefresh ( ) ;
408- } ) ;
409- }
410- } ) ;
411- } else if ( guestEnabled ) {
412- if ( ! guestName . trim ( ) ) {
413- setError ( t ( "comment.guest_name_required" ) ) ;
414- return ;
415- }
416- client . comment
417- . create ( parseInt ( id ) , {
418- content,
419- guestName : guestName . trim ( ) ,
420- guestEmail : guestEmail . trim ( ) || undefined ,
421- guestWebsite : guestWebsite . trim ( ) || undefined ,
422- } )
423- . then ( ( { error } ) => {
424- if ( error ) {
425- setError ( errorHumanize ( error . value as string ) ) ;
426- } else {
427- setContent ( "" ) ;
428- setGuestName ( "" ) ;
429- setGuestEmail ( "" ) ;
430- setGuestWebsite ( "" ) ;
431- setError ( "" ) ;
432- showAlert ( t ( "comment.success" ) , ( ) => {
433- onRefresh ( ) ;
434- } ) ;
435- }
436- } ) ;
437- } else {
438- setLocation ( '/login' ) ;
389+ if ( ! profile ) {
390+ setLocation ( '/login' )
391+ return ;
439392 }
393+ client . comment
394+ . create ( parseInt ( id ) , { content } )
395+ . then ( ( { error } ) => {
396+ if ( error ) {
397+ setError ( errorHumanize ( error . value as string ) ) ;
398+ } else {
399+ setContent ( "" ) ;
400+ setError ( "" ) ;
401+ showAlert ( t ( "comment.success" ) , ( ) => {
402+ onRefresh ( ) ;
403+ } ) ;
404+ }
405+ } ) ;
440406 }
441407 return (
442408 < div className = "w-full rounded-2xl bg-w t-primary p-6 items-end flex flex-col" >
@@ -457,42 +423,7 @@ function CommentInput({
457423 >
458424 { t ( "comment.submit" ) }
459425 </ button >
460- </ > ) : guestEnabled ? ( < >
461- < input
462- type = "text"
463- placeholder = { t ( "comment.guest_name_placeholder" ) }
464- className = "bg-w w-full rounded-lg px-3 py-2 mb-2 border border-gray-200 dark:border-gray-700"
465- value = { guestName }
466- onChange = { ( e ) => setGuestName ( e . target . value ) }
467- />
468- < input
469- type = "email"
470- placeholder = { t ( "comment.guest_email_placeholder" ) }
471- className = "bg-w w-full rounded-lg px-3 py-2 mb-2 border border-gray-200 dark:border-gray-700"
472- value = { guestEmail }
473- onChange = { ( e ) => setGuestEmail ( e . target . value ) }
474- />
475- < input
476- type = "url"
477- placeholder = { t ( "comment.guest_website_placeholder" ) }
478- className = "bg-w w-full rounded-lg px-3 py-2 mb-2 border border-gray-200 dark:border-gray-700"
479- value = { guestWebsite }
480- onChange = { ( e ) => setGuestWebsite ( e . target . value ) }
481- />
482- < textarea
483- id = "comment"
484- placeholder = { t ( "comment.placeholder.title" ) }
485- className = "bg-w w-full h-24 rounded-lg"
486- value = { content }
487- onChange = { ( e ) => setContent ( e . target . value ) }
488- />
489- < button
490- className = "mt-4 bg-theme text-white px-4 py-2 rounded-full"
491- onClick = { submit }
492- >
493- { t ( "comment.submit" ) }
494- </ button >
495- </ > ) : (
426+ </ > ) : (
496427 < div className = "flex flex-row w-full items-center justify-center space-x-2 py-12" >
497428 < button
498429 className = "mt-2 bg-theme text-white px-4 py-2 rounded-full"
@@ -513,15 +444,12 @@ type Comment = {
513444 content : string ;
514445 createdAt : Date ;
515446 updatedAt : Date ;
516- user ? : {
447+ user : {
517448 id : number ;
518449 username : string ;
519450 avatar : string | null ;
520451 permission : number | null ;
521- } | null ;
522- guestName ?: string ;
523- guestEmail ?: string ;
524- guestWebsite ?: string ;
452+ } ;
525453} ;
526454
527455function Comments ( { id } : { id : string } ) {
@@ -593,8 +521,6 @@ function CommentItem({
593521 const { showAlert, AlertUI } = useAlert ( ) ;
594522 const { t } = useTranslation ( ) ;
595523 const profile = useContext ( ProfileContext ) ;
596- const commenterName = comment . user ?. username || comment . guestName || t ( "anonymous" ) ;
597- const commenterAvatar = comment . user ?. avatar || "" ;
598524 function deleteComment ( ) {
599525 showConfirm (
600526 t ( "delete.comment.title" ) ,
@@ -616,24 +542,14 @@ function CommentItem({
616542 return (
617543 < div className = "flex flex-row items-start rounded-xl mt-2" >
618544 < img
619- src = { commenterAvatar }
545+ src = { comment . user . avatar || "" }
620546 className = "w-8 h-8 rounded-full mt-4"
621547 />
622548 < div className = "flex flex-col flex-1 w-0 ml-2 bg-w rounded-xl p-4" >
623549 < div className = "flex flex-row" >
624550 < span className = "t-primary text-base font-bold" >
625- { commenterName }
551+ { comment . user . username }
626552 </ span >
627- { comment . guestWebsite && (
628- < a
629- href = { comment . guestWebsite }
630- target = "_blank"
631- rel = "noopener noreferrer"
632- className = "ml-2 text-gray-400 hover:text-theme transition-colors"
633- >
634- < i className = "ri-external-link-line" > </ i >
635- </ a >
636- ) }
637553 < div className = "flex-1 w-0" />
638554 < span
639555 title = { new Date ( comment . createdAt ) . toLocaleString ( ) }
@@ -644,7 +560,7 @@ function CommentItem({
644560 </ div >
645561 < p className = "t-primary break-words" > { comment . content } </ p >
646562 < div className = "flex flex-row justify-end" >
647- { ( profile ?. permission || ( comment . user && profile ?. id == comment . user . id ) ) && (
563+ { ( profile ?. permission || profile ?. id == comment . user . id ) && (
648564 < Popup
649565 arrow = { false }
650566 trigger = {
0 commit comments