A self-hostable bookmark-everything app (links, notes and images) with AI-based automatic tagging and full text search
feat(mobile): manage public lists and collaborators
Mohamed Bassem292c13a5c3e3
diff --git a/apps/mobile/app/dashboard/(tabs)/(lists)/index.tsx b/apps/mobile/app/dashboard/(tabs)/(lists)/index.tsxindex 83b3e237..52ea1393 100644--- a/apps/mobile/app/dashboard/(tabs)/(lists)/index.tsx+++ b/apps/mobile/app/dashboard/(tabs)/(lists)/index.tsx@@ -8,6 +8,7 @@ import {} from "react-native";import * as Haptics from "expo-haptics";import { Link, router } from "expo-router";+import { PendingListInvitations } from "@/components/lists/pending-list-invitations";import QueryPageState from "@/components/QueryPageState";import ChevronRight from "@/components/ui/ChevronRight";import { FAB } from "@/components/ui/FAB";@@ -112,6 +113,7 @@ export default function Lists() {const onRefresh = () => {queryClient.invalidateQueries(api.lists.list.pathFilter());queryClient.invalidateQueries(api.lists.stats.pathFilter());+ queryClient.invalidateQueries(api.lists.getPendingInvitations.pathFilter());};const links: ListLink[] = [@@ -184,6 +186,7 @@ export default function Lists() {return (<><FlatList+ ListHeaderComponent={PendingListInvitations}className="h-full"contentInsetAdjustmentBehavior="automatic"contentContainerStyle={{diff --git a/apps/mobile/app/dashboard/_layout.tsx b/apps/mobile/app/dashboard/_layout.tsxindex 51bc79d0..bc99ba3a 100644--- a/apps/mobile/app/dashboard/_layout.tsx+++ b/apps/mobile/app/dashboard/_layout.tsx@@ -184,6 +184,20 @@ export default function Dashboard() {sheetGrabberVisible: true,}}/>+ <Stack.Screen+ name="lists/[slug]/sharing"+ options={{+ ...formSheetSurfaceOptions,+ headerTitle: "Sharing & Access",+ headerLargeTitle: false,+ headerTransparent: false,+ presentation: Platform.select({+ ios: "formSheet" as const,+ default: "modal" as const,+ }),+ sheetGrabberVisible: true,+ }}+ /><Stack.Screenname="lists/select-parent"options={{diff --git a/apps/mobile/app/dashboard/lists/[slug]/edit.tsx b/apps/mobile/app/dashboard/lists/[slug]/edit.tsxindex cd2b0201..ba0b172f 100644--- a/apps/mobile/app/dashboard/lists/[slug]/edit.tsx+++ b/apps/mobile/app/dashboard/lists/[slug]/edit.tsx@@ -6,6 +6,7 @@ import QueryPageState from "@/components/QueryPageState";import { Button } from "@/components/ui/Button";import { EmojiPicker } from "@/components/ui/emoji-picker";import FullPageSpinner from "@/components/ui/FullPageSpinner";+import { GroupedSection, NavigationRow } from "@/components/ui/GroupedList";import { Input } from "@/components/ui/Input";import { Text } from "@/components/ui/Text";import { useToast } from "@/components/ui/Toast";@@ -167,6 +168,17 @@ const EditListPage = () => {}/>+ {list.userRole === "owner" && (+ <GroupedSection>+ <NavigationRow+ label="Sharing & Access"+ onPress={() =>+ router.push(`/dashboard/lists/${listId}/sharing`)+ }+ />+ </GroupedSection>+ )}+{/* Smart List Query Input */}{list?.type === "smart" && (<View className="gap-2">diff --git a/apps/mobile/app/dashboard/lists/[slug]/index.tsx b/apps/mobile/app/dashboard/lists/[slug]/index.tsxindex af6695fc..164471b1 100644--- a/apps/mobile/app/dashboard/lists/[slug]/index.tsx+++ b/apps/mobile/app/dashboard/lists/[slug]/index.tsx@@ -131,6 +131,13 @@ function ListActionsMenu({ios: menuIconColor,}),},+ {+ id: "sharing",+ title: role === "owner" ? "Sharing & Access" : "People with Access",+ attributes: { hidden: role === "public" },+ image: Platform.select({ ios: "person.2" }),+ imageColor: Platform.select({ ios: menuIconColor }),+ },{id: "delete_list",title: "Delete List",@@ -170,6 +177,8 @@ function ListActionsMenu({handleDelete();} else if (nativeEvent.event === "leave") {handleLeave();+ } else if (nativeEvent.event === "sharing") {+ router.push(`/dashboard/lists/${listId}/sharing`);} else if (nativeEvent.event === "edit") {handleEdit();}diff --git a/apps/mobile/app/dashboard/lists/[slug]/sharing.tsx b/apps/mobile/app/dashboard/lists/[slug]/sharing.tsxnew file mode 100644index 00000000..bc0f913b--- /dev/null+++ b/apps/mobile/app/dashboard/lists/[slug]/sharing.tsx@@ -0,0 +1,51 @@+import { Pressable } from "react-native";+import { KeyboardAwareScrollView } from "react-native-keyboard-controller";+import { router, Stack, useLocalSearchParams } from "expo-router";+import { useQuery } from "@tanstack/react-query";++import { useTRPC } from "@karakeep/shared-react/trpc";++import { ListSharingSettings } from "@/components/lists/list-sharing-settings";+import QueryPageState from "@/components/QueryPageState";+import { Text } from "@/components/ui/Text";++export default function ListSharingPage() {+ const { slug } = useLocalSearchParams();+ const api = useTRPC();+ if (typeof slug !== "string") throw new Error("Unexpected param type");+ const {+ data: list,+ error,+ refetch,+ } = useQuery(api.lists.get.queryOptions({ listId: slug }));+ return (+ <>+ <Stack.Screen+ options={{+ headerTitle: "Sharing & Access",+ headerRight: () => (+ <Pressable+ accessibilityRole="button"+ onPress={() => router.back()}+ className="px-2"+ >+ <Text className="text-primary">Done</Text>+ </Pressable>+ ),+ }}+ />+ {list ? (+ <KeyboardAwareScrollView+ bottomOffset={16}+ keyboardShouldPersistTaps="handled"+ contentContainerStyle={{ padding: 16, paddingBottom: 40 }}+ className="flex-1 bg-background"+ >+ <ListSharingSettings list={list} />+ </KeyboardAwareScrollView>+ ) : (+ <QueryPageState error={error} onRetry={() => refetch()} />+ )}+ </>+ );+}diff --git a/apps/mobile/components/lists/list-sharing-settings.tsx b/apps/mobile/components/lists/list-sharing-settings.tsxnew file mode 100644index 00000000..442f1626--- /dev/null+++ b/apps/mobile/components/lists/list-sharing-settings.tsx@@ -0,0 +1,456 @@+import { Fragment, useState } from "react";+import {+ ActivityIndicator,+ Alert,+ Platform,+ Pressable,+ Share,+ Switch,+ View,+} from "react-native";+import * as Clipboard from "expo-clipboard";+import { MenuView } from "@react-native-menu/menu";+import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query";+import {+ ChevronDown,+ Copy,+ Globe,+ Share2,+ Trash2,+ UserPlus,+} from "lucide-react-native";++import { useEditBookmarkList } from "@karakeep/shared-react/hooks/lists";+import { useTRPC } from "@karakeep/shared-react/trpc";+import type { ZBookmarkList } from "@karakeep/shared/types/lists";++import { Button } from "@/components/ui/Button";+import { GroupedSection, RowSeparator } from "@/components/ui/GroupedList";+import { Input } from "@/components/ui/Input";+import { Text } from "@/components/ui/Text";+import { useToast } from "@/components/ui/Toast";+import useAppSettings from "@/lib/settings";+import { useColorScheme } from "@/lib/useColorScheme";++type Role = "viewer" | "editor";++function RolePicker({+ role,+ onChange,+ disabled,+ label = "Permission",+}: {+ role: Role;+ onChange: (role: Role) => void;+ disabled?: boolean;+ label?: string;+}) {+ const { colors } = useColorScheme();+ return (+ <MenuView+ title="Permission"+ actions={[+ {+ id: "viewer",+ title: "Can view",+ state: role === "viewer" ? "on" : "off",+ attributes: { disabled },+ },+ {+ id: "editor",+ title: "Can edit",+ state: role === "editor" ? "on" : "off",+ attributes: { disabled },+ },+ ]}+ onPressAction={({ nativeEvent }) => {+ if (+ !disabled &&+ (nativeEvent.event === "viewer" || nativeEvent.event === "editor")+ )+ onChange(nativeEvent.event);+ }}+ >+ <View+ accessible+ accessibilityRole="button"+ accessibilityLabel={`${label}: ${role === "viewer" ? "Can view" : "Can edit"}`}+ accessibilityState={{ disabled }}+ className="min-h-11 flex-row items-center gap-1.5"+ >+ <Text className="text-primary">+ {role === "viewer" ? "Can view" : "Can edit"}+ </Text>+ <ChevronDown size={16} color={colors.primary} />+ </View>+ </MenuView>+ );+}++function Person({+ name,+ email,+ subtitle,+ children,+}: {+ name: string;+ email?: string | null;+ subtitle?: string;+ children: React.ReactNode;+}) {+ return (+ <View className="flex-row items-center gap-3 px-4 py-3">+ <View className="h-10 w-10 items-center justify-center rounded-full bg-primary/10">+ <Text className="font-semibold text-primary">+ {(name || email || "?").slice(0, 1).toUpperCase()}+ </Text>+ </View>+ <View className="flex-1 gap-0.5">+ <Text numberOfLines={1}>{name || email || "User"}</Text>+ {email ? (+ <Text variant="footnote" color="tertiary" numberOfLines={1}>+ {email}+ </Text>+ ) : null}+ {subtitle ? (+ <Text variant="footnote" color="tertiary">+ {subtitle}+ </Text>+ ) : null}+ </View>+ {children}+ </View>+ );+}++export function ListSharingSettings({ list }: { list: ZBookmarkList }) {+ const api = useTRPC();+ const queryClient = useQueryClient();+ const { toast } = useToast();+ const { colors } = useColorScheme();+ const { settings } = useAppSettings();+ const [email, setEmail] = useState("");+ const [role, setRole] = useState<Role>("viewer");+ const isOwner = list.userRole === "owner";+ const { data: config } = useQuery(api.config.clientConfig.queryOptions());+ const publicUrl = `${(config?.publicUrl || settings.address).replace(/\/$/, "")}/public/lists/${list.id}`;+ const collaboratorsQuery = useQuery(+ api.lists.getCollaborators.queryOptions({ listId: list.id }),+ );+ const collaborators = collaboratorsQuery.data;++ const onError = (error: { message: string }) =>+ toast({+ message: error.message,+ variant: "destructive",+ showProgress: false,+ });+ const invalidate = () =>+ Promise.all([+ queryClient.invalidateQueries(+ api.lists.getCollaborators.queryFilter({ listId: list.id }),+ ),+ queryClient.invalidateQueries(+ api.lists.get.queryFilter({ listId: list.id }),+ ),+ queryClient.invalidateQueries(api.lists.list.pathFilter()),+ queryClient.invalidateQueries(api.lists.stats.pathFilter()),+ queryClient.invalidateQueries(api.bookmarks.getBookmarks.pathFilter()),+ ]);+ const editList = useEditBookmarkList({+ onError,+ onSuccess: async () => {+ await queryClient.invalidateQueries(+ api.lists.get.queryFilter({ listId: list.id }),+ );+ },+ });+ const invite = useMutation(+ api.lists.addCollaborator.mutationOptions({+ onError,+ onSuccess: async () => {+ setEmail("");+ toast({ message: "Invitation sent", showProgress: false });+ await invalidate();+ },+ }),+ );+ const remove = useMutation(+ api.lists.removeCollaborator.mutationOptions({+ onError,+ onSuccess: invalidate,+ }),+ );+ const updateRole = useMutation(+ api.lists.updateCollaboratorRole.mutationOptions({+ onError,+ onSuccess: invalidate,+ }),+ );+ const revoke = useMutation(+ api.lists.revokeInvitation.mutationOptions({+ onError,+ onSuccess: invalidate,+ }),+ );+ const isUpdating =+ invite.isPending ||+ remove.isPending ||+ updateRole.isPending ||+ revoke.isPending;++ const sendInvitation = () => {+ const trimmedEmail = email.trim();+ if (!/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(trimmedEmail)) {+ toast({+ message: "Enter a valid email address",+ variant: "destructive",+ showProgress: false,+ });+ return;+ }+ invite.mutate({ listId: list.id, email: trimmedEmail, role });+ };++ const sharePublicLink = async (copy: boolean) => {+ try {+ if (copy) {+ await Clipboard.setStringAsync(publicUrl);+ toast({ message: "Public link copied", showProgress: false });+ } else {+ await Share.share(+ Platform.OS === "ios" ? { url: publicUrl } : { message: publicUrl },+ );+ }+ } catch {+ toast({+ message: "Failed to share link",+ variant: "destructive",+ showProgress: false,+ });+ }+ };++ return (+ <View className="gap-5">+ <Text variant="title3" className="px-1 font-semibold">+ {list.name}+ </Text>+ {isOwner && (+ <GroupedSection header="Public access">+ <View className="flex-row items-center gap-3 px-4 py-3">+ <Globe size={22} color={colors.grey} />+ <View className="flex-1 gap-1">+ <Text>Public list</Text>+ <Text variant="footnote" color="tertiary">+ Anyone with the link can view the bookmarks in this list.+ </Text>+ </View>+ {editList.isPending ? <ActivityIndicator size="small" /> : null}+ <Switch+ accessibilityLabel="Public list"+ value={list.public}+ disabled={editList.isPending || !config || !!config.demoMode}+ onValueChange={(value) =>+ editList.mutate({ listId: list.id, public: value })+ }+ />+ </View>+ {list.public && (+ <>+ <RowSeparator />+ <View className="gap-2 px-4 py-3">+ <Text variant="footnote" color="tertiary" selectable>+ {publicUrl}+ </Text>+ <View className="flex-row gap-3">+ <Pressable+ accessibilityRole="button"+ onPress={() => void sharePublicLink(true)}+ className="min-h-11 flex-row items-center gap-2 pr-3 active:opacity-70"+ >+ <Copy size={18} color={colors.primary} />+ <Text className="text-primary">Copy link</Text>+ </Pressable>+ <Pressable+ accessibilityRole="button"+ onPress={() => void sharePublicLink(false)}+ className="min-h-11 flex-row items-center gap-2 px-3 active:opacity-70"+ >+ <Share2 size={18} color={colors.primary} />+ <Text className="text-primary">Share link</Text>+ </Pressable>+ </View>+ </View>+ </>+ )}+ </GroupedSection>+ )}++ {isOwner && list.type === "manual" && (+ <GroupedSection header="Invite a collaborator">+ <View className="gap-3 p-4">+ <Input+ accessibilityLabel="Collaborator email"+ placeholder="Email address"+ value={email}+ onChangeText={setEmail}+ keyboardType="email-address"+ autoCapitalize="none"+ autoCorrect={false}+ editable={!isUpdating}+ returnKeyType="send"+ onSubmitEditing={() => {+ if (!isUpdating) sendInvitation();+ }}+ />+ <View className="flex-row items-center justify-between">+ <Text>Permission</Text>+ <RolePicker+ role={role}+ onChange={setRole}+ disabled={isUpdating}+ />+ </View>+ <Text variant="footnote" color="tertiary">+ {role === "viewer"+ ? "Can view bookmarks in this list."+ : "Can view, add, and remove bookmarks in this list."}+ </Text>+ <Button+ onPress={sendInvitation}+ disabled={!email.trim() || isUpdating}+ size="lg"+ >+ {invite.isPending ? (+ <ActivityIndicator size="small" color="white" />+ ) : (+ <UserPlus size={18} color="white" />+ )}+ <Text>+ {invite.isPending ? "Inviting..." : "Send invitation"}+ </Text>+ </Button>+ </View>+ </GroupedSection>+ )}+ {isOwner && list.type === "smart" && (+ <Text variant="footnote" color="tertiary" className="px-4">+ Only manual lists can have collaborators.+ </Text>+ )}++ <GroupedSection header="People with access">+ {collaboratorsQuery.isPending ? (+ <ActivityIndicator className="p-4" />+ ) : collaboratorsQuery.error ? (+ <View className="gap-3 p-4">+ <Text color="tertiary">Unable to load collaborators.</Text>+ <Button+ variant="plain"+ onPress={() => void collaboratorsQuery.refetch()}+ >+ <Text>Try again</Text>+ </Button>+ </View>+ ) : collaborators ? (+ <>+ {collaborators.owner && (+ <Person+ name={collaborators.owner.name}+ email={collaborators.owner.email}+ >+ <Text variant="footnote" color="tertiary">+ Owner+ </Text>+ </Person>+ )}+ {collaborators.collaborators.map((person, index) => (+ <Fragment key={person.id}>+ {(index > 0 || !!collaborators.owner) && <RowSeparator />}+ <Person+ name={person.user.name}+ email={person.user.email}+ subtitle={+ person.status === "pending"+ ? "Invitation pending"+ : person.status === "declined"+ ? "Invitation declined"+ : undefined+ }+ >+ {isOwner && person.status === "accepted" ? (+ <RolePicker+ role={person.role}+ disabled={isUpdating}+ label={`Permission for ${person.user.name}`}+ onChange={(role) =>+ updateRole.mutate({+ listId: list.id,+ userId: person.userId,+ role,+ })+ }+ />+ ) : (+ <Text variant="footnote" color="tertiary">+ {person.role === "viewer" ? "Can view" : "Can edit"}+ </Text>+ )}+ {isOwner && (+ <Pressable+ accessibilityRole="button"+ accessibilityLabel={`${person.status === "accepted" ? "Remove" : "Revoke invitation for"} ${person.user.name}`}+ disabled={isUpdating}+ className="min-h-11 min-w-11 items-center justify-center active:opacity-70"+ onPress={() =>+ Alert.alert(+ person.status === "accepted"+ ? "Remove collaborator?"+ : "Revoke invitation?",+ person.status === "accepted"+ ? `${person.user.name} will lose access. Bookmarks they added will be removed from this list.`+ : `Revoke the invitation for ${person.user.name}?`,+ [+ { text: "Cancel", style: "cancel" },+ {+ text:+ person.status === "accepted"+ ? "Remove"+ : "Revoke",+ style: "destructive",+ onPress: () =>+ person.status === "accepted"+ ? remove.mutate({+ listId: list.id,+ userId: person.userId,+ })+ : revoke.mutate({ invitationId: person.id }),+ },+ ],+ )+ }+ >+ <Trash2 size={18} color={colors.destructive} />+ </Pressable>+ )}+ </Person>+ </Fragment>+ ))}+ {collaborators.collaborators.length === 0 && (+ <>+ {collaborators.owner && <RowSeparator />}+ <Text variant="footnote" color="tertiary" className="px-4 py-3">+ No collaborators yet.+ </Text>+ </>+ )}+ {isUpdating && !invite.isPending && (+ <ActivityIndicator className="pb-3" />+ )}+ </>+ ) : null}+ </GroupedSection>+ </View>+ );+}diff --git a/apps/mobile/components/lists/pending-list-invitations.tsx b/apps/mobile/components/lists/pending-list-invitations.tsxnew file mode 100644index 00000000..4e241e28--- /dev/null+++ b/apps/mobile/components/lists/pending-list-invitations.tsx@@ -0,0 +1,109 @@+import { ActivityIndicator, View } from "react-native";+import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query";++import { useTRPC } from "@karakeep/shared-react/trpc";++import { Button } from "@/components/ui/Button";+import { Text } from "@/components/ui/Text";+import { useToast } from "@/components/ui/Toast";++interface Invitation {+ id: string;+ role: "viewer" | "editor";+ list: { name: string; owner: { name: string } | null };+}++function InvitationRow({ invitation }: { invitation: Invitation }) {+ const api = useTRPC();+ const queryClient = useQueryClient();+ const { toast } = useToast();+ const onError = (error: { message: string }) =>+ toast({+ message: error.message,+ variant: "destructive",+ showProgress: false,+ });+ const accept = useMutation(+ api.lists.acceptInvitation.mutationOptions({+ onError,+ onSuccess: async () => {+ await Promise.all([+ queryClient.invalidateQueries(+ api.lists.getPendingInvitations.pathFilter(),+ ),+ queryClient.invalidateQueries(api.lists.list.pathFilter()),+ queryClient.invalidateQueries(api.lists.stats.pathFilter()),+ ]);+ toast({ message: "Invitation accepted", showProgress: false });+ },+ }),+ );+ const decline = useMutation(+ api.lists.declineInvitation.mutationOptions({+ onError,+ onSuccess: async () => {+ await queryClient.invalidateQueries(+ api.lists.getPendingInvitations.pathFilter(),+ );+ toast({ message: "Invitation declined", showProgress: false });+ },+ }),+ );+ const busy = accept.isPending || decline.isPending;+ return (+ <View className="gap-2 rounded-xl bg-card p-4">+ <Text className="font-semibold">{invitation.list.name}</Text>+ <Text variant="footnote" color="tertiary">+ {invitation.list.owner+ ? `Invited by ${invitation.list.owner.name}. `+ : ""}+ {invitation.role === "editor"+ ? "Can view, add, and remove bookmarks."+ : "Can view bookmarks."}+ </Text>+ <View className="flex-row items-center gap-3">+ <Button+ accessibilityLabel={`Accept invitation to ${invitation.list.name}`}+ disabled={busy}+ onPress={() => accept.mutate({ invitationId: invitation.id })}+ >+ <Text>Accept</Text>+ </Button>+ <Button+ accessibilityLabel={`Decline invitation to ${invitation.list.name}`}+ variant="plain"+ disabled={busy}+ onPress={() => decline.mutate({ invitationId: invitation.id })}+ >+ <Text>Decline</Text>+ </Button>+ {busy && <ActivityIndicator size="small" />}+ </View>+ </View>+ );+}++export function PendingListInvitations() {+ const api = useTRPC();+ const { data, error, refetch } = useQuery(+ api.lists.getPendingInvitations.queryOptions(),+ );+ if (error) {+ return (+ <Button variant="plain" onPress={() => void refetch()}>+ <Text>Retry loading invitations</Text>+ </Button>+ );+ }+ if (!data?.length) return null;+ return (+ <View className="mb-4 gap-2">+ <Text variant="footnote" color="tertiary" className="px-4 uppercase">+ Invitations+ </Text>+ {data.map((invitation) => (+ <InvitationRow key={invitation.id} invitation={invitation} />+ ))}+ </View>+ );+}