Skip to content

Commit

Permalink
fix: auto switch legacy comment if no providers
Browse files Browse the repository at this point in the history
Signed-off-by: Innei <i@innei.in>
  • Loading branch information
Innei committed Sep 18, 2024
1 parent 1ce56fe commit 3fcad20
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
17 changes: 15 additions & 2 deletions src/components/modules/comment/CommentBox/SignedOutContent.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,26 @@
'use client'

import clsx from 'clsx'
import { useEffect } from 'react'

import { useSessionReader } from '~/atoms/hooks/reader'
import { StyledButton } from '~/components/ui/button'
import { AuthProvidersRender } from '~/queries/hooks/authjs'
import { AuthProvidersRender, useAuthProviders } from '~/queries/hooks/authjs'

import { CommentBoxMode, setCommentMode } from './hooks'

export function CommentBoxSignedOutContent() {
const isReaderLogin = !!useSessionReader()
const providers = useAuthProviders()
const hasProviders = providers && Object.keys(providers).length > 0

useEffect(() => {
if (!providers) return
if (Object.keys(providers).length === 0) {
setCommentMode(CommentBoxMode.legacy)
}
}, [providers])

if (isReaderLogin) return null

return (
Expand All @@ -16,7 +29,7 @@ export function CommentBoxSignedOutContent() {
<AuthProvidersRender />

<StyledButton
className="mt-6"
className={clsx(hasProviders ? 'mt-6' : '')}
variant="secondary"
type="button"
onClick={() => {
Expand Down
2 changes: 1 addition & 1 deletion src/queries/hooks/authjs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ export const AuthProvidersRender: FC = () => {
})
}}
>
<div className="flex size-10 items-center justify-center rounded-full border dark:border-neutral-700">
<div className="flex size-10 items-center justify-center rounded-full border bg-base-100 dark:border-neutral-700">
{!authProcessingLockSet.has(provider) ? (
<Fragment>
{provider === 'github' ? (
Expand Down

0 comments on commit 3fcad20

Please sign in to comment.