⚡️⚡️⚡️ 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
chore(mobile): implement sheet manager
daniel31x133de6e9965a45
diff --git a/apps/mobile/app/(tabs)/dashboard.tsx b/apps/mobile/app/(tabs)/dashboard.tsxindex f7f1057b..bd5bdf5e 100644--- a/apps/mobile/app/(tabs)/dashboard.tsx+++ b/apps/mobile/app/(tabs)/dashboard.tsx@@ -1,21 +1,10 @@-import { Text, TouchableOpacity, View } from "react-native";+import { Text, TouchableOpacity } from "react-native";import { IconSymbol } from "@/components/ui/IconSymbol";import * as DropdownMenu from "zeego/dropdown-menu";import { SafeAreaView } from "react-native-safe-area-context";-import { useRef, useState } from "react";-// import AddLink from "@/components/Modals/AddLink";-import ActionSheet, { ActionSheetRef } from "react-native-actions-sheet";-import Input from "@/components/ui/Input";-import { Button } from "@/components/ui/Button";-import { useAddLink } from "@linkwarden/router/links";-import useAuthStore from "@/store/auth";+import { SheetManager } from "react-native-actions-sheet";export default function DashboardScreen() {- const actionSheetRef = useRef<ActionSheetRef>(null);- const { auth } = useAuthStore();- const addLink = useAddLink(auth);- const [link, setLink] = useState("");-return (<SafeAreaView className="flex-1 justify-center items-center"><DropdownMenu.Root>@@ -28,7 +17,7 @@ export default function DashboardScreen() {<DropdownMenu.Content><DropdownMenu.Itemkey="new-link"- onSelect={() => actionSheetRef.current?.show()}+ onSelect={() => SheetManager.show("add-link-sheet")}><DropdownMenu.ItemTitle>New Link</DropdownMenu.ItemTitle></DropdownMenu.Item>@@ -50,49 +39,6 @@ export default function DashboardScreen() {{/* <TouchableOpacity><IconSymbol size={20} name="plus" color={""} /></TouchableOpacity> */}- <ActionSheet ref={actionSheetRef} gestureEnabled>- <View className="px-8 py-5">- <Input- placeholder="e.g. https://example.com"- className="mb-4"- value={link}- onChangeText={setLink}- />-- <Button- onPress={() =>- addLink.mutate(- { url: link },- {- onSuccess: () => {- actionSheetRef.current?.hide();- setLink("");- },- onError: (error) => {- console.error("Error adding link:", error);- },- }- )- }- variant="accent"- className="mb-2"- >- Save to Linkwarden- </Button>-- <Button- onPress={() => {- actionSheetRef.current?.hide();- setLink("");- }}- variant="outline"- className="mb-2"- >- Cancel- </Button>- </View>- </ActionSheet>- {/* <AddLink isVisible={modalOpen} onClose={() => setModalOpen(false)} /> */}</SafeAreaView>);}diff --git a/apps/mobile/app/_layout.tsx b/apps/mobile/app/_layout.tsxindex 5205bd1a..5d0d509b 100644--- a/apps/mobile/app/_layout.tsx+++ b/apps/mobile/app/_layout.tsx@@ -4,6 +4,8 @@ import { PersistQueryClientProvider } from "@tanstack/react-query-persist-clientimport { mmkvPersister } from "@/lib/queryPersister";import { useState } from "react";import "../styles/global.css";+import { SheetProvider } from "react-native-actions-sheet";+import "@/components/ActionSheets/Sheets";const queryClient = new QueryClient({defaultOptions: {@@ -28,25 +30,27 @@ export default function RootLayout() {}}onSuccess={() => setIsLoading(false)}>- {!isLoading && (- <Stack- screenOptions={{- headerShown: false,- }}- >- {/* <Stack.Screen name="(tabs)" /> */}- <Stack.Screen- name="links/[id]"- options={{- headerBackTitle: "Back",- headerShown: true,- headerTitle: "",+ <SheetProvider>+ {!isLoading && (+ <Stack+ screenOptions={{+ headerShown: false,}}- />- <Stack.Screen name="login" />- <Stack.Screen name="+not-found" />- </Stack>- )}+ >+ {/* <Stack.Screen name="(tabs)" /> */}+ <Stack.Screen+ name="links/[id]"+ options={{+ headerBackTitle: "Back",+ headerShown: true,+ headerTitle: "",+ }}+ />+ <Stack.Screen name="login" />+ <Stack.Screen name="+not-found" />+ </Stack>+ )}+ </SheetProvider></PersistQueryClientProvider>);}diff --git a/apps/mobile/components/ActionSheets/AddLinkSheet.tsx b/apps/mobile/components/ActionSheets/AddLinkSheet.tsxnew file mode 100644index 00000000..a664730b--- /dev/null+++ b/apps/mobile/components/ActionSheets/AddLinkSheet.tsx@@ -0,0 +1,59 @@+import { View } from "react-native";+import { useRef, useState } from "react";+import ActionSheet, { ActionSheetRef } from "react-native-actions-sheet";+import Input from "@/components/ui/Input";+import { Button } from "@/components/ui/Button";+import { useAddLink } from "@linkwarden/router/links";+import useAuthStore from "@/store/auth";++export default function AddLinkSheet() {+ const actionSheetRef = useRef<ActionSheetRef>(null);+ const { auth } = useAuthStore();+ const addLink = useAddLink(auth);+ const [link, setLink] = useState("");++ return (+ <ActionSheet ref={actionSheetRef} gestureEnabled>+ <View className="px-8 py-5">+ <Input+ placeholder="e.g. https://example.com"+ className="mb-4"+ value={link}+ onChangeText={setLink}+ />++ <Button+ onPress={() =>+ addLink.mutate(+ { url: link },+ {+ onSuccess: () => {+ actionSheetRef.current?.hide();+ setLink("");+ },+ onError: (error) => {+ console.error("Error adding link:", error);+ },+ }+ )+ }+ variant="accent"+ className="mb-2"+ >+ Save to Linkwarden+ </Button>++ <Button+ onPress={() => {+ actionSheetRef.current?.hide();+ setLink("");+ }}+ variant="outline"+ className="mb-2"+ >+ Cancel+ </Button>+ </View>+ </ActionSheet>+ );+}diff --git a/apps/mobile/components/ActionSheets/EditLinkSheet.tsx b/apps/mobile/components/ActionSheets/EditLinkSheet.tsxnew file mode 100644index 00000000..445fb31b--- /dev/null+++ b/apps/mobile/components/ActionSheets/EditLinkSheet.tsx@@ -0,0 +1,64 @@+import { View, Text } from "react-native";+import { useRef, useState } from "react";+import ActionSheet, {+ ActionSheetRef,+ SheetProps,+} from "react-native-actions-sheet";+import Input from "@/components/ui/Input";+import { Button } from "@/components/ui/Button";+import { useAddLink } from "@linkwarden/router/links";+import useAuthStore from "@/store/auth";++export default function EditLinkSheet(props: SheetProps<"edit-link-sheet">) {+ const actionSheetRef = useRef<ActionSheetRef>(null);+ const { auth } = useAuthStore();+ const addLink = useAddLink(auth);+ const [link, setLink] = useState("");++ return (+ <ActionSheet ref={actionSheetRef} gestureEnabled>+ <View className="px-8 py-5">+ <Input+ placeholder="e.g. https://example.com"+ className="mb-4"+ value={link}+ onChangeText={setLink}+ />++ <Text>{props.payload?.id}</Text>++ <Button+ onPress={() =>+ addLink.mutate(+ { url: link },+ {+ onSuccess: () => {+ actionSheetRef.current?.hide();+ setLink("");+ },+ onError: (error) => {+ console.error("Error adding link:", error);+ },+ }+ )+ }+ variant="accent"+ className="mb-2"+ >+ Save to Linkwarden+ </Button>++ <Button+ onPress={() => {+ actionSheetRef.current?.hide();+ setLink("");+ }}+ variant="outline"+ className="mb-2"+ >+ Cancel+ </Button>+ </View>+ </ActionSheet>+ );+}diff --git a/apps/mobile/components/ActionSheets/Sheets.tsx b/apps/mobile/components/ActionSheets/Sheets.tsxnew file mode 100644index 00000000..a977888b--- /dev/null+++ b/apps/mobile/components/ActionSheets/Sheets.tsx@@ -0,0 +1,29 @@+import {+ registerSheet,+ RouteDefinition,+ SheetDefinition,+} from "react-native-actions-sheet";+import AddLinkSheet from "./AddLinkSheet";+import EditLinkSheet from "./EditLinkSheet";++registerSheet("add-link-sheet", AddLinkSheet);+registerSheet("edit-link-sheet", EditLinkSheet);++declare module "react-native-actions-sheet" {+ interface Sheets {+ "add-link-sheet": SheetDefinition;+ "edit-link-sheet": SheetDefinition<{+ payload: {+ id: number;+ };+ // routes: {+ // main: RouteDefinition;+ // collections: RouteDefinition<{+ // data: string;+ // }>;+ // };+ }>;+ }+}++export {};diff --git a/apps/mobile/components/LinkListing.tsx b/apps/mobile/components/LinkListing.tsxindex 6072a0c9..e262fec2 100644--- a/apps/mobile/components/LinkListing.tsx+++ b/apps/mobile/components/LinkListing.tsx@@ -11,6 +11,7 @@ import useAuthStore from "@/store/auth";import { useRouter } from "expo-router";import * as ContextMenu from "zeego/context-menu";import { useDeleteLink } from "@linkwarden/router/links";+import { SheetManager } from "react-native-actions-sheet";type Props = {link: LinkIncludingShortenedCollectionAndTags;@@ -109,6 +110,28 @@ const LinkListing = ({ link }: Props) => {<ContextMenu.ItemTitle>Open Link</ContextMenu.ItemTitle></ContextMenu.Item>+ {link.url && (+ <ContextMenu.Item+ key="copy-url"+ onSelect={() => {+ /* copy URL */+ }}+ >+ <ContextMenu.ItemTitle>Copy URL</ContextMenu.ItemTitle>+ </ContextMenu.Item>+ )}++ <ContextMenu.Item+ key="edit-link"+ onSelect={() => {+ SheetManager.show("edit-link-sheet", {+ payload: { id: link.id as number },+ });+ }}+ >+ <ContextMenu.ItemTitle>Edit Link</ContextMenu.ItemTitle>+ </ContextMenu.Item>+{link.url && atLeastOneFormatAvailable(link) && (<ContextMenu.Sub><ContextMenu.SubTrigger key="preserved-formats">@@ -171,14 +194,6 @@ const LinkListing = ({ link }: Props) => {</ContextMenu.Sub>)}- <ContextMenu.Item- key="copy-url"- onSelect={() => {- /* copy URL */- }}- >- <ContextMenu.ItemTitle>Copy URL</ContextMenu.ItemTitle>- </ContextMenu.Item><ContextMenu.Itemkey="delete-link"onSelect={() => {diff --git a/packages/router/user.tsx b/packages/router/user.tsxindex 0bb1723f..82db1780 100644--- a/packages/router/user.tsx+++ b/packages/router/user.tsx@@ -112,7 +112,7 @@ const useUpdateUserPreference = () => {return useMutation({mutationFn: async (preference: UpdateUserPreferenceSchemaType) => {const response = await fetch(- `/api/v1/users/${session?.user.id}/preference`,+ `/api/v1/users/${(session?.user as any)?.id}/preference`,{method: "PUT",headers: { "Content-Type": "application/json" },