Skip to content

⚡️⚡️⚡️ Self-hosted collaborative bookmark manager to collect, read, annotate, and fully preserve what matters, all in one place.

fix(mobile): fix infinite spinner bug + fix android dark mode bug

daniel31x13eccf27425c52
diff --git a/apps/mobile/store/auth.ts b/apps/mobile/store/auth.ts
index b04178f2..c2e7f760 100644
--- a/apps/mobile/store/auth.ts
+++ b/apps/mobile/store/auth.ts
@@ -3,13 +3,10 @@ import * as SecureStore from "expo-secure-store";
import { router } from "expo-router";
import { MobileAuth } from "@linkwarden/types";
import { Alert } from "react-native";
-import * as FileSystem from "expo-file-system";
import { queryClient } from "@/lib/queryClient";
import { mmkvPersister } from "@/lib/queryPersister";
import { clearCache } from "@/lib/cache";
-const CACHE_DIR = FileSystem.documentDirectory + "archivedData/";
-
type AuthStore = {
auth: MobileAuth;
signIn: (
@@ -78,31 +75,42 @@ const useAuthStore = create<AuthStore>((set) => ({
}
});
} else {
- await fetch(instance + "/api/v1/session", {
- method: "POST",
- body: JSON.stringify({ username, password }),
- headers: {
- "Content-Type": "application/json",
- },
- }).then(async (res) => {
+ try {
+ const res = await Promise.race([
+ fetch(`${instance}/api/v1/session`, {
+ method: "POST",
+ body: JSON.stringify({ username, password }),
+ headers: { "Content-Type": "application/json" },
+ }),
+ new Promise<Response>((_, reject) =>
+ setTimeout(() => reject(new Error("TIMEOUT")), 30000)
+ ),
+ ]);
+
if (res.ok) {
const data = await res.json();
const session = (data as any).response.token;
+
await SecureStore.setItemAsync("TOKEN", session);
await SecureStore.setItemAsync("INSTANCE", instance);
- set({
- auth: {
- session,
- instance,
- status: "authenticated",
- },
- });
-
+ set({ auth: { session, instance, status: "authenticated" } });
router.replace("/(tabs)/dashboard");
} else {
Alert.alert("Error", "Invalid credentials");
}
- });
+ } catch (err: any) {
+ if (err?.message === "TIMEOUT") {
+ Alert.alert(
+ "Request timed out",
+ "Unable to reach the server in time. Please check your network configuration and try again."
+ );
+ } else {
+ Alert.alert(
+ "Network error",
+ "Could not connect to the server. Please check your network configuration and try again."
+ );
+ }
+ }
}
},
signOut: async () => {
diff --git a/apps/mobile/store/data.ts b/apps/mobile/store/data.ts
index b3a59065..c9ba3ac0 100644
--- a/apps/mobile/store/data.ts
+++ b/apps/mobile/store/data.ts
@@ -15,13 +15,13 @@ const useDataStore = create<DataStore>((set, get) => ({
hasShareIntent: false,
url: "",
},
- theme: "light",
+ theme: "system",
preferredBrowser: "app",
},
setData: async () => {
const dataString = JSON.parse((await AsyncStorage.getItem("data")) || "{}");
- colorScheme.set(dataString.theme || "light");
+ colorScheme.set(dataString.theme || "system");
if (dataString)
set((state) => ({ data: { ...state.data, ...dataString } }));