Browse Source

style: 🎨

imwald
codytseng 9 months ago
parent
commit
6cc3dd32a5
  1. 30
      src/components/Favicon/index.tsx
  2. 7
      src/components/Nip05/index.tsx

30
src/components/Favicon/index.tsx

@ -1,15 +1,29 @@
import { cn } from '@/lib/utils'
import { useState } from 'react' import { useState } from 'react'
export function Favicon({ domain, className }: { domain: string; className?: string }) { export function Favicon({
domain,
className,
fallback = null
}: {
domain: string
className?: string
fallback?: React.ReactNode
}) {
const [loading, setLoading] = useState(true)
const [error, setError] = useState(false) const [error, setError] = useState(false)
if (error) return null if (error) return fallback
return ( return (
<img <div className={cn('relative', className)}>
src={`https://${domain}/favicon.ico`} {loading && <div className={cn('absolute inset-0', className)}>{fallback}</div>}
alt={domain} <img
className={className} src={`https://${domain}/favicon.ico`}
onError={() => setError(true)} alt={domain}
/> className={cn('absolute inset-0', className)}
onError={() => setError(true)}
onLoad={() => setLoading(false)}
/>
</div>
) )
} }

7
src/components/Nip05/index.tsx

@ -32,10 +32,13 @@ export default function Nip05({ pubkey, append }: { pubkey: string; append?: str
to={toNoteList({ domain: nip05Domain })} to={toNoteList({ domain: nip05Domain })}
className={`flex items-center gap-1 hover:underline truncate [&_svg]:size-3.5 [&_svg]:shrink-0 ${nip05IsVerified ? 'text-primary' : 'text-muted-foreground'}`} className={`flex items-center gap-1 hover:underline truncate [&_svg]:size-3.5 [&_svg]:shrink-0 ${nip05IsVerified ? 'text-primary' : 'text-muted-foreground'}`}
> >
{nip05IsVerified ? <BadgeCheck /> : <BadgeAlert />} {nip05IsVerified ? (
<Favicon domain={nip05Domain} className="w-3.5 h-3.5" fallback={<BadgeCheck />} />
) : (
<BadgeAlert />
)}
<span className="text-sm truncate">{nip05Domain}</span> <span className="text-sm truncate">{nip05Domain}</span>
</SecondaryPageLink> </SecondaryPageLink>
<Favicon domain={nip05Domain} className="w-3.5 h-3.5" />
{append && <span className="text-sm text-muted-foreground truncate">{append}</span>} {append && <span className="text-sm text-muted-foreground truncate">{append}</span>}
</div> </div>
) )

Loading…
Cancel
Save