Skip to content

A self-hostable bookmark-everything app (links, notes and images) with AI-based automatic tagging and full text search

feat(mobile): add archive,fav,share and highlights to info page

Mohamed Bassemc32b7f993dec
diff --git a/apps/mobile/app/dashboard/_layout.tsx b/apps/mobile/app/dashboard/_layout.tsx
index 95969cc7..609f04a0 100644
--- a/apps/mobile/app/dashboard/_layout.tsx
+++ b/apps/mobile/app/dashboard/_layout.tsx
@@ -124,6 +124,19 @@ export default function Dashboard() {
sheetGrabberVisible: true,
}}
/>
+ <Stack.Screen
+ name="bookmarks/[slug]/highlights"
+ options={{
+ headerTitle: "Highlights",
+ headerTransparent: false,
+ headerLargeTitle: false,
+ presentation: Platform.select({
+ ios: "formSheet" as const,
+ default: "modal" as const,
+ }),
+ sheetGrabberVisible: true,
+ }}
+ />
<Stack.Screen
name="lists/new"
options={{
diff --git a/apps/mobile/app/dashboard/bookmarks/[slug]/highlights.tsx b/apps/mobile/app/dashboard/bookmarks/[slug]/highlights.tsx
new file mode 100644
index 00000000..6a01e110
--- /dev/null
+++ b/apps/mobile/app/dashboard/bookmarks/[slug]/highlights.tsx
@@ -0,0 +1,47 @@
+import FullPageError from "@/components/FullPageError";
+import HighlightList from "@/components/highlights/HighlightList";
+import FullPageSpinner from "@/components/ui/FullPageSpinner";
+import { useQuery, useQueryClient } from "@tanstack/react-query";
+import { useLocalSearchParams } from "expo-router";
+
+import { useTRPC } from "@karakeep/shared-react/trpc";
+
+export default function BookmarkHighlightsPage() {
+ const { slug } = useLocalSearchParams();
+ const api = useTRPC();
+ const queryClient = useQueryClient();
+
+ if (typeof slug !== "string") {
+ throw new Error("Unexpected param type");
+ }
+
+ const { data, isPending, isPlaceholderData, error, refetch } = useQuery(
+ api.highlights.getForBookmark.queryOptions({
+ bookmarkId: slug,
+ }),
+ );
+
+ if (error) {
+ return <FullPageError error={error.message} onRetry={() => refetch()} />;
+ }
+
+ if (isPending || !data) {
+ return <FullPageSpinner />;
+ }
+
+ const onRefresh = () => {
+ queryClient.invalidateQueries(
+ api.highlights.getForBookmark.queryFilter({
+ bookmarkId: slug,
+ }),
+ );
+ };
+
+ return (
+ <HighlightList
+ highlights={data.highlights}
+ onRefresh={onRefresh}
+ isRefreshing={isPending || isPlaceholderData}
+ />
+ );
+}
diff --git a/apps/mobile/app/dashboard/bookmarks/[slug]/info.tsx b/apps/mobile/app/dashboard/bookmarks/[slug]/info.tsx
index c8479383..ddb69d86 100644
--- a/apps/mobile/app/dashboard/bookmarks/[slug]/info.tsx
+++ b/apps/mobile/app/dashboard/bookmarks/[slug]/info.tsx
@@ -3,6 +3,7 @@ import {
ActivityIndicator,
Alert,
Pressable,
+ Switch,
TextInput,
View,
} from "react-native";
@@ -15,6 +16,7 @@ import { router, Stack, useLocalSearchParams } from "expo-router";
import BookmarkTextMarkdown from "@/components/bookmarks/BookmarkTextMarkdown";
import TagPill from "@/components/bookmarks/TagPill";
import FullPageError from "@/components/FullPageError";
+import ChevronRight from "@/components/ui/ChevronRight";
import FullPageSpinner from "@/components/ui/FullPageSpinner";
import {
GroupedSection,
@@ -24,8 +26,19 @@ import {
import { Skeleton } from "@/components/ui/Skeleton";
import { Text } from "@/components/ui/Text";
import { useToast } from "@/components/ui/Toast";
+import { shareBookmark } from "@/lib/shareBookmark";
+import useAppSettings from "@/lib/settings";
import { useColorScheme } from "@/lib/useColorScheme";
-import { ChevronUp, RefreshCw, Sparkles, Trash2 } from "lucide-react-native";
+import {
+ Archive,
+ ChevronUp,
+ Highlighter,
+ RefreshCw,
+ Share2,
+ Sparkles,
+ Star,
+ Trash2,
+} from "lucide-react-native";
import { useHeaderHeight } from "@react-navigation/elements";
import {
@@ -289,6 +302,151 @@ function AISummarySection({
);
}
+function BookmarkActionsSection({ bookmark }: { bookmark: ZBookmark }) {
+ const { toast } = useToast();
+ const { settings } = useAppSettings();
+ const { colors } = useColorScheme();
+
+ const onError = () => {
+ toast({
+ message: "Something went wrong",
+ variant: "destructive",
+ showProgress: false,
+ });
+ };
+
+ const { mutate: favoriteBookmark, variables: favoriteVariables } =
+ useUpdateBookmark({
+ onSuccess: (resp) => {
+ toast({
+ message: `Bookmark ${resp.favourited ? "added to" : "removed from"} favourites!`,
+ showProgress: false,
+ });
+ },
+ onError,
+ });
+
+ const { mutate: archiveBookmark, isPending: isArchivePending } =
+ useUpdateBookmark({
+ onSuccess: (resp) => {
+ toast({
+ message: `Bookmark ${resp.archived ? "archived" : "un-archived"}!`,
+ showProgress: false,
+ });
+ },
+ onError,
+ });
+
+ const isFavourited =
+ favoriteVariables?.bookmarkId === bookmark.id
+ ? favoriteVariables.favourited
+ : bookmark.favourited;
+
+ const actionIconColor = colors.grey;
+
+ return (
+ <GroupedSection>
+ <Pressable
+ onPress={() => {
+ Haptics.selectionAsync();
+ favoriteBookmark({
+ bookmarkId: bookmark.id,
+ favourited: !isFavourited,
+ });
+ }}
+ className="flex-row items-center justify-between px-4 py-3 active:opacity-70"
+ >
+ <View className="flex-1 flex-row items-center gap-3">
+ <Star
+ size={20}
+ color={isFavourited ? "#ebb434" : actionIconColor}
+ fill={isFavourited ? "#ebb434" : "transparent"}
+ />
+ <Text className="flex-1" numberOfLines={1}>
+ Favourite
+ </Text>
+ </View>
+ <Switch
+ className="shrink-0"
+ value={isFavourited}
+ onValueChange={(value) => {
+ Haptics.selectionAsync();
+ favoriteBookmark({
+ bookmarkId: bookmark.id,
+ favourited: value,
+ });
+ }}
+ />
+ </Pressable>
+ <RowSeparator />
+ <Pressable
+ onPress={() => {
+ Haptics.selectionAsync();
+ archiveBookmark({
+ bookmarkId: bookmark.id,
+ archived: !bookmark.archived,
+ });
+ }}
+ disabled={isArchivePending}
+ className="flex-row items-center justify-between px-4 py-3 active:opacity-70"
+ >
+ <View className="flex-1 flex-row items-center gap-3">
+ <Archive size={20} color={actionIconColor} />
+ <Text className="flex-1" numberOfLines={1}>
+ Archived
+ </Text>
+ </View>
+ {isArchivePending ? (
+ <ActivityIndicator size="small" />
+ ) : (
+ <Switch
+ className="shrink-0"
+ value={bookmark.archived}
+ onValueChange={(value) => {
+ Haptics.selectionAsync();
+ archiveBookmark({
+ bookmarkId: bookmark.id,
+ archived: value,
+ });
+ }}
+ />
+ )}
+ </Pressable>
+ <RowSeparator />
+ {bookmark.content.type === BookmarkTypes.LINK && (
+ <>
+ <Pressable
+ onPress={() => {
+ Haptics.selectionAsync();
+ router.push(`/dashboard/bookmarks/${bookmark.id}/highlights`);
+ }}
+ className="flex-row items-center justify-between gap-3 px-4 py-3 active:opacity-70"
+ >
+ <View className="flex-1 flex-row items-center gap-3">
+ <Highlighter size={20} color={actionIconColor} />
+ <Text className="flex-1" numberOfLines={1}>
+ Highlights
+ </Text>
+ </View>
+ <ChevronRight size={16} />
+ </Pressable>
+ <RowSeparator />
+ </>
+ )}
+ <Pressable
+ onPress={() => {
+ Haptics.selectionAsync();
+ shareBookmark(bookmark, settings, toast);
+ }}
+ className="flex-row items-center gap-3 px-4 py-3 active:opacity-70"
+ >
+ <Share2 size={20} color={actionIconColor} />
+ <Text numberOfLines={1}>Share Bookmark</Text>
+ </Pressable>
+ </GroupedSection>
+ );
+}
+
// --- Main Page ---
const ViewBookmarkPage = () => {
@@ -450,17 +608,20 @@ const ViewBookmarkPage = () => {
disabled={!isOwner}
/>
{isOwner && (
- <GroupedSection>
- <Pressable
- onPress={handleDeleteBookmark}
- disabled={isDeletionPending}
- className="items-center px-4 py-3 active:opacity-70"
- >
- <Text className="text-destructive" numberOfLines={1}>
- {isDeletionPending ? "Deleting..." : "Delete Bookmark"}
- </Text>
- </Pressable>
- </GroupedSection>
+ <>
+ <BookmarkActionsSection bookmark={bookmark} />
+ <GroupedSection>
+ <Pressable
+ onPress={handleDeleteBookmark}
+ disabled={isDeletionPending}
+ className="items-center px-4 py-3 active:opacity-70"
+ >
+ <Text className="text-destructive" numberOfLines={1}>
+ {isDeletionPending ? "Deleting..." : "Delete Bookmark"}
+ </Text>
+ </Pressable>
+ </GroupedSection>
+ </>
)}
<View className="items-center gap-1 pt-2">
<Text variant="caption1" color="tertiary" selectable>