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>
321 lines
7.8 KiB
TypeScript
321 lines
7.8 KiB
TypeScript
'use client'
|
|
|
|
import { useEffect, useRef, useCallback } from 'react'
|
|
|
|
export interface GridPost {
|
|
id: string
|
|
content: string
|
|
author: {
|
|
username: string
|
|
avatarUrl?: string
|
|
}
|
|
likes: number
|
|
comments: number
|
|
createdAt: string
|
|
thumbnailUrl?: string
|
|
/** Author-supplied alt text for the thumbnail (accessibility). */
|
|
thumbnailAlt?: string
|
|
}
|
|
|
|
export interface PostGridProps {
|
|
posts: GridPost[]
|
|
onLoadMore: () => void
|
|
hasMore: boolean
|
|
isLoading: boolean
|
|
}
|
|
|
|
const CONTENT_PREVIEW_MAX = 80
|
|
|
|
function truncate(text: string, max: number): string {
|
|
if (text.length <= max) return text
|
|
return text.slice(0, max).trimEnd() + '…'
|
|
}
|
|
|
|
function HeartIcon() {
|
|
return (
|
|
<svg
|
|
xmlns="http://www.w3.org/2000/svg"
|
|
viewBox="0 0 24 24"
|
|
fill="currentColor"
|
|
aria-hidden="true"
|
|
style={{ width: 16, height: 16 }}
|
|
>
|
|
<path d="M11.645 20.91l-.007-.003-.022-.012a15.247 15.247 0 01-.383-.218 25.18 25.18 0 01-4.244-3.17C4.688 15.36 2.25 12.174 2.25 8.25 2.25 5.322 4.714 3 7.688 3A5.5 5.5 0 0112 5.052 5.5 5.5 0 0116.313 3c2.973 0 5.437 2.322 5.437 5.25 0 3.925-2.438 7.111-4.739 9.256a25.175 25.175 0 01-4.244 3.17 15.247 15.247 0 01-.383.219l-.022.012-.007.004-.003.001a.752.752 0 01-.704 0l-.003-.001z" />
|
|
</svg>
|
|
)
|
|
}
|
|
|
|
function CommentIcon() {
|
|
return (
|
|
<svg
|
|
xmlns="http://www.w3.org/2000/svg"
|
|
viewBox="0 0 24 24"
|
|
fill="currentColor"
|
|
aria-hidden="true"
|
|
style={{ width: 16, height: 16 }}
|
|
>
|
|
<path
|
|
fillRule="evenodd"
|
|
d="M4.804 21.644A6.707 6.707 0 006 21.75a6.721 6.721 0 003.583-1.029c.774.182 1.584.279 2.417.279 5.322 0 9.75-3.97 9.75-9 0-5.03-4.428-9-9.75-9s-9.75 3.97-9.75 9c0 2.409 1.025 4.587 2.674 6.192.232.226.277.428.254.543a3.73 3.73 0 01-.814 1.686.75.75 0 00.44 1.223 4.996 4.996 0 003-.621z"
|
|
clipRule="evenodd"
|
|
/>
|
|
</svg>
|
|
)
|
|
}
|
|
|
|
function SkeletonCell() {
|
|
return (
|
|
<div
|
|
aria-hidden="true"
|
|
style={{
|
|
aspectRatio: '1 / 1',
|
|
borderRadius: 8,
|
|
background: '#1A1A2E',
|
|
animation: 'postgrid-pulse 1.5s ease-in-out infinite',
|
|
}}
|
|
/>
|
|
)
|
|
}
|
|
|
|
function PostCell({ post }: { post: GridPost }) {
|
|
const preview = truncate(post.content, CONTENT_PREVIEW_MAX)
|
|
|
|
return (
|
|
<article
|
|
style={{
|
|
position: 'relative',
|
|
aspectRatio: '1 / 1',
|
|
borderRadius: 8,
|
|
overflow: 'hidden',
|
|
background: '#1A1A2E',
|
|
cursor: 'pointer',
|
|
}}
|
|
>
|
|
{/* Background: thumbnail image or gradient fallback */}
|
|
{post.thumbnailUrl ? (
|
|
<img
|
|
src={post.thumbnailUrl}
|
|
alt={post.thumbnailAlt?.trim() || ''}
|
|
aria-hidden={post.thumbnailAlt?.trim() ? undefined : 'true'}
|
|
style={{
|
|
position: 'absolute',
|
|
inset: 0,
|
|
width: '100%',
|
|
height: '100%',
|
|
objectFit: 'cover',
|
|
}}
|
|
/>
|
|
) : (
|
|
<div
|
|
aria-hidden="true"
|
|
style={{
|
|
position: 'absolute',
|
|
inset: 0,
|
|
background:
|
|
'#1A1A2E',
|
|
}}
|
|
/>
|
|
)}
|
|
|
|
{/* Content preview bar (always visible at bottom) */}
|
|
<div
|
|
style={{
|
|
position: 'absolute',
|
|
inset: 0,
|
|
display: 'flex',
|
|
flexDirection: 'column',
|
|
justifyContent: 'flex-end',
|
|
padding: '10px 12px',
|
|
background:
|
|
'rgba(0,0,0,0.5)',
|
|
}}
|
|
>
|
|
<p
|
|
style={{
|
|
margin: 0,
|
|
fontSize: 12,
|
|
lineHeight: 1.4,
|
|
color: 'rgba(255,255,255,0.8)',
|
|
wordBreak: 'break-word',
|
|
}}
|
|
>
|
|
{preview}
|
|
</p>
|
|
</div>
|
|
|
|
{/* Hover overlay with like/comment counts */}
|
|
<div
|
|
className="postgrid-hover-overlay"
|
|
style={{
|
|
position: 'absolute',
|
|
inset: 0,
|
|
display: 'flex',
|
|
flexDirection: 'column',
|
|
alignItems: 'center',
|
|
justifyContent: 'center',
|
|
gap: 12,
|
|
background: 'rgba(15,15,26,0.78)',
|
|
opacity: 0,
|
|
transition: 'opacity 0.2s ease',
|
|
}}
|
|
>
|
|
<div
|
|
style={{
|
|
display: 'flex',
|
|
alignItems: 'center',
|
|
gap: 18,
|
|
}}
|
|
>
|
|
<span
|
|
style={{
|
|
display: 'flex',
|
|
alignItems: 'center',
|
|
gap: 5,
|
|
color: '#ffffff',
|
|
fontSize: 14,
|
|
fontWeight: 600,
|
|
}}
|
|
>
|
|
<HeartIcon />
|
|
{post.likes.toLocaleString()}
|
|
</span>
|
|
<span
|
|
style={{
|
|
display: 'flex',
|
|
alignItems: 'center',
|
|
gap: 5,
|
|
color: '#ffffff',
|
|
fontSize: 14,
|
|
fontWeight: 600,
|
|
}}
|
|
>
|
|
<CommentIcon />
|
|
{post.comments.toLocaleString()}
|
|
</span>
|
|
</div>
|
|
|
|
<span
|
|
style={{
|
|
fontSize: 11,
|
|
color: 'rgba(255,255,255,0.6)',
|
|
}}
|
|
>
|
|
@{post.author.username}
|
|
</span>
|
|
</div>
|
|
</article>
|
|
)
|
|
}
|
|
|
|
export default function PostGrid({
|
|
posts,
|
|
onLoadMore,
|
|
hasMore,
|
|
isLoading,
|
|
}: PostGridProps) {
|
|
const sentinelRef = useRef<HTMLDivElement>(null)
|
|
|
|
// Stable ref so the IntersectionObserver callback never captures stale props
|
|
const onLoadMoreRef = useRef(onLoadMore)
|
|
useEffect(() => {
|
|
onLoadMoreRef.current = onLoadMore
|
|
}, [onLoadMore])
|
|
|
|
const handleIntersect = useCallback(
|
|
(entries: IntersectionObserverEntry[]) => {
|
|
const [entry] = entries
|
|
if (entry.isIntersecting && hasMore && !isLoading) {
|
|
onLoadMoreRef.current()
|
|
}
|
|
},
|
|
[hasMore, isLoading],
|
|
)
|
|
|
|
useEffect(() => {
|
|
const el = sentinelRef.current
|
|
if (!el) return
|
|
|
|
const observer = new IntersectionObserver(handleIntersect, {
|
|
rootMargin: '120px',
|
|
threshold: 0,
|
|
})
|
|
|
|
observer.observe(el)
|
|
return () => observer.disconnect()
|
|
}, [handleIntersect])
|
|
|
|
return (
|
|
<>
|
|
<style>{`
|
|
@keyframes postgrid-pulse {
|
|
0%, 100% { opacity: 1; }
|
|
50% { opacity: 0.4; }
|
|
}
|
|
.postgrid-cell:hover .postgrid-hover-overlay {
|
|
opacity: 1 !important;
|
|
}
|
|
@media (max-width: 768px) {
|
|
.postgrid-root {
|
|
grid-template-columns: repeat(2, 1fr) !important;
|
|
}
|
|
}
|
|
@media (max-width: 480px) {
|
|
.postgrid-root {
|
|
grid-template-columns: repeat(1, 1fr) !important;
|
|
}
|
|
}
|
|
`}</style>
|
|
|
|
<section
|
|
aria-label="Posts grid"
|
|
style={{
|
|
background: '#0F0F1A',
|
|
padding: '8px 0',
|
|
minHeight: '100%',
|
|
}}
|
|
>
|
|
<div
|
|
className="postgrid-root"
|
|
style={{
|
|
display: 'grid',
|
|
gridTemplateColumns: 'repeat(3, 1fr)',
|
|
gap: 3,
|
|
}}
|
|
>
|
|
{posts.map((post) => (
|
|
<div key={post.id} className="postgrid-cell">
|
|
<PostCell post={post} />
|
|
</div>
|
|
))}
|
|
|
|
{isLoading &&
|
|
Array.from({ length: 6 }).map((_, i) => (
|
|
<SkeletonCell key={`skeleton-${i}`} />
|
|
))}
|
|
</div>
|
|
|
|
{/* Sentinel element watched by IntersectionObserver */}
|
|
<div
|
|
ref={sentinelRef}
|
|
aria-hidden="true"
|
|
style={{ height: 1, marginTop: 8 }}
|
|
/>
|
|
|
|
{!hasMore && !isLoading && posts.length > 0 && (
|
|
<p
|
|
style={{
|
|
textAlign: 'center',
|
|
color: 'rgba(255,255,255,0.35)',
|
|
fontSize: 13,
|
|
padding: '24px 0 16px',
|
|
margin: 0,
|
|
}}
|
|
>
|
|
You’ve reached the end
|
|
</p>
|
|
)}
|
|
</section>
|
|
</>
|
|
)
|
|
}
|