fix oauth
This commit is contained in:
55
src/web/components/profile.ts
Normal file
55
src/web/components/profile.ts
Normal file
@@ -0,0 +1,55 @@
|
||||
import type { Profile } from '../types'
|
||||
import { getAvatarUrl } from '../lib/api'
|
||||
|
||||
export async function renderProfile(
|
||||
did: string,
|
||||
profile: Profile,
|
||||
handle: string,
|
||||
webUrl?: string
|
||||
): Promise<string> {
|
||||
const avatarUrl = await getAvatarUrl(did, profile)
|
||||
const displayName = profile.value.displayName || handle || 'Unknown'
|
||||
const description = profile.value.description || ''
|
||||
|
||||
// Build profile link (e.g., https://bsky.app/profile/did:plc:xxx)
|
||||
const profileLink = webUrl ? `${webUrl}/profile/${did}` : null
|
||||
|
||||
const handleHtml = profileLink
|
||||
? `<a href="${profileLink}" class="profile-handle-link" target="_blank" rel="noopener">@${escapeHtml(handle)}</a>`
|
||||
: `<span>@${escapeHtml(handle)}</span>`
|
||||
|
||||
const avatarHtml = avatarUrl
|
||||
? `<a href="/"><img class="profile-avatar" src="${avatarUrl}" alt="${displayName}"></a>`
|
||||
: `<a href="/"><div class="profile-avatar-placeholder"></div></a>`
|
||||
|
||||
return `
|
||||
<div class="profile">
|
||||
<div class="profile-row">
|
||||
${avatarHtml}
|
||||
<div class="profile-meta">
|
||||
<span class="profile-name">${escapeHtml(displayName)}</span>
|
||||
<span class="profile-handle">${handleHtml}</span>
|
||||
</div>
|
||||
</div>
|
||||
${description ? `
|
||||
<div class="profile-row">
|
||||
<div class="profile-avatar-spacer"></div>
|
||||
<p class="profile-description">${escapeHtml(description)}</p>
|
||||
</div>
|
||||
` : ''}
|
||||
</div>
|
||||
`
|
||||
}
|
||||
|
||||
export function mountProfile(container: HTMLElement, html: string): void {
|
||||
container.innerHTML = html
|
||||
}
|
||||
|
||||
function escapeHtml(text: string): string {
|
||||
return text
|
||||
.replace(/&/g, '&')
|
||||
.replace(/</g, '<')
|
||||
.replace(/>/g, '>')
|
||||
.replace(/"/g, '"')
|
||||
.replace(/'/g, ''')
|
||||
}
|
||||
Reference in New Issue
Block a user