import { useState, useEffect } from "react"; import { View, StyleSheet, Text, ActivityIndicator, Platform } from "react-native"; import { useLocalSearchParams } from "expo-router"; import { Ionicons } from "@expo/vector-icons"; import Animated, { FadeIn, FadeInUp } from "react-native-reanimated"; import { supabase } from "../../src/lib/supabase"; import SwipeCard from "../../src/components/SwipeCard"; import { GradientBackground, GlassCard, GlassButton } from "../../src/components/ui"; import { colors, spacing, typography, radius, shadows } from "../../src/theme"; export default function SwipeScreen() { const { packId } = useLocalSearchParams(); const [questions, setQuestions] = useState([]); const [isLoading, setIsLoading] = useState(true); const [currentIndex, setCurrentIndex] = useState(0); useEffect(() => { fetchQuestions(); }, [packId]); const fetchQuestions = async () => { try { const { data, error } = await supabase.rpc("get_recommended_questions", { target_pack_id: packId || null }); if (error) { console.error("Error fetching recommended questions:", error); throw error; } const sorted = (data || []).sort((a: any, b: any) => { let scoreA = Math.random(); let scoreB = Math.random(); if (a.partner_answered && a.is_two_part) scoreA += 1.5; else if (a.partner_answered) scoreA += 0.7; else if (a.is_two_part) scoreA += 0.4; if (b.partner_answered && b.is_two_part) scoreB += 1.5; else if (b.partner_answered) scoreB += 0.7; else if (b.is_two_part) scoreB += 0.4; return scoreB - scoreA; }); setQuestions(sorted); } catch (error) { console.error(error); } finally { setIsLoading(false); } }; const handleSwipe = async (direction: "left" | "right" | "up") => { const question = questions[currentIndex]; const answer = direction === "right" ? "yes" : direction === "left" ? "no" : "maybe"; setCurrentIndex(prev => prev + 1); try { const { data: { session } } = await supabase.auth.getSession(); console.log("DEBUG - Session exists:", !!session); await supabase.functions.invoke("submit-response", { body: { question_id: question.id, answer, }, }); } catch (error) { console.error("Failed to submit response", error); } }; if (isLoading) { return ( ); } if (currentIndex >= questions.length) { return ( All caught up! Check back later for more questions or try a different pack. Refresh Questions ); } return ( {/* Header */} {currentIndex + 1} of {questions.length} {/* Card Stack */} {/* Background card (next) */} {questions[currentIndex + 1] && ( )} {/* Active card */} {/* Hint */} Swipe or tap to answer {/* Bottom spacing for tab bar */} ); } const styles = StyleSheet.create({ container: { flex: 1, }, centerContainer: { flex: 1, justifyContent: "center", alignItems: "center", }, header: { paddingTop: 60, paddingHorizontal: spacing.lg, paddingBottom: spacing.md, }, progressContainer: { alignItems: "center", }, progressText: { ...typography.subhead, color: colors.textSecondary, marginBottom: spacing.sm, }, progressBar: { width: 120, height: 4, backgroundColor: colors.glass.background, borderRadius: 2, overflow: "hidden", }, progressFill: { height: "100%", backgroundColor: colors.primary, borderRadius: 2, }, cardContainer: { flex: 1, justifyContent: "center", alignItems: "center", }, backgroundCard: { position: "absolute", width: "85%", height: 480, backgroundColor: colors.glass.backgroundLight, borderRadius: radius.xxl, borderWidth: 1, borderColor: colors.glass.border, transform: [{ scale: 0.95 }, { translateY: 12 }], opacity: 0.5, ...shadows.md, }, hintContainer: { alignItems: "center", paddingBottom: spacing.md, }, hintText: { ...typography.caption1, color: colors.textTertiary, }, emptyContent: { alignItems: "center", paddingHorizontal: spacing.xl, }, emptyIconContainer: { width: 120, height: 120, borderRadius: 60, backgroundColor: colors.primaryLight, justifyContent: "center", alignItems: "center", marginBottom: spacing.lg, }, emptyTitle: { ...typography.title2, color: colors.text, marginBottom: spacing.sm, }, emptySubtitle: { ...typography.body, color: colors.textSecondary, textAlign: "center", }, bottomSpacer: { height: Platform.OS === 'ios' ? 100 : 80, }, });