"use client" import { useEffect, useState } from "react" import { getApiUrl } from "@/lib/api-config" import { Card, CardContent } from "@/components/ui/card" import { Calendar, MessageSquare, Star, Users } from "lucide-react" import Link from "next/link" import { WikiText } from "@/components/ui/wiki-text" import { UserAvatar } from "@/components/ui/user-avatar" interface EntityInfo { type: "performance" | "show" | "song" | "venue" | "tour" slug: string title: string date?: string } interface FeedItem { type: string timestamp: string data: any user: { id: number username: string display_name?: string | null avatar_bg_color?: string avatar_text?: string | null } entity?: EntityInfo | null } export function ActivityFeed() { const [feed, setFeed] = useState([]) const [loading, setLoading] = useState(true) useEffect(() => { const fetchFeed = async () => { try { const res = await fetch(`${getApiUrl()}/feed/`) if (!res.ok) { const text = await res.text() console.error('Feed API error:', res.status, text) setFeed([]) // Fallback to empty return } const data = await res.json() setFeed(data) } catch (error) { console.error('Failed to fetch feed:', error) setFeed([]) } finally { setLoading(false) } } fetchFeed() }, []) const getEntityLink = (entity: EntityInfo | null | undefined) => { if (!entity) return null const basePath = entity.type === "performance" ? "/performances" : entity.type === "show" ? "/shows" : entity.type === "song" ? "/songs" : entity.type === "venue" ? "/venues" : "/tours" return `${basePath}/${entity.slug}` } const getEntityTypeLabel = (entity: EntityInfo | null | undefined) => { if (!entity) return "something" switch (entity.type) { case "performance": return "a performance of" case "show": return "the" case "song": return "" case "venue": return "" default: return "" } } const displayName = (user: FeedItem["user"]) => user.display_name || user.username if (loading) return
Loading activity...
return (
{feed.map((item, idx) => (

{displayName(item.user)} {item.type === "review" && ( <> {" reviewed "} {item.entity ? ( {getEntityTypeLabel(item.entity)} {item.entity.title} {item.entity.date && ` (${new Date(item.entity.date).toLocaleDateString()})`} ) : ( "a performance" )} )} {item.type === "attendance" && ( <> {" attended "} {item.entity ? ( {item.entity.title} ) : ( "a show" )} )} {item.type === "post" && " posted in a group"}

{item.type === "review" && item.data.blurb && (
""
)} {item.type === "post" && (

{item.data.content}

)}

{new Date(item.timestamp).toLocaleDateString(undefined, { year: 'numeric', month: 'short', day: 'numeric' })}

))} {feed.length === 0 && (

No recent activity.

)}
) }