import { View, Image, Text, TouchableOpacity, ActivityIndicator, Alert, } from "react-native"; import { useEffect, useState } from "react"; import { type ImageAsset } from "@/cloudinary/cloudinary"; import { MasonryFlashList } from "@shopify/flash-list"; import { useRouter } from "expo-router"; import { useStore } from "@/store/store"; export default function HomeScreen() { const router = useRouter(); const setSelectedWallpaper = useStore((store) => store.setSelectedWallpaper); const [images, setImages] = useState(null); const [isLoading, setIsLoading] = useState(false); useEffect(() => { async function fetchWallpapers() { try { setIsLoading(true); const res = await fetch( `${process.env.EXPO_PUBLIC_API_URL}/wallpapers`, ); const images: ImageAsset[] = await res.json(); setImages(images); setIsLoading(false); } catch (err) { console.log(err); Alert.alert( "Unable to fetch wallpaper", "Check your internet connection. Otherwise, it's probably our fault.", ); } } fetchWallpapers(); }, []); return ( {isLoading ? ( ) : ( ( Wallpapers )} renderItem={({ item }) => ( { setSelectedWallpaper(item); router.push("/wallpaper"); }} > {item.display_name} )} estimatedItemSize={200} /> )} ); }