diff --git a/app/cooking/[id].tsx b/app/cooking/[id].tsx index 46c1fa6..ea58e57 100644 --- a/app/cooking/[id].tsx +++ b/app/cooking/[id].tsx @@ -1,68 +1,75 @@ "use client"; import { IconSymbol } from "@/components/ui/IconSymbol"; -import { Image } from "expo-image"; +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, - StyleSheet, - Text, - TouchableOpacity, - View, -} from "react-native"; +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 } = useLocalSearchParams(); + const { id: foodId } = useLocalSearchParams(); const [currentStep, setCurrentStep] = useState(0); - // Mock data - in a real app, you would fetch this based on the ID - const recipeData = { - id: 1, - name: "Pad Kra Pao Moo Sab with Eggs", - steps: [ - { - title: "Gather and prepare all ingredients", - description: - "Chop garlic, Thai chilies, and protein of choice (chicken, pork, beef, or tofu)", - image: require("@/assets/images/cooking/step1.png"), - }, - { - title: "Heat oil in a wok or large frying pan", - description: - "Use medium-high heat. The oil should be hot but not smoking.", - image: require("@/assets/images/cooking/step2.png"), - }, - { - title: "Fry the eggs sunny side up", - description: - "Heat oil in a separate pan and fry eggs until whites are set but yolks are still runny. Set aside.", - image: require("@/assets/images/cooking/step3.png"), - }, - { - title: "Stir-fry garlic and chilies", - description: - "Add chopped garlic and chilies to the hot oil and stir-fry until fragrant, about 30 seconds.", - image: require("@/assets/images/cooking/step4.png"), - }, - { - title: "Add ground pork and cook until browned", - description: - "Break up the meat with a spatula and cook until no longer pink, about 3-4 minutes.", - image: require("@/assets/images/cooking/step5.png"), - }, - { - title: "Add sauces and basil", - description: - "Add soy sauce, oyster sauce, sugar, and holy basil. Stir well and cook for another minute. Serve with rice and top with the fried egg.", - image: require("@/assets/images/cooking/step6.png"), - }, - ], - }; + 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, + }); - const totalSteps = recipeData.steps.length; + if (stepsLoading) { + return ( + + + Loading... + + + ); + } + + if (stepsError) { + return ( + + + Error loading steps + + + ); + } + + const totalSteps = steps?.length || 0; const goToNextStep = () => { if (currentStep < totalSteps - 1) { @@ -76,24 +83,6 @@ export default function CookingSessionScreen() { } }; - const getHelpWithStep = () => { - Alert.alert( - "Need Help?", - `Tips for ${recipeData.steps[currentStep].title}:\n\n` + - "• Make sure ingredients are properly prepared\n" + - "• Watch your heat level\n" + - "• Don't overcook the ingredients\n\n" + - "Would you like to see a video tutorial?", - [ - { text: "No, thanks", style: "cancel" }, - { - text: "Yes, show video", - onPress: () => console.log("Show video tutorial"), - }, - ] - ); - }; - const stopCookingSession = () => { Alert.alert( "Stop Cooking?", @@ -104,14 +93,31 @@ export default function CookingSessionScreen() { ] ); }; + if (!steps || steps.length === 0) { + return ( + + + No steps found + router.back()} + > + + Go back to home page + + + + + ); + } return ( - - + + {/* Header with back button */} - + router.back()} > @@ -119,78 +125,77 @@ export default function CookingSessionScreen() { {/* 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} - - {recipeData.steps[currentStep].title} + + {steps && steps[currentStep]?.title} - - {recipeData.steps[currentStep].description} + + {steps && steps[currentStep]?.description} {/* Step Indicators */} - - Steps - - {recipeData.steps.map((_, index) => ( - setCurrentStep(index)} - > - - - ))} + + Steps + + {steps && + steps.map((_: any, index: any) => ( + setCurrentStep(index)} + > + + + ))} {/* Navigation Buttons */} - - - Help me! - - - + + {currentStep > 0 && ( - Previous + + Previous + )} {currentStep < totalSteps - 1 ? ( - Next Step + + Next Step + ) : ( router.back()} > - Finish + + Finish + )} @@ -199,165 +204,15 @@ export default function CookingSessionScreen() { {/* Stop Session Button */} - - Stop Session + + + Stop Session + ); } - -const styles = StyleSheet.create({ - container: { - flex: 1, - backgroundColor: "#FFFFFF", - }, - scrollView: { - flex: 1, - }, - header: { - paddingHorizontal: 16, - paddingVertical: 12, - }, - backButton: { - width: 40, - height: 40, - borderRadius: 20, - backgroundColor: "#FFCC00", - justifyContent: "center", - alignItems: "center", - }, - illustrationContainer: { - alignItems: "center", - marginVertical: 20, - }, - stepImage: { - width: 200, - height: 200, - borderRadius: 100, - backgroundColor: "#FFCC00", - }, - stepInfoContainer: { - paddingHorizontal: 24, - alignItems: "center", - marginBottom: 30, - }, - stepCounter: { - fontSize: 18, - color: "#8BC34A", - fontWeight: "bold", - marginBottom: 8, - }, - stepTitle: { - fontSize: 24, - fontWeight: "bold", - color: "#333333", - textAlign: "center", - marginBottom: 12, - }, - stepDescription: { - fontSize: 16, - color: "#666666", - textAlign: "center", - lineHeight: 24, - }, - stepIndicatorsContainer: { - paddingHorizontal: 24, - marginBottom: 24, - }, - stepsLabel: { - fontSize: 18, - fontWeight: "bold", - color: "#333333", - marginBottom: 12, - }, - stepDots: { - flexDirection: "row", - justifyContent: "center", - }, - stepDot: { - width: 40, - height: 40, - borderRadius: 20, - backgroundColor: "#EEEEEE", - marginHorizontal: 8, - }, - activeStepDot: { - backgroundColor: "#FFCC00", - }, - navigationContainer: { - paddingHorizontal: 24, - marginBottom: 80, - }, - helpButton: { - backgroundColor: "#FF6B6B", - borderRadius: 8, - paddingVertical: 16, - alignItems: "center", - marginBottom: 16, - }, - helpButtonText: { - fontSize: 18, - fontWeight: "bold", - color: "#FFFFFF", - }, - stepNavigation: { - flexDirection: "row", - justifyContent: "space-between", - }, - navButton: { - flex: 1, - flexDirection: "row", - alignItems: "center", - justifyContent: "center", - paddingVertical: 16, - borderRadius: 8, - }, - prevButton: { - backgroundColor: "#FFFFFF", - borderWidth: 1, - borderColor: "#DDDDDD", - marginRight: 8, - }, - prevButtonText: { - fontSize: 16, - fontWeight: "bold", - color: "#333333", - marginLeft: 8, - }, - nextButton: { - backgroundColor: "#FFCC00", - }, - nextButtonText: { - fontSize: 16, - fontWeight: "bold", - color: "#333333", - marginRight: 8, - }, - finishButton: { - backgroundColor: "#4CAF50", - }, - finishButtonText: { - fontSize: 16, - fontWeight: "bold", - color: "#FFFFFF", - marginRight: 8, - }, - stopButton: { - position: "absolute", - bottom: 0, - left: 0, - right: 0, - backgroundColor: "#C62828", - flexDirection: "row", - justifyContent: "center", - alignItems: "center", - paddingVertical: 16, - }, - stopButtonText: { - fontSize: 18, - fontWeight: "bold", - color: "#FFCC00", - marginRight: 8, - }, -});