'use client'; import { useRef } from 'react'; import Image from 'next/image'; import { useQuery } from '@tanstack/react-query'; import api from '@/services/api'; export interface StoryUser { userId: string; username: string; avatarUrl?: string; hasUnread: boolean; } interface StoriesRingProps { onUserClick?: (userId: string) => void; } async function fetchStoriesFeed(): Promise { const { data } = await api.get('/api/v1/stories/feed'); return Array.isArray(data) ? data : []; } function AvatarFallback({ username }: { username: string }) { const initial = username ? username.charAt(0).toUpperCase() : '?'; return (
{initial}
); } interface StoryAvatarProps { user: StoryUser; onClick: (userId: string) => void; } function StoryAvatar({ user, onClick }: StoryAvatarProps) { const { userId, username, avatarUrl, hasUnread } = user; return ( ); } function YourStoryButton({ onClick }: { onClick: () => void }) { return ( ); } function StoriesRingSkeletons() { return ( <> {Array.from({ length: 6 }).map((_, i) => (
))} ); } export default function StoriesRing({ onUserClick }: StoriesRingProps) { const scrollRef = useRef(null); const { data: stories, isLoading } = useQuery({ queryKey: ['stories', 'feed'], queryFn: fetchStoriesFeed, refetchInterval: 30_000, staleTime: 30_000, retry: 1, }); function handleStoryClick(userId: string) { onUserClick?.(userId); } function handleYourStoryClick() { // no-op: parent handles navigation if needed } return (
{isLoading && } {!isLoading && stories?.map((user) => ( ))}
); }