aboutsummaryrefslogtreecommitdiffstats
path: root/packages/mobile/app
diff options
context:
space:
mode:
authorMohamedBassem <me@mbassem.com>2024-03-13 16:51:42 +0000
committerMohamedBassem <me@mbassem.com>2024-03-13 16:51:42 +0000
commit61e852d963fb04b13b7bda39830e208a648b3545 (patch)
treeb24462270a245ea2cef3ee15ede56c7b22aec927 /packages/mobile/app
parenta80869cee9e841c319e603a51daa9cd34d1e83e8 (diff)
downloadkarakeep-61e852d963fb04b13b7bda39830e208a648b3545.tar.zst
fix(mobile): Multiple attempts to stop the duplication sharing
Diffstat (limited to 'packages/mobile/app')
-rw-r--r--packages/mobile/app/_layout.tsx10
-rw-r--r--packages/mobile/app/sharing.tsx8
2 files changed, 15 insertions, 3 deletions
diff --git a/packages/mobile/app/_layout.tsx b/packages/mobile/app/_layout.tsx
index 561e911e..c4298ec4 100644
--- a/packages/mobile/app/_layout.tsx
+++ b/packages/mobile/app/_layout.tsx
@@ -9,16 +9,22 @@ import { useEffect } from "react";
import { View } from "react-native";
import { Providers } from "@/lib/providers";
+import { useLastSharedIntent } from "@/lib/last-shared-intent";
export default function RootLayout() {
const router = useRouter();
const { hasShareIntent, shareIntent, resetShareIntent } = useShareIntent();
+ const lastSharedIntent = useLastSharedIntent();
+
useEffect(() => {
- if (hasShareIntent) {
+ const intentJson = JSON.stringify(shareIntent);
+ if (hasShareIntent && !lastSharedIntent.isPreviouslyShared(intentJson)) {
+ // TODO: Remove once https://github.com/achorein/expo-share-intent/issues/14 is fixed
+ lastSharedIntent.setIntent(intentJson);
router.replace({
pathname: "sharing",
- params: { shareIntent: JSON.stringify(shareIntent) },
+ params: { shareIntent: intentJson },
});
resetShareIntent();
}
diff --git a/packages/mobile/app/sharing.tsx b/packages/mobile/app/sharing.tsx
index 59c6fc25..64bbd933 100644
--- a/packages/mobile/app/sharing.tsx
+++ b/packages/mobile/app/sharing.tsx
@@ -1,5 +1,5 @@
import { Link, useLocalSearchParams, useRouter } from "expo-router";
-import { ShareIntent } from "expo-share-intent";
+import { ShareIntent, useShareIntent } from "expo-share-intent";
import { useEffect, useMemo, useState } from "react";
import { View, Text } from "react-native";
import { z } from "zod";
@@ -12,6 +12,9 @@ type Mode =
| { type: "error" };
function SaveBookmark({ setMode }: { setMode: (mode: Mode) => void }) {
+ // Desperate attempt to fix sharing duplication
+ const { hasShareIntent, resetShareIntent } = useShareIntent();
+
const params = useLocalSearchParams();
const shareIntent = useMemo(() => {
@@ -36,6 +39,9 @@ function SaveBookmark({ setMode }: { setMode: (mode: Mode) => void }) {
mutate({ type: "text", text: shareIntent.text });
}
}
+ if (hasShareIntent) {
+ resetShareIntent();
+ }
}, []);
const { mutate, isPending } = api.bookmarks.createBookmark.useMutation({