diff --git a/app/(tabs)/index.tsx b/app/(tabs)/index.tsx
index 60d0484..5a862f5 100644
--- a/app/(tabs)/index.tsx
+++ b/app/(tabs)/index.tsx
@@ -8,6 +8,7 @@ import {
} from "react-native";
import { useEffect, useState } from "react";
+import { Ionicons } from "@expo/vector-icons";
import { type ImageAsset } from "@/cloudinary/cloudinary";
import { MasonryFlashList } from "@shopify/flash-list";
import { useRouter } from "expo-router";
@@ -20,33 +21,39 @@ export default function HomeScreen() {
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 ? (
+ async function fetchWallpapers() {
+ try {
+ setIsLoading(true);
+ const res = await fetch(`${process.env.EXPO_PUBLIC_API_URL}/wallpapers`);
+ if (res.status !== 200) {
+ throw new Error("server returned error response");
+ }
+ const images: ImageAsset[] = await res.json();
+ setImages(images);
+ } catch (err) {
+ Alert.alert(
+ "Unable to fetch wallpaper",
+ "Check your internet connection. Otherwise, it's probably our fault.",
+ );
+ } finally {
+ setIsLoading(false);
+ }
+ }
+
+ function content() {
+ if (isLoading) {
+ return (
- ) : (
+ );
+ }
+
+ if (images) {
+ return (
- )}
-
- );
+ );
+ }
+
+ return (
+
+ {
+ fetchWallpapers();
+ }}
+ >
+
+
+ Reload
+
+
+
+ );
+ }
+
+ return {content()};
}
diff --git a/app/_layout.tsx b/app/_layout.tsx
index c57d02e..d14572a 100644
--- a/app/_layout.tsx
+++ b/app/_layout.tsx
@@ -3,32 +3,13 @@ import {
DefaultTheme,
ThemeProvider,
} from "@react-navigation/native";
-import { useFonts } from "expo-font";
import { Stack } from "expo-router";
-import * as SplashScreen from "expo-splash-screen";
-import { useEffect } from "react";
import "react-native-reanimated";
import { useColorScheme } from "@/hooks/useColorScheme";
-// Prevent the splash screen from auto-hiding before asset loading is complete.
-SplashScreen.preventAutoHideAsync();
-
export default function RootLayout() {
const colorScheme = useColorScheme();
- const [loaded] = useFonts({
- SpaceMono: require("../assets/fonts/SpaceMono-Regular.ttf"),
- });
-
- useEffect(() => {
- if (loaded) {
- SplashScreen.hideAsync();
- }
- }, [loaded]);
-
- if (!loaded) {
- return null;
- }
return (