'use client'; import React, { useState, useEffect } from 'react'; import { motion, AnimatePresence } from 'framer-motion'; import { Plus, Check, ChevronRight, Loader2 } from 'lucide-react'; import { useSession } from '@/context/SessionContext'; import { createClient } from '@/lib/supabase/client'; interface Session { id: string; name: string; } interface SessionBottomSheetProps { isOpen: boolean; onClose: () => void; } export default function SessionBottomSheet({ isOpen, onClose }: SessionBottomSheetProps) { const { activeSession, setActiveSession } = useSession(); const [sessions, setSessions] = useState([]); const [newSessionName, setNewSessionName] = useState(''); const [isLoading, setIsLoading] = useState(false); const [isCreating, setIsCreating] = useState(false); const supabase = createClient(); useEffect(() => { if (isOpen) { fetchSessions(); } }, [isOpen]); const fetchSessions = async () => { setIsLoading(true); const { data, error } = await supabase .from('tasting_sessions') .select('id, name') .order('scheduled_at', { ascending: false }) .limit(10); if (!error && data) { setSessions(data); } setIsLoading(false); }; const handleCreateSession = async () => { if (!newSessionName.trim()) return; setIsCreating(true); const { data: { user } } = await supabase.auth.getUser(); if (!user) return; const { data, error } = await supabase .from('tasting_sessions') .insert([{ name: newSessionName.trim(), user_id: user.id }]) .select() .single(); if (!error && data) { setSessions(prev => [data, ...prev]); setNewSessionName(''); setActiveSession({ id: data.id, name: data.name }); onClose(); } setIsCreating(false); }; return ( {isOpen && ( <> {/* Backdrop */} {/* Sheet */} {/* Drag Handle */}

Tasting Session

{/* New Session Input */}
setNewSessionName(e.target.value)} onKeyDown={(e) => e.key === 'Enter' && handleCreateSession()} placeholder="Neue Session erstellen..." className="w-full bg-white/5 border border-white/10 rounded-2xl py-4 px-6 text-white focus:outline-none focus:border-[#C89D46] transition-colors" />
{/* Session List */}

Aktuelle Sessions

{isLoading ? (
) : sessions.length > 0 ? ( sessions.map((s) => ( )) ) : (
Keine aktiven Sessions gefunden
)}
)} ); }