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>
120 lines
3.1 KiB
TypeScript
120 lines
3.1 KiB
TypeScript
'use client'
|
|
|
|
import { useEffect, useState } from 'react'
|
|
import { useRouter } from 'next/navigation'
|
|
import { useAuthStore } from '@/store/authStore'
|
|
import { storyService } from '@/services/storyService'
|
|
import { useToast } from '@/components/ui/toast'
|
|
|
|
export default function StoriesPage() {
|
|
const router = useRouter()
|
|
const { isAuthenticated } = useAuthStore()
|
|
const { showToast } = useToast()
|
|
const [stories, setStories] = useState<any[]>([])
|
|
const [currentIndex, setCurrentIndex] = useState(0)
|
|
const [loading, setLoading] = useState(true)
|
|
|
|
useEffect(() => {
|
|
if (!isAuthenticated) {
|
|
router.push('/login')
|
|
return
|
|
}
|
|
loadStories()
|
|
}, [isAuthenticated])
|
|
|
|
const loadStories = async () => {
|
|
try {
|
|
const data = await storyService.getStories()
|
|
const groups = Array.isArray(data?.stories) ? data.stories : []
|
|
const flattened = groups.flatMap((group: any) =>
|
|
Array.isArray(group?.stories)
|
|
? group.stories.map((story: any) => ({
|
|
...story,
|
|
user: story.user ?? group.user,
|
|
}))
|
|
: []
|
|
)
|
|
setStories(flattened)
|
|
} catch (error: unknown) {
|
|
showToast('Failed to load stories', 'error')
|
|
} finally {
|
|
setLoading(false)
|
|
}
|
|
}
|
|
|
|
const handleView = async (storyId: string) => {
|
|
try {
|
|
await storyService.viewStory(storyId)
|
|
} catch (error) {
|
|
console.error('Failed to mark story as viewed')
|
|
}
|
|
}
|
|
|
|
useEffect(() => {
|
|
if (stories[currentIndex]) {
|
|
handleView(stories[currentIndex].id)
|
|
}
|
|
}, [currentIndex])
|
|
|
|
if (!isAuthenticated || loading) return null
|
|
|
|
const currentStory = stories[currentIndex]
|
|
|
|
return (
|
|
<div className="fixed inset-0 bg-black">
|
|
{currentStory && (
|
|
<div className="relative h-full flex items-center justify-center">
|
|
{currentStory.mediaType === 'video' ? (
|
|
<video
|
|
src={currentStory.mediaUrl}
|
|
className="h-full w-auto max-w-full object-contain"
|
|
autoPlay
|
|
playsInline
|
|
/>
|
|
) : (
|
|
<img
|
|
src={currentStory.mediaUrl}
|
|
alt="Story"
|
|
className="h-full w-auto max-w-full object-contain"
|
|
/>
|
|
)}
|
|
|
|
<div className="absolute top-4 left-4 right-4 flex items-center gap-3 text-white">
|
|
<div className="w-10 h-10 rounded-full bg-white/20 flex items-center justify-center">
|
|
<span className="font-semibold">{currentStory.user?.username?.[0]?.toUpperCase()}</span>
|
|
</div>
|
|
<div className="flex-1">
|
|
<p className="font-semibold">{currentStory.user?.username}</p>
|
|
<p className="text-sm opacity-80">2h ago</p>
|
|
</div>
|
|
<button onClick={() => router.back()} className="text-white"></button>
|
|
</div>
|
|
|
|
<div className="absolute top-2 left-0 right-0 flex gap-1 px-4">
|
|
{stories.map((_, i) => (
|
|
<div key={i} className={`h-1 flex-1 rounded ${i === currentIndex ? 'bg-white' : 'bg-white/30'}`} />
|
|
))}
|
|
</div>
|
|
|
|
{currentIndex > 0 && (
|
|
<button
|
|
onClick={() => setCurrentIndex(currentIndex - 1)}
|
|
className="absolute left-4 top-1/2 -translate-y-1/2 w-12 h-12 bg-white/20 rounded-full flex items-center justify-center text-white"
|
|
>
|
|
←
|
|
</button>
|
|
)}
|
|
{currentIndex < stories.length - 1 && (
|
|
<button
|
|
onClick={() => setCurrentIndex(currentIndex + 1)}
|
|
className="absolute right-4 top-1/2 -translate-y-1/2 w-12 h-12 bg-white/20 rounded-full flex items-center justify-center text-white"
|
|
>
|
|
→
|
|
</button>
|
|
)}
|
|
</div>
|
|
)}
|
|
</div>
|
|
)
|
|
}
|