"use client"; import RecipeHighlightCard from "@/components/RecipeHighlightCard"; import { supabase } from "@/services/supabase"; import { useQuery } from "@tanstack/react-query"; import { router } from "expo-router"; import { ActivityIndicator, ScrollView, Text, View } from "react-native"; import { SafeAreaView } from "react-native-safe-area-context"; interface Recipe { id: number; name: string; description: string; image_url: string; created_by: string; is_shared: boolean; time_to_cook_minutes?: number; } export default function RecipesScreen() { const { data: allRecipes, isLoading: isAllLoading, error: allError, } = useQuery({ queryKey: ["all-recipes"], queryFn: async () => { const { data, error } = await supabase .from("foods") .select("*") .eq("is_shared", true) .order("created_at", { ascending: false }); if (error) throw error; return data ?? []; }, staleTime: 1000 * 60, }); const recipes: Recipe[] = allRecipes || []; const loading = isAllLoading; const error = allError; if (loading) { return ( ); } if (error) { return ( Failed to load recipes ); } return ( All Recipes {recipes.length === 0 ? ( No recipes found. ) : ( recipes.map((item, idx) => ( { router.push(`/food/${item.id}`); }} /> )) )} ); }