diff --git a/app/(tabs)/home.tsx b/app/(tabs)/home.tsx index e9d9502..9c4ede2 100644 --- a/app/(tabs)/home.tsx +++ b/app/(tabs)/home.tsx @@ -61,44 +61,48 @@ const navigateToFoodDetail = (foodId: string) => { router.push({ pathname: "/recipe-detail", params: { id: foodId } }); }; -const handleImageSelection = async ( - pickerFn: - | typeof ImagePicker.launchCameraAsync - | typeof ImagePicker.launchImageLibraryAsync -) => { - const result = await pickerFn({ - mediaTypes: ["images"], - allowsEditing: true, - aspect: [1, 1], - quality: 1, - }); - - if (!result.canceled) { - try { - const { data, error } = await supabase.auth.getUser(); - if (error || !data?.user?.id) throw new Error("Cannot get user id"); - const userId = data.user.id; - await processImage(result.assets[0], userId); - } catch (err) { - Alert.alert( - "Image Processing Failed", - (err as Error).message || "Unknown error" - ); - } - router.push({ - pathname: "/recipe-detail", - params: { - title: "My New Recipe", - image: result.assets[0].uri, - }, - }); - } -}; - export default function HomeScreen() { + const [imageProcessing, setImageProcessing] = useState(false); const [searchQuery, setSearchQuery] = useState(""); const { data: foodsData = [], isLoading, error } = useFoodsQuery(); + const handleImageSelection = async ( + pickerFn: + | typeof ImagePicker.launchCameraAsync + | typeof ImagePicker.launchImageLibraryAsync + ) => { + const result = await pickerFn({ + mediaTypes: ["images"], + allowsEditing: true, + aspect: [1, 1], + quality: 1, + }); + + if (!result.canceled) { + setImageProcessing(true); + try { + const { data, error } = await supabase.auth.getUser(); + if (error || !data?.user?.id) throw new Error("Cannot get user id"); + const userId = data.user.id; + await processImage(result.assets[0], userId); + } catch (err) { + Alert.alert( + "Image Processing Failed", + (err as Error).message || "Unknown error" + ); + } finally { + setImageProcessing(false); + } + router.push({ + pathname: "/recipe-detail", + params: { + title: "My New Recipe", + image: result.assets[0].uri, + }, + }); + } + }; + const filteredFoods = useMemo(() => { return searchQuery ? foodsData.filter((food) => @@ -110,6 +114,45 @@ export default function HomeScreen() { return ( + {imageProcessing && ( + + + + Processing image... + + + + + Please wait + + + )} Hi! Mr. Chef