'use client'; import React, { useState, useEffect } from 'react'; import { createClientComponentClient } from '@supabase/auth-helpers-nextjs'; import { ChevronLeft, Users, Calendar, GlassWater, Plus, Trash2, Loader2, Sparkles, ChevronRight, Play, Square } from 'lucide-react'; import Link from 'next/link'; import { useSession } from '@/context/SessionContext'; import { useParams, useRouter } from 'next/navigation'; import { useI18n } from '@/i18n/I18nContext'; interface Buddy { id: string; name: string; } interface Participant { buddy_id: string; buddies: { name: string; }; } interface Session { id: string; name: string; scheduled_at: string; } interface SessionTasting { id: string; rating: number; bottles: { id: string; name: string; distillery: string; }; } export default function SessionDetailPage() { const { t } = useI18n(); const { id } = useParams(); const router = useRouter(); const supabase = createClientComponentClient(); const [session, setSession] = useState(null); const [participants, setParticipants] = useState([]); const [tastings, setTastings] = useState([]); const [allBuddies, setAllBuddies] = useState([]); const [isLoading, setIsLoading] = useState(true); const { activeSession, setActiveSession } = useSession(); const [isAddingParticipant, setIsAddingParticipant] = useState(false); useEffect(() => { fetchSessionData(); }, [id]); const fetchSessionData = async () => { setIsLoading(true); // Fetch Session const { data: sessionData } = await supabase .from('tasting_sessions') .select('*') .eq('id', id) .single(); if (sessionData) { setSession(sessionData); // Fetch Participants const { data: partData } = await supabase .from('session_participants') .select('buddy_id, buddies(name)') .eq('session_id', id); setParticipants((partData as any)?.map((p: any) => ({ buddy_id: p.buddy_id, buddies: p.buddies })) || []); // Fetch Tastings in this session const { data: tastingData } = await supabase .from('tastings') .select('id, rating, bottles(id, name, distillery)') .eq('session_id', id); setTastings((tastingData as any)?.map((t: any) => ({ id: t.id, rating: t.rating, bottles: t.bottles })) || []); // Fetch all buddies for the picker const { data: buddies } = await supabase .from('buddies') .select('id, name') .order('name'); setAllBuddies(buddies || []); } setIsLoading(false); }; const handleAddParticipant = async (buddyId: string) => { if (participants.some(p => p.buddy_id === buddyId)) return; const { data: { user } } = await supabase.auth.getUser(); if (!user) return; const { error } = await supabase .from('session_participants') .insert([{ session_id: id, buddy_id: buddyId, user_id: user.id }]); if (!error) { fetchSessionData(); } }; const handleRemoveParticipant = async (buddyId: string) => { const { error } = await supabase .from('session_participants') .delete() .eq('session_id', id) .eq('buddy_id', buddyId); if (!error) { fetchSessionData(); } }; if (isLoading) { return (
); } if (!session) { return (

Session nicht gefunden

Zurück zum Start
); } return (
{/* Back Button */} Alle Sessions {/* Hero */}
Tasting Session

{session.name}

{new Date(session.scheduled_at).toLocaleDateString('de-DE')} {tastings.length > 0 && ( {tastings.length} {tastings.length === 1 ? 'Whisky' : 'Whiskys'} )}
{activeSession?.id !== session.id ? ( ) : ( )}
{/* Sidebar: Participants */} {/* Main Content: Bottle List */}

Verkostete Flaschen

Flasche hinzufügen
{tastings.length === 0 ? (
Noch keine Flaschen in dieser Session verkostet. 🥃
) : (
{tastings.map((t) => (
{t.bottles.distillery}
{t.bottles.name}
{t.rating}/100
))}
)}
); }