caelum0x aa848c66d0 fix(ritgram): Apple-design unslop pass + Rithub OAuth2 sign-in + critical login-redirect-loop fix
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>
2026-11-17 17:33:41 +03:00

297 lines
12 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 EmbedRepo {
id: string
owner: string
name: string
fullName: string
description?: string
stars: number
forks: number
language?: string
updatedAt?: string
pushedAt?: string
topics?: string[]
isPrivate?: 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 formatRelativeTime(dateString: string): string {
const diffMs = Date.now() - new Date(dateString).getTime()
const diffMin = Math.floor(diffMs / 60_000)
const diffHr = Math.floor(diffMs / 3_600_000)
const diffDay = Math.floor(diffMs / 86_400_000)
const diffMonth = Math.floor(diffDay / 30)
if (diffMin < 1) return 'just now'
if (diffMin < 60) return `${diffMin}m ago`
if (diffHr < 24) return `${diffHr}h ago`
if (diffDay < 30) return `${diffDay}d ago`
if (diffMonth < 12) return `${diffMonth}mo ago`
return new Date(dateString).toLocaleDateString(undefined, { month: 'short', year: 'numeric' })
}
// ─── Language 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)'
}
// ─── 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 EmbedRepoPage() {
const params = useParams()
const searchParams = useSearchParams()
const owner = params.owner as string
const repoName = params.name as string
const theme: Theme = searchParams.get('theme') === 'light' ? 'light' : 'dark'
const isDark = theme === 'dark'
const [repo, setRepo] = useState<EmbedRepo | null>(null)
const [loading, setLoading] = useState(true)
const [error, setError] = useState(false)
useEffect(() => {
let cancelled = false
const fetchRepo = async () => {
try {
const { data } = await api.get(`/repositories/${owner}/${repoName}`)
const payload = data?.data ?? data
if (!cancelled) setRepo(payload)
} catch {
if (!cancelled) setError(true)
} finally {
if (!cancelled) setLoading(false)
}
}
fetchRepo()
return () => { cancelled = true }
}, [owner, repoName])
const repoUrl = `https://ritgram.rithub.dev/${owner}/${repoName}`
const s = buildStyles(isDark)
if (loading) {
return (
<div style={s.shell}>
<div style={s.body}>
<div style={{ ...s.skel, width: '55%', height: 14, marginBottom: 10 }} />
<div style={{ ...s.skel, width: '100%', marginBottom: 6 }} />
<div style={{ ...s.skel, width: '75%', marginBottom: 16 }} />
<div style={{ display: 'flex', gap: 16 }}>
{[0, 1, 2].map((i) => (
<div key={i} style={{ ...s.skel, width: 48, height: 20 }} />
))}
</div>
</div>
<div style={s.footer}><BrandLogo /></div>
</div>
)
}
if (error || !repo) {
return (
<div style={s.shell}>
<div style={{ ...s.body, justifyContent: 'center', alignItems: 'center' }}>
<svg width="24" height="24" fill="none" stroke={isDark ? '#475569' : '#94a3b8'} strokeWidth={1.5} viewBox="0 0 24 24" style={{ marginBottom: 8 }}>
<path strokeLinecap="round" strokeLinejoin="round" d="M12 9v4m0 4h.01M3.055 11C3.548 6.956 7.33 4 12 4s8.452 2.956 8.945 7M12 4v1M3 12h1m17 0h-1" />
</svg>
<p style={{ color: isDark ? '#64748B' : '#94a3b8', fontSize: 13, margin: 0 }}>Repository not found</p>
</div>
<div style={s.footer}><BrandLogo /></div>
</div>
)
}
const lastActivity = repo.pushedAt ?? repo.updatedAt
return (
<div style={s.shell}>
<div style={s.body}>
{/* Repo name + icon */}
<div style={{ display: 'flex', alignItems: 'center', gap: 8, marginBottom: 6 }}>
<svg width="16" height="16" fill="none" stroke={isDark ? '#98989d' : '#6e6e73'} strokeWidth={1.8} viewBox="0 0 24 24" style={{ flexShrink: 0 }}>
<path strokeLinecap="round" strokeLinejoin="round" d="M3 7a2 2 0 012-2h14a2 2 0 012 2v10a2 2 0 01-2 2H5a2 2 0 01-2-2V7z" />
<path strokeLinecap="round" strokeLinejoin="round" d="M3 7l9 6 9-6" />
</svg>
<span style={{ fontSize: 15, fontWeight: 700, color: isDark ? '#0071e3' : '#0969da', overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap' }}>
{repo.fullName ?? `${owner}/${repoName}`}
</span>
{repo.isPrivate && (
<span style={{ fontSize: 9, fontWeight: 600, padding: '1px 5px', borderRadius: 999, border: `1px solid ${isDark ? '#38383a' : '#d0d7de'}`, color: isDark ? '#98989d' : '#6e6e73', flexShrink: 0 }}>
Private
</span>
)}
</div>
{/* Description */}
{repo.description ? (
<p style={{ fontSize: 12, color: isDark ? '#94a3b8' : '#475569', lineHeight: 1.6, margin: '0 0 14px', wordBreak: 'break-word' }}>
{repo.description.length > 140 ? repo.description.slice(0, 140).trimEnd() + '…' : repo.description}
</p>
) : (
<p style={{ fontSize: 12, color: isDark ? '#475569' : '#94a3b8', fontStyle: 'italic', margin: '0 0 14px' }}>
No description provided.
</p>
)}
{/* Stats row: stars, forks, language */}
<div style={{ display: 'flex', alignItems: 'center', gap: 14, marginBottom: 14, flexWrap: 'wrap' }}>
{/* Stars */}
<div style={{ display: 'flex', alignItems: 'center', gap: 4 }}>
<svg width="14" height="14" fill={isDark ? '#e3b341' : '#9a6700'} viewBox="0 0 24 24">
<path d="M12 2l3.09 6.26L22 9.27l-5 4.87 1.18 6.88L12 17.77l-6.18 3.25L7 14.14 2 9.27l6.91-1.01L12 2z" />
</svg>
<span style={{ fontSize: 12, fontWeight: 600, color: isDark ? '#e3b341' : '#9a6700' }}>
{formatCount(repo.stars ?? 0)}
</span>
</div>
{/* Forks */}
<div style={{ display: 'flex', alignItems: 'center', gap: 4 }}>
<svg width="14" height="14" fill="none" stroke={isDark ? '#98989d' : '#6e6e73'} strokeWidth={1.8} viewBox="0 0 24 24">
<path strokeLinecap="round" strokeLinejoin="round" d="M7 5a2 2 0 100 4 2 2 0 000-4zm10 0a2 2 0 100 4 2 2 0 000-4zm-5 10a2 2 0 100 4 2 2 0 000-4zM7 9v2a5 5 0 0010 0V9M12 15v-4" />
</svg>
<span style={{ fontSize: 12, color: isDark ? '#98989d' : '#6e6e73' }}>
{formatCount(repo.forks ?? 0)}
</span>
</div>
{/* Language */}
{repo.language && (
<div style={{ display: 'flex', alignItems: 'center', gap: 5 }}>
<span style={{ width: 10, height: 10, borderRadius: '50%', background: langColor(repo.language), display: 'inline-block', flexShrink: 0 }} />
<span style={{ fontSize: 12, color: isDark ? '#98989d' : '#6e6e73' }}>{repo.language}</span>
</div>
)}
</div>
{/* Last activity */}
{lastActivity && (
<div style={{ display: 'flex', alignItems: 'center', gap: 5, marginBottom: 14 }}>
<svg width="12" height="12" fill="none" stroke={isDark ? '#475569' : '#94a3b8'} strokeWidth={1.8} viewBox="0 0 24 24" style={{ flexShrink: 0 }}>
<path strokeLinecap="round" strokeLinejoin="round" d="M12 8v4l3 3m6-3a9 9 0 11-18 0 9 9 0 0118 0z" />
</svg>
<span style={{ fontSize: 11, color: isDark ? '#475569' : '#94a3b8' }}>
Updated {formatRelativeTime(lastActivity)}
</span>
</div>
)}
{/* Topics */}
{repo.topics && repo.topics.length > 0 && (
<div style={{ display: 'flex', flexWrap: 'wrap', gap: 5, marginBottom: 14 }}>
{repo.topics.slice(0, 4).map((topic) => (
<span key={topic} style={{
fontSize: 10, fontWeight: 500, padding: '2px 7px', borderRadius: 999,
background: isDark ? '#000000' : '#ddf4ff',
color: isDark ? '#0071e3' : '#0969da',
border: `1px solid ${isDark ? '#1f3a5c' : '#b6e3ff'}`,
}}>
{topic}
</span>
))}
</div>
)}
{/* CTA button */}
<Link
href={repoUrl}
target="_blank"
rel="noopener noreferrer"
style={{
display: 'block', textAlign: 'center', padding: '7px 14px',
borderRadius: 8, textDecoration: 'none', fontSize: 12, fontWeight: 600,
background: isDark
? '#0071e3'
: '#30D158',
color: '#fff', marginTop: 'auto',
}}
>
View Repository
</Link>
</div>
{/* Footer */}
<div style={s.footer}>
<BrandLogo />
<span style={{ fontSize: 10, color: isDark ? '#475569' : '#94a3b8' }}>
{owner}/{repoName}
</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,
},
}
}