Skip to content

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

fix(mobile): bug fix and improvements

daniel31x13fed53fd1879a
diff --git a/apps/mobile/app/_layout.tsx b/apps/mobile/app/_layout.tsx
index ee5869b7..d1e20731 100644
--- a/apps/mobile/app/_layout.tsx
+++ b/apps/mobile/app/_layout.tsx
@@ -1,4 +1,9 @@
-import { Stack, usePathname, useRouter } from "expo-router";
+import {
+ Stack,
+ usePathname,
+ useRootNavigationState,
+ useRouter,
+} from "expo-router";
import { QueryClient } from "@tanstack/react-query";
import { PersistQueryClientProvider } from "@tanstack/react-query-persist-client";
import { mmkvPersister } from "@/lib/queryPersister";
@@ -12,6 +17,7 @@ import { Platform, View } from "react-native";
import { rawTheme, ThemeName } from "@/lib/colors";
import { useShareIntent } from "expo-share-intent";
import useDataStore from "@/store/data";
+import useAuthStore from "@/store/auth";
const queryClient = new QueryClient({
defaultOptions: {
@@ -29,16 +35,21 @@ export default function RootLayout() {
const { colorScheme } = useColorScheme();
const { hasShareIntent, shareIntent, error, resetShareIntent } =
useShareIntent();
- const { updateData } = useDataStore();
+ const { updateData, setData, data } = useDataStore();
const router = useRouter();
const pathname = usePathname();
+ const { setAuth } = useAuthStore();
+ const rootNavState = useRootNavigationState();
+
useEffect(() => {
- const needsRewrite =
- ((typeof pathname === "string" && pathname.startsWith("/dataUrl=")) ||
- hasShareIntent) &&
- pathname !== "/incoming";
+ setAuth();
+ setData();
+ }, []);
+
+ useEffect(() => {
+ if (!rootNavState?.key) return;
if (hasShareIntent && shareIntent.webUrl) {
updateData({
@@ -51,6 +62,11 @@ export default function RootLayout() {
resetShareIntent();
}
+ const needsRewrite =
+ ((typeof pathname === "string" && pathname.startsWith("/dataUrl=")) ||
+ hasShareIntent) &&
+ pathname !== "/incoming";
+
if (needsRewrite) {
router.replace("/incoming");
}
@@ -58,7 +74,13 @@ export default function RootLayout() {
resetShareIntent();
router.replace("/incoming");
}
- }, [hasShareIntent, pathname]);
+ }, [
+ rootNavState?.key,
+ hasShareIntent,
+ pathname,
+ shareIntent?.webUrl,
+ data.shareIntent,
+ ]);
return (
<PersistQueryClientProvider
diff --git a/apps/mobile/app/incoming.tsx b/apps/mobile/app/incoming.tsx
index 5795f39f..463450b4 100644
--- a/apps/mobile/app/incoming.tsx
+++ b/apps/mobile/app/incoming.tsx
@@ -5,6 +5,7 @@ import {
Text,
StyleSheet,
ActivityIndicator,
+ Alert,
} from "react-native";
import { Redirect, useRouter } from "expo-router";
import useAuthStore from "@/store/auth";
@@ -22,26 +23,28 @@ export default function IncomingScreen() {
const { colorScheme } = useColorScheme();
useEffect(() => {
- addLink.mutate(
- { url: data.shareIntent.url },
- {
- onSuccess: () => {
- setTimeout(() => {
- updateData({
- shareIntent: {
- hasShareIntent: false,
- url: "",
- },
- });
- router.replace("/dashboard");
- }, 1000);
- },
- onError: (error) => {
- console.error("Error adding link:", error);
- },
- }
- );
- }, []);
+ if (auth.status === "authenticated" && data.shareIntent.url)
+ addLink.mutate(
+ { url: data.shareIntent.url },
+ {
+ onSuccess: () => {
+ setTimeout(() => {
+ updateData({
+ shareIntent: {
+ hasShareIntent: false,
+ url: "",
+ },
+ });
+ router.replace("/dashboard");
+ }, 1000);
+ },
+ onError: (error) => {
+ Alert.alert("Error", "There was an error adding the link.");
+ console.error("Error adding link:", error);
+ },
+ }
+ );
+ }, [auth, data.shareIntent.url]);
if (auth.status === "unauthenticated") return <Redirect href="/login" />;
diff --git a/apps/mobile/app/index.tsx b/apps/mobile/app/index.tsx
index a38140b6..fdc4ff53 100644
--- a/apps/mobile/app/index.tsx
+++ b/apps/mobile/app/index.tsx
@@ -1,16 +1,8 @@
import useAuthStore from "@/store/auth";
-import useDataStore from "@/store/data";
import { Redirect } from "expo-router";
-import { useEffect } from "react";
export default function HomeScreen() {
- const { setAuth, auth } = useAuthStore();
- const { setData } = useDataStore();
-
- useEffect(() => {
- setAuth();
- setData();
- }, []);
+ const { auth } = useAuthStore();
if (auth.session) {
return <Redirect href="/(tabs)/dashboard" />;
diff --git a/apps/mobile/components/ActionSheets/AddLinkSheet.tsx b/apps/mobile/components/ActionSheets/AddLinkSheet.tsx
index 04571245..572199d7 100644
--- a/apps/mobile/components/ActionSheets/AddLinkSheet.tsx
+++ b/apps/mobile/components/ActionSheets/AddLinkSheet.tsx
@@ -1,4 +1,4 @@
-import { Text, View } from "react-native";
+import { Alert, Text, View } from "react-native";
import { useRef, useState } from "react";
import ActionSheet, { ActionSheetRef } from "react-native-actions-sheet";
import Input from "@/components/ui/Input";
@@ -41,6 +41,7 @@ export default function AddLinkSheet() {
setLink("");
},
onError: (error) => {
+ Alert.alert("Error", "There was an error adding the link.");
console.error("Error adding link:", error);
},
}
diff --git a/apps/mobile/components/ActionSheets/EditLinkSheet.tsx b/apps/mobile/components/ActionSheets/EditLinkSheet.tsx
index ebd9a30e..52770e24 100644
--- a/apps/mobile/components/ActionSheets/EditLinkSheet.tsx
+++ b/apps/mobile/components/ActionSheets/EditLinkSheet.tsx
@@ -1,4 +1,4 @@
-import { View, Text } from "react-native";
+import { View, Text, Alert } from "react-native";
import { useCallback, useEffect, useMemo, useState } from "react";
import ActionSheet, {
FlatList,
@@ -114,7 +114,8 @@ const Main = (props: SheetProps<"edit-link-sheet">) => {
SheetManager.hide("edit-link-sheet");
},
onError: (error) => {
- console.error("Error adding link:", error);
+ Alert.alert("Error", "There was an error editing the link.");
+ console.error("Error editing link:", error);
},
})
}