⚡️⚡️⚡️ 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
mobile: move highlight button into the headerRight
daniel31x1392d1f679f121
diff --git a/apps/mobile/app/_layout.tsx b/apps/mobile/app/_layout.tsxindex d57adbce..e9c6bd1f 100644--- a/apps/mobile/app/_layout.tsx+++ b/apps/mobile/app/_layout.tsx@@ -1,5 +1,4 @@import {- router,Stack,usePathname,useRootNavigationState,@@ -9,37 +8,18 @@ import { PersistQueryClientProvider } from "@tanstack/react-query-persist-clientimport { mmkvPersister } from "@/lib/queryPersister";import { useState, useEffect } from "react";import "../styles/global.css";-import { SheetManager, SheetProvider } from "react-native-actions-sheet";+import { SheetProvider } from "react-native-actions-sheet";import "@/components/ActionSheets/Sheets";import { useColorScheme } from "nativewind";import { lightTheme, darkTheme } from "../lib/theme";-import {- Alert,- Linking,- Platform,- Share,- TouchableOpacity,- View,-} from "react-native";+import { 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";import { KeyboardProvider } from "react-native-keyboard-controller";-import * as DropdownMenu from "zeego/dropdown-menu";-import { Compass, Ellipsis } from "lucide-react-native";-import { Chromium } from "@/components/ui/Icons";-import useTmpStore from "@/store/tmp";-import {- LinkIncludingShortenedCollectionAndTags,- MobileAuth,-} from "@linkwarden/types/global";-import { useDeleteLink, useUpdateLink } from "@linkwarden/router/links";-import { deleteLinkCache } from "@/lib/cache";import { queryClient } from "@/lib/queryClient";-import getOriginalFormat from "@linkwarden/lib/getOriginalFormat";import { StatusBar } from "expo-status-bar";-import { cn } from "@linkwarden/lib/utils";import * as Sentry from "@sentry/react-native";Sentry.init({@@ -50,8 +30,7 @@ Sentry.init({export default Sentry.wrap(function RootLayout() {const [isLoading, setIsLoading] = useState(true);- const { hasShareIntent, shareIntent, error, resetShareIntent } =- useShareIntent();+ const { hasShareIntent, shareIntent, resetShareIntent } = useShareIntent();const { updateData, setData, data } = useDataStore();const router = useRouter();@@ -116,26 +95,13 @@ export default Sentry.wrap(function RootLayout() {queryClient.invalidateQueries();}}>- <RootComponent isLoading={isLoading} auth={auth} />+ <RootComponent isLoading={isLoading} /></PersistQueryClientProvider>);});-const RootComponent = ({- isLoading,- auth,-}: {- isLoading: boolean;- auth: MobileAuth;-}) => {+const RootComponent = ({ isLoading }: { isLoading: boolean }) => {const { colorScheme } = useColorScheme();- const updateLink = useUpdateLink({ auth, Alert });- const deleteLink = useDeleteLink({ auth, Alert });-- const { tmp } = useTmpStore();-- const isIOS26Plus =- Platform.OS === "ios" && parseInt(Platform.Version, 10) >= 26;return (<KeyboardProvider>@@ -171,156 +137,6 @@ const RootComponent = ({? rawTheme["dark"]["base-100"]: "white",},- headerRight: () => (- <View- className={cn("flex-row gap-5", isIOS26Plus && "px-2")}- >- <TouchableOpacity- onPress={() => {- if (tmp.link) {- if (tmp.link.url) {- return Linking.openURL(tmp.link.url);- } else {- const format = getOriginalFormat(tmp.link);-- return Linking.openURL(- format !== null- ? auth.instance +- `/preserved/${tmp.link.id}?format=${format}`- : tmp.link.url || ""- );- }- }- }}- >- {Platform.OS === "ios" ? (- <Compass- size={21}- color={- rawTheme[colorScheme as ThemeName]["base-content"]- }- />- ) : (- <Chromium- stroke={- rawTheme[colorScheme as ThemeName]["base-content"]- }- />- )}- </TouchableOpacity>- <DropdownMenu.Root>- <DropdownMenu.Trigger>- <TouchableOpacity>- <Ellipsis- size={21}- color={- rawTheme[colorScheme as ThemeName][- "base-content"- ]- }- />- </TouchableOpacity>- </DropdownMenu.Trigger>-- <DropdownMenu.Content>- {tmp.link?.url && (- <DropdownMenu.Item- key="share"- onSelect={async () => {- await Share.share({- ...(Platform.OS === "android"- ? { message: tmp.link?.url as string }- : { url: tmp.link?.url as string }),- });- }}- >- <DropdownMenu.ItemTitle>- Share- </DropdownMenu.ItemTitle>- </DropdownMenu.Item>- )}-- {tmp.link && tmp.user && (- <DropdownMenu.Item- key="pin-link"- onSelect={() => {- const isAlreadyPinned =- tmp.link?.pinnedBy && tmp.link.pinnedBy[0]- ? true- : false;- updateLink.mutateAsync({- ...(tmp.link as LinkIncludingShortenedCollectionAndTags),- pinnedBy: (isAlreadyPinned- ? [{ id: undefined }]- : [{ id: tmp.user?.id }]) as any,- });- }}- >- <DropdownMenu.ItemTitle>- {tmp.link.pinnedBy && tmp.link.pinnedBy[0]- ? "Unpin Link"- : "Pin Link"}- </DropdownMenu.ItemTitle>- </DropdownMenu.Item>- )}-- {tmp.link && (- <DropdownMenu.Item- key="edit-link"- onSelect={() => {- SheetManager.show("edit-link-sheet", {- payload: {- link: tmp.link as LinkIncludingShortenedCollectionAndTags,- },- });- }}- >- <DropdownMenu.ItemTitle>- Edit Link- </DropdownMenu.ItemTitle>- </DropdownMenu.Item>- )}-- {tmp.link && (- <DropdownMenu.Item- key="delete-link"- onSelect={() => {- return Alert.alert(- "Delete Link",- "Are you sure you want to delete this link? This action cannot be undone.",- [- {- text: "Cancel",- style: "cancel",- },- {- text: "Delete",- style: "destructive",- onPress: async () => {- deleteLink.mutate(- tmp.link?.id as number- );-- await deleteLinkCache(- tmp.link?.id as number- );-- router.back();- },- },- ]- );- }}- >- <DropdownMenu.ItemTitle>- Delete- </DropdownMenu.ItemTitle>- </DropdownMenu.Item>- )}- </DropdownMenu.Content>- </DropdownMenu.Root>- </View>- ),}}/><Stack.Screen name="login" />diff --git a/apps/mobile/app/links/[id].tsx b/apps/mobile/app/links/[id].tsxindex b3dc29dc..2b11e489 100644--- a/apps/mobile/app/links/[id].tsx+++ b/apps/mobile/app/links/[id].tsx@@ -1,19 +1,30 @@import React, { useCallback, useEffect, useRef, useState } from "react";import {+ Alert,View,ActivityIndicator,Text,+ Linking,Platform,+ Share,TouchableOpacity,} from "react-native";import { WebView } from "react-native-webview";import { useQueryClient } from "@tanstack/react-query";import useAuthStore from "@/store/auth";-import { useFocusEffect, useLocalSearchParams } from "expo-router";+import {+ Stack,+ useFocusEffect,+ useLocalSearchParams,+ useRouter,+} from "expo-router";import { useUser } from "@linkwarden/router/user";-import { useGetLink } from "@linkwarden/router/links";+import { useDeleteLink, useGetLink, useUpdateLink } from "@linkwarden/router/links";import useTmpStore from "@/store/tmp";-import { ArchivedFormat } from "@linkwarden/types/global";+import {+ ArchivedFormat,+ LinkIncludingShortenedCollectionAndTags,+} from "@linkwarden/types/global";import ReadableFormat, {ReadableFormatRef,} from "@/components/Formats/ReadableFormat";@@ -22,13 +33,19 @@ import PdfFormat from "@/components/Formats/PdfFormat";import WebpageFormat from "@/components/Formats/WebpageFormat";import { useSafeAreaInsets } from "react-native-safe-area-context";import { SheetManager } from "react-native-actions-sheet";-import { Highlighter, List } from "lucide-react-native";+import { Compass, Ellipsis, Highlighter } from "lucide-react-native";import { useColorScheme } from "nativewind";import { rawTheme, ThemeName } from "@/lib/colors";+import { Chromium } from "@/components/ui/Icons";+import * as DropdownMenu from "zeego/dropdown-menu";+import { deleteLinkCache } from "@/lib/cache";+import getOriginalFormat from "@linkwarden/lib/getOriginalFormat";+import { cn } from "@linkwarden/lib/utils";export default function LinkScreen() {const { auth } = useAuthStore();const { id, format } = useLocalSearchParams();+ const router = useRouter();const queryClient = useQueryClient();const { data: user } = useUser(auth);const linkId = Number(id);@@ -39,6 +56,10 @@ export default function LinkScreen() {const readableFormatRef = useRef<ReadableFormatRef>(null);const { colorScheme } = useColorScheme();const theme = rawTheme[colorScheme as ThemeName];+ const updateLink = useUpdateLink({ auth, Alert });+ const deleteLink = useDeleteLink({ auth, Alert });+ const isIOS26Plus =+ Platform.OS === "ios" && parseInt(Platform.Version, 10) >= 26;const { data: link, refetch: refetchLink } = useGetLink({id: linkId,@@ -46,7 +67,7 @@ export default function LinkScreen() {enabled: true,});- const { updateTmp } = useTmpStore();+ const { tmp, updateTmp } = useTmpStore();useEffect(() => {if (link?.id && user?.id)@@ -103,11 +124,161 @@ export default function LinkScreen() {}}, [isReadableFormat, link?.id]);+ const renderHeaderRight = useCallback(+ () => (+ <View className={cn("flex-row gap-5", isIOS26Plus && "px-2")}>+ <TouchableOpacity+ onPress={() => {+ if (tmp.link) {+ if (tmp.link.url) {+ return Linking.openURL(tmp.link.url);+ } else {+ const originalFormat = getOriginalFormat(tmp.link);++ return Linking.openURL(+ originalFormat !== null+ ? auth.instance ++ `/preserved/${tmp.link.id}?format=${originalFormat}`+ : tmp.link.url || ""+ );+ }+ }+ }}+ >+ {Platform.OS === "ios" ? (+ <Compass size={21} color={theme["base-content"]} />+ ) : (+ <Chromium stroke={theme["base-content"]} />+ )}+ </TouchableOpacity>+ {isReadableFormat ? (+ <TouchableOpacity+ onPress={() => {+ void handleOpenHighlights();+ }}+ >+ <Highlighter size={21} color={theme["base-content"]} />+ </TouchableOpacity>+ ) : null}+ <DropdownMenu.Root>+ <DropdownMenu.Trigger>+ <TouchableOpacity>+ <Ellipsis size={21} color={theme["base-content"]} />+ </TouchableOpacity>+ </DropdownMenu.Trigger>++ <DropdownMenu.Content>+ {tmp.link?.url && (+ <DropdownMenu.Item+ key="share"+ onSelect={async () => {+ await Share.share({+ ...(Platform.OS === "android"+ ? { message: tmp.link?.url as string }+ : { url: tmp.link?.url as string }),+ });+ }}+ >+ <DropdownMenu.ItemTitle>Share</DropdownMenu.ItemTitle>+ </DropdownMenu.Item>+ )}++ {tmp.link && tmp.user && (+ <DropdownMenu.Item+ key="pin-link"+ onSelect={() => {+ const isAlreadyPinned =+ tmp.link?.pinnedBy && tmp.link.pinnedBy[0] ? true : false;+ updateLink.mutateAsync({+ ...(tmp.link as LinkIncludingShortenedCollectionAndTags),+ pinnedBy: (isAlreadyPinned+ ? [{ id: undefined }]+ : [{ id: tmp.user?.id }]) as any,+ });+ }}+ >+ <DropdownMenu.ItemTitle>+ {tmp.link.pinnedBy && tmp.link.pinnedBy[0]+ ? "Unpin Link"+ : "Pin Link"}+ </DropdownMenu.ItemTitle>+ </DropdownMenu.Item>+ )}++ {tmp.link && (+ <DropdownMenu.Item+ key="edit-link"+ onSelect={() => {+ void SheetManager.show("edit-link-sheet", {+ payload: {+ link: tmp.link as LinkIncludingShortenedCollectionAndTags,+ },+ });+ }}+ >+ <DropdownMenu.ItemTitle>Edit Link</DropdownMenu.ItemTitle>+ </DropdownMenu.Item>+ )}++ {tmp.link && (+ <DropdownMenu.Item+ key="delete-link"+ onSelect={() => {+ return Alert.alert(+ "Delete Link",+ "Are you sure you want to delete this link? This action cannot be undone.",+ [+ {+ text: "Cancel",+ style: "cancel",+ },+ {+ text: "Delete",+ style: "destructive",+ onPress: async () => {+ deleteLink.mutate(tmp.link?.id as number);++ await deleteLinkCache(tmp.link?.id as number);++ router.back();+ },+ },+ ]+ );+ }}+ >+ <DropdownMenu.ItemTitle>Delete</DropdownMenu.ItemTitle>+ </DropdownMenu.Item>+ )}+ </DropdownMenu.Content>+ </DropdownMenu.Root>+ </View>+ ),+ [+ auth.instance,+ deleteLink,+ handleOpenHighlights,+ isIOS26Plus,+ isReadableFormat,+ router,+ theme,+ tmp.link,+ tmp.user,+ updateLink,+ ]+ );+return (<ViewclassName="flex-1"style={{ paddingBottom: Platform.OS === "android" ? insets.bottom : 0 }}>+ <Stack.Screen+ options={{+ headerRight: renderHeaderRight,+ }}+ />+{link?.id && isReadableFormat ? (<ReadableFormatref={readableFormatRef}@@ -150,33 +321,6 @@ export default function LinkScreen() {</View>)}- {link?.id && isReadableFormat ? (- <TouchableOpacity- activeOpacity={0.85}- onPress={() => {- void handleOpenHighlights();- }}- style={{- position: "absolute",- right: 20,- bottom: insets.bottom + 20,- width: 56,- height: 56,- borderRadius: 28,- alignItems: "center",- justifyContent: "center",- backgroundColor: theme.primary,- shadowColor: "#000",- shadowOffset: { width: 0, height: 4 },- shadowOpacity: 0.18,- shadowRadius: 8,- elevation: 5,- }}- >- <Highlighter size={22} color={theme["base-100"]} />- </TouchableOpacity>- ) : null}-{isLoading && (<View className="absolute inset-0 flex-1 justify-center items-center bg-base-100 p-5"><ActivityIndicator size="large" />