"use client"; import { IconSymbol } from "@/components/ui/IconSymbol"; import { supabase } from "@/services/supabase"; import { useQuery } from "@tanstack/react-query"; import { router, useLocalSearchParams } from "expo-router"; import "nativewind"; import { useState } from "react"; import { Alert, ScrollView, Text, TouchableOpacity, View } from "react-native"; import { SafeAreaView } from "react-native-safe-area-context"; interface Step { id: string; food_id: string; title: string; step_order: number; description: string; created_at: string; } export default function CookingSessionScreen() { const { id: foodId } = useLocalSearchParams(); const [currentStep, setCurrentStep] = useState(0); const { data: steps, isLoading: stepsLoading, error: stepsError, } = useQuery({ queryKey: ["food-steps", foodId], queryFn: async () => { const { data, error } = await supabase .from("cooking_steps") .select( ` id, food_id, title, step_order, description, created_at ` ) .eq("food_id", foodId) .order("step_order", { ascending: true }); if (error) throw error; return data ?? []; }, enabled: !!foodId, }); if (stepsLoading) { return ( Loading... ); } if (stepsError) { return ( Error loading steps ); } const totalSteps = steps?.length || 0; const goToNextStep = () => { if (currentStep < totalSteps - 1) { setCurrentStep(currentStep + 1); } }; const goToPreviousStep = () => { if (currentStep > 0) { setCurrentStep(currentStep - 1); } }; const stopCookingSession = () => { Alert.alert( "Stop Cooking?", "Are you sure you want to stop this cooking session?", [ { text: "Cancel", style: "cancel" }, { text: "Yes, stop", onPress: () => router.back() }, ] ); }; if (!steps || steps.length === 0) { return ( No steps found router.back()} > Go back to home page ); } return ( {/* Header with back button */} router.back()} > {/* Step Illustration */} {/* If your steps have an image property, render it. Otherwise, skip the image or add a placeholder. */} {/* */} {/* Step Information */} Step {currentStep + 1} of {totalSteps} {steps && steps[currentStep]?.title} {steps && steps[currentStep]?.description} {/* Step Indicators */} Steps {steps && steps.map((_: any, index: any) => ( setCurrentStep(index)} > ))} {/* Navigation Buttons */} {currentStep > 0 && ( Previous )} {currentStep < totalSteps - 1 ? ( Next Step ) : ( router.back()} > Finish )} {/* Stop Session Button */} Stop Session ); }