Apple design (plans/gtm/APPLE-DESIGN-RULES-2026-11-17.md): rewrote theme tokens in globals.css/tailwind.config.js to neutral black/white + one accent (#0071E3), replacing the GitHub-dark blue+green dual-accent theme; mechanically swept every raw inline hex/rgba literal across app/components that bypassed the CSS vars (506 hex + 326 rgb(a) replacements) since most of the app hardcoded colors rather than using tokens; removed all emoji, decorative gradients (Tailwind bg-gradient-to-* and raw linear/radial- gradient() in inline styles), confetti, and glow/blur decorative orbs; converted Navbar/Navigation to icon-only with aria-label+title. Finished two stopped agents' in-progress work: deleted the fake AnimatedStats/ LiveActivity/ProjectShowcase/Testimonials auth-panel components and cleaned up the emoji-laden feature list in (auth)/layout.tsx. Removed remaining fabricated stats (topics/topics/[slug] posts-per-week/ contributors/followers) per the no-fake-numbers rule. Rithub sign-in: added "Continue with Rithub" as an icon-only OAuth2 button (RithubMark component) on login/register, hidden "Continue with GitHub" when GITHUB_CLIENT_ID is unset (confirmed unset in prod). Backend: authenticateWithGitea in oauthService.ts exchanges the Gitea OAuth2 code, resolves identity via the existing ForgeConnection table (no schema migration needed), issues the same JWT/session as GitHub/Google login. OAuth2 app created live on rithub.dev via its REST API as admin user caelum0x; client id/secret stored in railyard-box's compose file (env files don't ship to the runtime image, so the actual wiring lives in docker-compose.yml, not backend/.env) and in ~/products/.env. Critical bug found and fixed while verifying: services/api.ts's global 401 interceptor redirected every anonymous visitor to /login a couple seconds after ANY page load -- including /login and /register themselves -- because the AuthBootstrap's background GET /auth/me (expected to 401 for signed-out visitors) was treated the same as a real session-expiry 401, triggering a refresh attempt, another 401, and a hard window.location.href redirect, which re-ran AuthBootstrap and repeated. Fixed by excluding /auth/me and /auth/refresh from that redirect path. Verified live with a fresh, cookie-less browser: previously looped /register -> /login forever; now stable after 6s. Also fixed: production CORS/API origin mismatch -- the frontend was built with NEXT_PUBLIC_API_URL pointing at ritgram.ereboslab.com while served from ritgram.rithub.dev, so every API call (login, register, etc.) was blocked by CORS; rebuilt with rithub.dev as canonical and CORS_ORIGIN allowing both domains. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
283 lines
11 KiB
TypeScript
283 lines
11 KiB
TypeScript
'use client'
|
|
|
|
import { useEffect, useState } from 'react'
|
|
import { useParams, useSearchParams } from 'next/navigation'
|
|
import Link from 'next/link'
|
|
import api from '@/services/api'
|
|
|
|
// ─── Types ────────────────────────────────────────────────────────────────────
|
|
|
|
interface EmbedUserProfile {
|
|
id: string
|
|
username: string
|
|
displayName?: string
|
|
bio?: string
|
|
avatar?: string
|
|
postsCount: number
|
|
followersCount: number
|
|
followingCount: number
|
|
topLanguages?: string[]
|
|
isVerified?: boolean
|
|
}
|
|
|
|
type Theme = 'dark' | 'light'
|
|
|
|
// ─── Helpers ──────────────────────────────────────────────────────────────────
|
|
|
|
function formatCount(n: number): string {
|
|
if (n >= 1_000_000) return `${(n / 1_000_000).toFixed(1)}M`
|
|
if (n >= 1_000) return `${(n / 1_000).toFixed(1)}k`
|
|
return String(n)
|
|
}
|
|
|
|
function truncateBio(bio: string, max: number): string {
|
|
if (bio.length <= max) return bio
|
|
return bio.slice(0, max).trimEnd() + '…'
|
|
}
|
|
|
|
// ─── Language badge colours ───────────────────────────────────────────────────
|
|
|
|
const LANG_COLORS: Record<string, string> = {
|
|
typescript: '#3178c6', javascript: '#f7df1e', python: '#3572a5',
|
|
go: '#00add8', rust: '#dea584', java: '#b07219', kotlin: '#a97bff',
|
|
swift: '#f05138', ruby: '#701516', php: '#4f5d95', csharp: '#178600',
|
|
cpp: '#f34b7d', c: '#555555', css: '#563d7c', html: '#e34c26',
|
|
}
|
|
|
|
function langColor(lang: string): string {
|
|
return LANG_COLORS[lang.toLowerCase()] ?? 'var(--primary)'
|
|
}
|
|
|
|
// ─── Avatar ───────────────────────────────────────────────────────────────────
|
|
|
|
function Avatar({ user, isDark }: { user: EmbedUserProfile; isDark: boolean }) {
|
|
const initial = user.username?.[0]?.toUpperCase() ?? '?'
|
|
if (user.avatar) {
|
|
return (
|
|
<img
|
|
src={user.avatar}
|
|
alt={user.username}
|
|
width={56}
|
|
height={56}
|
|
style={{
|
|
width: 56, height: 56, borderRadius: '50%', objectFit: 'cover', flexShrink: 0,
|
|
border: `2px solid ${isDark ? 'var(--primary)' : '#a78bfa'}`,
|
|
}}
|
|
/>
|
|
)
|
|
}
|
|
return (
|
|
<div style={{
|
|
width: 56, height: 56, borderRadius: '50%', flexShrink: 0,
|
|
background: 'var(--primary)',
|
|
display: 'flex', alignItems: 'center', justifyContent: 'center',
|
|
fontSize: 22, fontWeight: 700, color: '#fff',
|
|
border: `2px solid ${isDark ? 'var(--primary)' : '#a78bfa'}`,
|
|
}}>
|
|
{initial}
|
|
</div>
|
|
)
|
|
}
|
|
|
|
// ─── Brand logo ───────────────────────────────────────────────────────────────
|
|
|
|
function BrandLogo() {
|
|
return (
|
|
<Link
|
|
href="https://ritgram.rithub.dev"
|
|
target="_blank"
|
|
rel="noopener noreferrer"
|
|
style={{ display: 'flex', alignItems: 'center', gap: 5, textDecoration: 'none' }}
|
|
>
|
|
<svg width="14" height="14" viewBox="0 0 24 24" fill="none">
|
|
<rect width="24" height="24" rx="6" fill="var(--primary)" />
|
|
<path d="M7 17V9.5L12 7l5 2.5V17" stroke="#fff" strokeWidth="1.8" strokeLinejoin="round" />
|
|
<path d="M9.5 17v-4.5h5V17" stroke="#fff" strokeWidth="1.8" strokeLinejoin="round" />
|
|
</svg>
|
|
<span style={{ fontSize: 11, fontWeight: 700, color: '#A78BFA', letterSpacing: '-0.01em' }}>Ritgram</span>
|
|
</Link>
|
|
)
|
|
}
|
|
|
|
// ─── Page ─────────────────────────────────────────────────────────────────────
|
|
|
|
export default function EmbedUserPage() {
|
|
const params = useParams()
|
|
const searchParams = useSearchParams()
|
|
const username = params.username as string
|
|
|
|
const theme: Theme = searchParams.get('theme') === 'light' ? 'light' : 'dark'
|
|
const isDark = theme === 'dark'
|
|
|
|
const [user, setUser] = useState<EmbedUserProfile | null>(null)
|
|
const [loading, setLoading] = useState(true)
|
|
const [error, setError] = useState(false)
|
|
|
|
useEffect(() => {
|
|
let cancelled = false
|
|
const fetchUser = async () => {
|
|
try {
|
|
const { data } = await api.get(`/users/${username}`)
|
|
const payload = data?.data ?? data
|
|
if (!cancelled) setUser(payload)
|
|
} catch {
|
|
if (!cancelled) setError(true)
|
|
} finally {
|
|
if (!cancelled) setLoading(false)
|
|
}
|
|
}
|
|
fetchUser()
|
|
return () => { cancelled = true }
|
|
}, [username])
|
|
|
|
const profileUrl = `https://ritgram.rithub.dev/${username}`
|
|
const s = buildStyles(isDark)
|
|
|
|
if (loading) {
|
|
return (
|
|
<div style={s.shell}>
|
|
<div style={s.body}>
|
|
<div style={{ display: 'flex', gap: 14, marginBottom: 14 }}>
|
|
<div style={{ width: 56, height: 56, borderRadius: '50%', background: s.skel.background as string, flexShrink: 0 }} />
|
|
<div style={{ flex: 1 }}>
|
|
<div style={{ ...s.skel, width: '50%', marginBottom: 8 }} />
|
|
<div style={{ ...s.skel, width: '35%' }} />
|
|
</div>
|
|
</div>
|
|
<div style={{ ...s.skel, width: '90%', marginBottom: 6 }} />
|
|
<div style={{ ...s.skel, width: '70%' }} />
|
|
</div>
|
|
<div style={s.footer}><BrandLogo /></div>
|
|
</div>
|
|
)
|
|
}
|
|
|
|
if (error || !user) {
|
|
return (
|
|
<div style={s.shell}>
|
|
<div style={{ ...s.body, justifyContent: 'center', alignItems: 'center' }}>
|
|
<p style={{ color: isDark ? '#64748B' : '#94a3b8', fontSize: 13, margin: 0 }}>User not found</p>
|
|
</div>
|
|
<div style={s.footer}><BrandLogo /></div>
|
|
</div>
|
|
)
|
|
}
|
|
|
|
const stats = [
|
|
{ label: 'Posts', value: formatCount(user.postsCount ?? 0) },
|
|
{ label: 'Followers', value: formatCount(user.followersCount ?? 0) },
|
|
{ label: 'Following', value: formatCount(user.followingCount ?? 0) },
|
|
]
|
|
|
|
return (
|
|
<div style={s.shell}>
|
|
<div style={s.body}>
|
|
{/* Avatar + name row */}
|
|
<div style={{ display: 'flex', alignItems: 'flex-start', gap: 14, marginBottom: 12 }}>
|
|
<Avatar user={user} isDark={isDark} />
|
|
<div style={{ minWidth: 0, flex: 1 }}>
|
|
<div style={{ display: 'flex', alignItems: 'center', gap: 5 }}>
|
|
<span style={{ fontSize: 15, fontWeight: 700, color: isDark ? '#e2e8f0' : '#1e293b', overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap' }}>
|
|
{user.displayName ?? user.username}
|
|
</span>
|
|
{user.isVerified && (
|
|
<svg width="14" height="14" fill={isDark ? '#0071e3' : '#1d4ed8'} viewBox="0 0 24 24" style={{ flexShrink: 0 }}>
|
|
<path d="M9 12l2 2 4-4m6 2a9 9 0 11-18 0 9 9 0 0118 0z" stroke="currentColor" strokeWidth={2} fill="none" strokeLinecap="round" strokeLinejoin="round" />
|
|
</svg>
|
|
)}
|
|
</div>
|
|
<span style={{ fontSize: 12, color: isDark ? '#98989d' : '#6e6e73' }}>@{user.username}</span>
|
|
</div>
|
|
</div>
|
|
|
|
{/* Bio */}
|
|
{user.bio && (
|
|
<p style={{ fontSize: 12, color: isDark ? '#94a3b8' : '#475569', lineHeight: 1.6, margin: '0 0 12px', wordBreak: 'break-word' }}>
|
|
{truncateBio(user.bio, 120)}
|
|
</p>
|
|
)}
|
|
|
|
{/* Stats row */}
|
|
<div style={{ display: 'flex', gap: 0, marginBottom: 12, borderTop: `1px solid ${isDark ? '#2c2c2e' : '#e2e8f0'}`, borderBottom: `1px solid ${isDark ? '#2c2c2e' : '#e2e8f0'}`, padding: '8px 0' }}>
|
|
{stats.map(({ label, value }) => (
|
|
<div key={label} style={{ flex: 1, textAlign: 'center' }}>
|
|
<div style={{ fontSize: 14, fontWeight: 700, color: isDark ? '#e2e8f0' : '#1e293b' }}>{value}</div>
|
|
<div style={{ fontSize: 10, color: isDark ? '#98989d' : '#6e6e73', marginTop: 1 }}>{label}</div>
|
|
</div>
|
|
))}
|
|
</div>
|
|
|
|
{/* Top languages */}
|
|
{user.topLanguages && user.topLanguages.length > 0 && (
|
|
<div style={{ display: 'flex', flexWrap: 'wrap', gap: 5, marginBottom: 12 }}>
|
|
{user.topLanguages.slice(0, 5).map((lang) => (
|
|
<span key={lang} style={{
|
|
fontSize: 10, fontWeight: 600, padding: '2px 8px', borderRadius: 999,
|
|
background: isDark ? '#000000' : '#f1f5f9',
|
|
color: langColor(lang),
|
|
border: `1px solid ${isDark ? '#38383a' : '#e2e8f0'}`,
|
|
display: 'flex', alignItems: 'center', gap: 4,
|
|
}}>
|
|
<span style={{ width: 7, height: 7, borderRadius: '50%', background: langColor(lang), display: 'inline-block', flexShrink: 0 }} />
|
|
{lang.charAt(0).toUpperCase() + lang.slice(1)}
|
|
</span>
|
|
))}
|
|
</div>
|
|
)}
|
|
|
|
{/* CTA button */}
|
|
<Link
|
|
href={profileUrl}
|
|
target="_blank"
|
|
rel="noopener noreferrer"
|
|
style={{
|
|
display: 'block', textAlign: 'center', padding: '7px 14px',
|
|
borderRadius: 8, textDecoration: 'none', fontSize: 12, fontWeight: 600,
|
|
background: 'var(--primary)',
|
|
color: '#fff', transition: 'opacity 0.15s',
|
|
}}
|
|
>
|
|
Follow on Ritgram
|
|
</Link>
|
|
</div>
|
|
|
|
{/* Footer */}
|
|
<div style={s.footer}>
|
|
<BrandLogo />
|
|
<span style={{ fontSize: 10, color: isDark ? '#475569' : '#94a3b8' }}>
|
|
ritgram.rithub.dev/{username}
|
|
</span>
|
|
</div>
|
|
</div>
|
|
)
|
|
}
|
|
|
|
// ─── Styles factory ───────────────────────────────────────────────────────────
|
|
|
|
function buildStyles(isDark: boolean): Record<string, React.CSSProperties> {
|
|
const bg = isDark ? '#0F0F1A' : '#ffffff'
|
|
const surface = isDark ? '#1c1c1e' : '#f6f8fa'
|
|
const border = isDark ? '#2c2c2e' : '#d0d7de'
|
|
|
|
return {
|
|
shell: {
|
|
display: 'flex', flexDirection: 'column', height: '100vh', overflow: 'hidden',
|
|
background: bg,
|
|
fontFamily: 'system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif',
|
|
},
|
|
body: {
|
|
flex: 1, padding: '16px', overflow: 'hidden', display: 'flex', flexDirection: 'column',
|
|
},
|
|
footer: {
|
|
display: 'flex', alignItems: 'center', justifyContent: 'space-between',
|
|
padding: '7px 14px', borderTop: `1px solid ${border}`,
|
|
background: surface, flexShrink: 0,
|
|
},
|
|
skel: {
|
|
height: 10, borderRadius: 4,
|
|
background: isDark ? '#2c2c2e' : '#e1e4e8',
|
|
marginBottom: 6,
|
|
},
|
|
}
|
|
}
|