⚡️⚡️⚡️ Self-hosted collaborative bookmark manager to collect, read, annotate, and fully preserve what matters, all in one place.
TypeScript bookmarkbookmark-managercollaborationnextjsreact-nativeread-it-laterself-hostedtypescript
feat(mobile): add share sheet page
daniel31x13915395881160
diff --git a/apps/mobile/app/_layout.tsx b/apps/mobile/app/_layout.tsxindex 71291e9b..1b94f261 100644--- a/apps/mobile/app/_layout.tsx+++ b/apps/mobile/app/_layout.tsx@@ -1,4 +1,4 @@-import { Stack } from "expo-router";+import { Stack, usePathname, useRouter } from "expo-router";import { QueryClient } from "@tanstack/react-query";import { PersistQueryClientProvider } from "@tanstack/react-query-persist-client";import { mmkvPersister } from "@/lib/queryPersister";@@ -11,11 +11,12 @@ import { lightTheme, darkTheme } from "../lib/theme";import { Platform, View } from "react-native";import { rawTheme, ThemeName } from "@/lib/colors";import { useShareIntent } from "expo-share-intent";+import useDataStore from "@/store/data";const queryClient = new QueryClient({defaultOptions: {queries: {- staleTime: 1000 * 60 * 60 * 24, // never refetch for 24h+ staleTime: 1000 * 60 * 60 * 24,refetchOnMount: true,refetchOnWindowFocus: false,refetchOnReconnect: false,@@ -26,16 +27,38 @@ const queryClient = new QueryClient({export default function RootLayout() {const [isLoading, setIsLoading] = useState(true);const { colorScheme } = useColorScheme();- const { hasShareIntent, shareIntent, resetShareIntent, error } =+ const { hasShareIntent, shareIntent, error, resetShareIntent } =useShareIntent();+ const { updateData } = useDataStore();++ const router = useRouter();+ const pathname = usePathname();useEffect(() => {+ const needsRewrite =+ ((typeof pathname === "string" && pathname.startsWith("/dataUrl=")) ||+ hasShareIntent) &&+ pathname !== "/incoming";++ if (hasShareIntent && shareIntent.webUrl) {+ updateData({+ shareIntent: {+ hasShareIntent: true,+ url: shareIntent.webUrl || "",+ },+ });++ resetShareIntent();+ }++ if (needsRewrite) {+ router.replace("/incoming");+ }if (hasShareIntent) {- // Handle the share intent- console.log("Received share intent:", shareIntent);resetShareIntent();+ router.replace("/incoming");}- }, [hasShareIntent, shareIntent, resetShareIntent]);+ }, [hasShareIntent, pathname]);return (<PersistQueryClientProviderdiff --git a/apps/mobile/app/incoming.tsx b/apps/mobile/app/incoming.tsxnew file mode 100644index 00000000..d1a3b776--- /dev/null+++ b/apps/mobile/app/incoming.tsx@@ -0,0 +1,81 @@+import React, { useEffect, useState } from "react";+import {+ SafeAreaView,+ View,+ Text,+ StyleSheet,+ ActivityIndicator,+} from "react-native";+import { useRouter } from "expo-router";+import useAuthStore from "@/store/auth";+import useDataStore from "@/store/data";+import { Check } from "lucide-react-native";++export default function IncomingScreen() {+ const { auth } = useAuthStore();+ const router = useRouter();+ const { data, updateData } = useDataStore();++ useEffect(() => {+ if (auth.status === "unauthenticated") {+ router.replace("/login");+ return;+ }+ }, []);++ useEffect(() => {+ let timeout = setTimeout(() => {+ updateData({+ shareIntent: {+ hasShareIntent: false,+ url: "",+ },+ });+ router.replace("/dashboard");+ }, 3000);+ return () => clearTimeout(timeout);+ }, []);++ return (+ <SafeAreaView style={styles.container}>+ <Text style={styles.subtitle}>{String(data?.shareIntent.url)}</Text>+ {auth.status !== "unauthenticated" && data?.shareIntent.url ? (+ <View style={styles.center}>+ <Check size={140} style={styles.check} />+ <Text style={styles.title}>Link Saved!</Text>+ </View>+ ) : (+ <View style={styles.center}>+ <ActivityIndicator size="large" />+ <Text style={styles.subtitle}>+ One sec… {String(data?.shareIntent.url)}+ </Text>+ </View>+ )}+ </SafeAreaView>+ );+}++const styles = StyleSheet.create({+ container: {+ flex: 1,+ backgroundColor: "#fff",+ },+ center: {+ flex: 1,+ alignItems: "center",+ justifyContent: "center",+ },+ check: {+ marginBottom: 12,+ },+ title: {+ fontSize: 28,+ fontWeight: "600",+ },+ subtitle: {+ marginTop: 12,+ fontSize: 16,+ opacity: 0.7,+ },+});diff --git a/apps/mobile/app/login.tsx b/apps/mobile/app/login.tsxindex 5a33cbe6..13f50900 100644--- a/apps/mobile/app/login.tsx+++ b/apps/mobile/app/login.tsx@@ -1,17 +1,22 @@import { Button } from "@/components/ui/Button";import Input from "@/components/ui/Input";import useAuthStore from "@/store/auth";+import { Redirect } from "expo-router";import { useState } from "react";-import { View, Text, StyleSheet, TouchableOpacity } from "react-native";+import { View, Text, StyleSheet } from "react-native";export default function HomeScreen() {- const { signIn } = useAuthStore();+ const { auth, signIn } = useAuthStore();const [form, setForm] = useState({user: "",password: "",instance: "",});+ if (auth.status === "authenticated") {+ return <Redirect href="/dashboard" />;+ }+return (<View style={styles.container}><Text className="text-base-content">Login</Text>diff --git a/apps/mobile/store/data.ts b/apps/mobile/store/data.tsnew file mode 100644index 00000000..5b5cc96c--- /dev/null+++ b/apps/mobile/store/data.ts@@ -0,0 +1,26 @@+import { create } from "zustand";+import { MobileData } from "@linkwarden/types";++type DataStore = {+ data: MobileData;+ updateData: (newData: Partial<MobileData>) => void;+};++const useDataStore = create<DataStore>((set) => ({+ data: {+ shareIntent: {+ hasShareIntent: false,+ url: "",+ },+ },+ updateData: (newData) => {+ set((state) => ({+ data: {+ ...state.data,+ ...newData,+ },+ }));+ },+}));++export default useDataStore;diff --git a/packages/types/global.ts b/packages/types/global.tsindex a95b064c..ecc4478f 100644--- a/packages/types/global.ts+++ b/packages/types/global.ts@@ -179,3 +179,10 @@ export interface MobileAuth {session: string | null;instance: string | null;}++export interface MobileData {+ shareIntent: {+ hasShareIntent: boolean;+ url: string;+ };+}