Skip to content

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

feat(mobile): tag management

Mohamed Bassemfc401d02bfda
diff --git a/apps/mobile/app/dashboard/(tabs)/(tags)/index.tsx b/apps/mobile/app/dashboard/(tabs)/(tags)/index.tsx
index 01a232cf..66c81c43 100644
--- a/apps/mobile/app/dashboard/(tabs)/(tags)/index.tsx
+++ b/apps/mobile/app/dashboard/(tabs)/(tags)/index.tsx
@@ -1,13 +1,21 @@
import { useEffect, useState } from "react";
-import { FlatList, Pressable, View } from "react-native";
-import { Link } from "expo-router";
+import {
+ FlatList,
+ Platform,
+ PlatformColor,
+ Pressable,
+ View,
+} from "react-native";
+import * as Haptics from "expo-haptics";
+import { Link, router } from "expo-router";
import QueryPageState from "@/components/QueryPageState";
import ChevronRight from "@/components/ui/ChevronRight";
import EmptyState from "@/components/ui/EmptyState";
+import { FAB } from "@/components/ui/FAB";
import { SearchInput } from "@/components/ui/SearchInput";
import { Text } from "@/components/ui/Text";
import { useQueryClient } from "@tanstack/react-query";
-import { Tag } from "lucide-react-native";
+import { Plus, Tag } from "lucide-react-native";
import { usePaginatedSearchTags } from "@karakeep/shared-react/hooks/tags";
import { useDebounce } from "@karakeep/shared-react/hooks/use-debounce";
@@ -70,68 +78,86 @@ export default function Tags() {
};
return (
- <FlatList
- className="h-full"
- contentInsetAdjustmentBehavior="automatic"
- ListHeaderComponent={
- <SearchInput
- containerClassName="mx-2 mb-2"
- placeholder="Search tags..."
- value={searchQuery}
- onChangeText={setSearchQuery}
- />
- }
- contentContainerStyle={{
- gap: 6,
- paddingBottom: 20,
- }}
- renderItem={(item) => (
- <View
- className="mx-2 flex flex-row items-center rounded-xl bg-card px-4 py-2"
- style={{ borderCurve: "continuous" }}
- >
- <Link
- asChild
- key={item.item.id}
- href={item.item.href}
- className="flex-1"
+ <>
+ <FlatList
+ className="h-full"
+ contentInsetAdjustmentBehavior="automatic"
+ ListHeaderComponent={
+ <SearchInput
+ containerClassName="mx-2 mb-2"
+ placeholder="Search tags..."
+ value={searchQuery}
+ onChangeText={setSearchQuery}
+ />
+ }
+ contentContainerStyle={{
+ gap: 6,
+ paddingBottom: 20,
+ }}
+ renderItem={(item) => (
+ <View
+ className="mx-2 flex flex-row items-center rounded-xl bg-card px-4 py-2"
+ style={{ borderCurve: "continuous" }}
>
- <Pressable className="flex flex-row items-center justify-between">
- <View className="flex-1">
- <Text className="font-medium">{item.item.name}</Text>
- <Text className="text-sm text-muted-foreground">
- {item.item.numBookmarks}{" "}
- {item.item.numBookmarks === 1 ? "bookmark" : "bookmarks"}
- </Text>
- </View>
- <ChevronRight />
- </Pressable>
- </Link>
- </View>
- )}
- data={tags}
- refreshing={refreshing}
- onRefresh={onRefresh}
- onEndReached={handleLoadMore}
- onEndReachedThreshold={0.5}
- ListFooterComponent={
- isFetchingNextPage ? (
- <View className="py-4">
- <Text className="text-center text-muted-foreground">
- Loading more...
- </Text>
+ <Link
+ asChild
+ key={item.item.id}
+ href={item.item.href}
+ className="flex-1"
+ >
+ <Pressable className="flex flex-row items-center justify-between">
+ <View className="flex-1">
+ <Text className="font-medium">{item.item.name}</Text>
+ <Text className="text-sm text-muted-foreground">
+ {item.item.numBookmarks}{" "}
+ {item.item.numBookmarks === 1 ? "bookmark" : "bookmarks"}
+ </Text>
+ </View>
+ <ChevronRight />
+ </Pressable>
+ </Link>
</View>
- ) : null
- }
- ListEmptyComponent={
- !isPending ? (
- <EmptyState
- icon={Tag}
- title="No Tags"
- subtitle="Tags will appear as you organize your bookmarks"
+ )}
+ data={tags}
+ refreshing={refreshing}
+ onRefresh={onRefresh}
+ onEndReached={handleLoadMore}
+ onEndReachedThreshold={0.5}
+ ListFooterComponent={
+ isFetchingNextPage ? (
+ <View className="py-4">
+ <Text className="text-center text-muted-foreground">
+ Loading more...
+ </Text>
+ </View>
+ ) : null
+ }
+ ListEmptyComponent={
+ !isPending ? (
+ <EmptyState
+ icon={Tag}
+ title="No Tags"
+ subtitle="Tags will appear as you organize your bookmarks"
+ />
+ ) : null
+ }
+ />
+ <FAB>
+ <Pressable
+ accessibilityLabel="Create tag"
+ accessibilityRole="button"
+ className="h-full w-full items-center justify-center"
+ onPress={() => {
+ void Haptics.selectionAsync();
+ router.push("/dashboard/tags/new");
+ }}
+ >
+ <Plus
+ size={24}
+ color={Platform.OS === "ios" ? PlatformColor("label") : "white"}
/>
- ) : null
- }
- />
+ </Pressable>
+ </FAB>
+ </>
);
}
diff --git a/apps/mobile/app/dashboard/_layout.tsx b/apps/mobile/app/dashboard/_layout.tsx
index 9f3d9f1f..493b1163 100644
--- a/apps/mobile/app/dashboard/_layout.tsx
+++ b/apps/mobile/app/dashboard/_layout.tsx
@@ -191,6 +191,36 @@ export default function Dashboard() {
headerTransparent: false,
}}
/>
+ <Stack.Screen
+ name="tags/new"
+ options={{
+ ...formSheetSurfaceOptions,
+ headerTitle: "New Tag",
+ headerBackTitle: "Back",
+ headerLargeTitle: false,
+ headerTransparent: false,
+ presentation: Platform.select({
+ ios: "formSheet" as const,
+ default: "modal" as const,
+ }),
+ sheetGrabberVisible: true,
+ }}
+ />
+ <Stack.Screen
+ name="tags/[slug]/edit"
+ options={{
+ ...formSheetSurfaceOptions,
+ headerTitle: "Edit Tag",
+ headerBackTitle: "Back",
+ headerLargeTitle: false,
+ headerTransparent: false,
+ presentation: Platform.select({
+ ios: "formSheet" as const,
+ default: "modal" as const,
+ }),
+ sheetGrabberVisible: true,
+ }}
+ />
<Stack.Screen
name="archive"
options={{
diff --git a/apps/mobile/app/dashboard/tags/[slug].tsx b/apps/mobile/app/dashboard/tags/[slug].tsx
index 9d0878d7..6d99f7d8 100644
--- a/apps/mobile/app/dashboard/tags/[slug].tsx
+++ b/apps/mobile/app/dashboard/tags/[slug].tsx
@@ -1,11 +1,19 @@
-import { Stack, useLocalSearchParams } from "expo-router";
-import BookmarkListHeader from "@/components/bookmarks/BookmarkListHeader";
+import { Alert, Platform, View } from "react-native";
+import * as Haptics from "expo-haptics";
+import { router, Stack, useLocalSearchParams } from "expo-router";
+import { useBookmarkListLayoutMenu } from "@/components/bookmarks/BookmarkListHeader";
import UpdatingBookmarkList from "@/components/bookmarks/UpdatingBookmarkList";
import QueryPageState from "@/components/QueryPageState";
import FullPageSpinner from "@/components/ui/FullPageSpinner";
+import { useToast } from "@/components/ui/Toast";
import { useArchiveFilter } from "@/lib/hooks";
+import { useColorScheme } from "@/lib/useColorScheme";
+import { useMenuIconColors } from "@/lib/useMenuIconColors";
+import { MenuView } from "@react-native-menu/menu";
import { useQuery } from "@tanstack/react-query";
+import { Ellipsis } from "lucide-react-native";
+import { useDeleteTag } from "@karakeep/shared-react/hooks/tags";
import { useTRPC } from "@karakeep/shared-react/trpc";
export default function TagView() {
@@ -28,7 +36,8 @@ export default function TagView() {
options={{
headerTitle: tag?.name ?? "",
headerBackTitle: "Back",
- headerRight: () => <BookmarkListHeader />,
+ headerRight: () =>
+ tag ? <TagActionsMenu tagId={tag.id} tagName={tag.name} /> : null,
}}
/>
{!tag ? (
@@ -46,3 +55,87 @@ export default function TagView() {
</>
);
}
+
+function TagActionsMenu({
+ tagId,
+ tagName,
+}: {
+ tagId: string;
+ tagName: string;
+}) {
+ const { colors } = useColorScheme();
+ const { menuIconColor, destructiveMenuIconColor } = useMenuIconColors();
+ const { layoutActions, handleLayoutAction } = useBookmarkListLayoutMenu();
+ const { toast } = useToast();
+ const { mutate: deleteTag } = useDeleteTag({
+ onSuccess: () => {
+ router.dismissTo("/dashboard/(tabs)/(tags)");
+ toast({ message: `Tag "${tagName}" deleted`, variant: "success" });
+ },
+ onError: (error) => {
+ toast({ message: error.message, variant: "destructive" });
+ },
+ });
+
+ const handleDelete = () => {
+ Alert.alert(
+ "Delete Tag",
+ `Are you sure you want to delete the tag "${tagName}"?`,
+ [
+ { text: "Cancel", style: "cancel" },
+ {
+ text: "Delete",
+ onPress: () => deleteTag({ tagId }),
+ style: "destructive",
+ },
+ ],
+ );
+ };
+
+ const handleEdit = () => {
+ router.push({
+ pathname: "/dashboard/tags/[slug]/edit",
+ params: { slug: tagId },
+ });
+ };
+
+ return (
+ <MenuView
+ actions={[
+ {
+ id: "edit",
+ title: "Edit Tag",
+ image: Platform.select({ ios: "square.and.pencil" }),
+ imageColor: Platform.select({ ios: menuIconColor }),
+ },
+ {
+ id: "delete_tag",
+ title: "Delete Tag",
+ attributes: { destructive: true },
+ image: Platform.select({ ios: "trash" }),
+ imageColor: Platform.select({ ios: destructiveMenuIconColor }),
+ },
+ ...layoutActions,
+ ]}
+ onPressAction={({ nativeEvent }) => {
+ if (handleLayoutAction(nativeEvent.event)) {
+ return;
+ }
+
+ if (nativeEvent.event === "delete_tag") {
+ handleDelete();
+ } else if (nativeEvent.event === "edit") {
+ handleEdit();
+ }
+ }}
+ shouldOpenOnLongPress={false}
+ >
+ <View className="my-auto">
+ <Ellipsis
+ onPress={() => void Haptics.selectionAsync()}
+ color={colors.foreground}
+ />
+ </View>
+ </MenuView>
+ );
+}
diff --git a/apps/mobile/app/dashboard/tags/[slug]/edit.tsx b/apps/mobile/app/dashboard/tags/[slug]/edit.tsx
new file mode 100644
index 00000000..4814d0c4
--- /dev/null
+++ b/apps/mobile/app/dashboard/tags/[slug]/edit.tsx
@@ -0,0 +1,98 @@
+import { useEffect, useState } from "react";
+import { ScrollView } from "react-native";
+import { router, useLocalSearchParams } from "expo-router";
+import QueryPageState from "@/components/QueryPageState";
+import { Button } from "@/components/ui/Button";
+import FullPageSpinner from "@/components/ui/FullPageSpinner";
+import { Input } from "@/components/ui/Input";
+import { Text } from "@/components/ui/Text";
+import { useToast } from "@/components/ui/Toast";
+import { useQuery } from "@tanstack/react-query";
+
+import { useUpdateTag } from "@karakeep/shared-react/hooks/tags";
+import { useTRPC } from "@karakeep/shared-react/trpc";
+
+export default function EditTagPage() {
+ const { slug: tagId } = useLocalSearchParams<{
+ slug?: string | string[];
+ }>();
+ const [name, setName] = useState("");
+ const api = useTRPC();
+ const { toast } = useToast();
+
+ if (typeof tagId !== "string") {
+ throw new Error("Unexpected param type");
+ }
+
+ const {
+ data: tag,
+ error,
+ refetch,
+ } = useQuery(api.tags.get.queryOptions({ tagId }));
+ const { mutate: updateTag, isPending } = useUpdateTag({
+ onSuccess: () => {
+ toast({ message: "Tag updated", variant: "success" });
+ router.back();
+ },
+ onError: (mutationError) => {
+ const message = mutationError.data?.zodError
+ ? Object.values(mutationError.data.zodError.fieldErrors)
+ .flat()
+ .join("\n")
+ : mutationError.message;
+ toast({
+ message: message || "Something went wrong",
+ variant: "destructive",
+ });
+ },
+ });
+
+ useEffect(() => {
+ if (tag) {
+ setName(tag.name);
+ }
+ }, [tag]);
+
+ const onSubmit = () => {
+ const trimmedName = name.trim();
+ if (!trimmedName) {
+ toast({ message: "Tag name can't be empty", variant: "destructive" });
+ return;
+ }
+
+ updateTag({ tagId, name: trimmedName });
+ };
+
+ if (!tag) {
+ return <QueryPageState error={error} onRetry={() => refetch()} />;
+ }
+
+ if (isPending) {
+ return <FullPageSpinner />;
+ }
+
+ return (
+ <ScrollView
+ contentInsetAdjustmentBehavior="automatic"
+ keyboardShouldPersistTaps="handled"
+ contentContainerClassName="gap-4 px-4 pb-8"
+ >
+ <Input
+ label="Tag Name"
+ labelClasses="text-sm text-muted-foreground"
+ inputClasses="bg-card"
+ onChangeText={setName}
+ onSubmitEditing={onSubmit}
+ value={name}
+ placeholder="Reading"
+ autoFocus
+ autoCapitalize="sentences"
+ returnKeyType="done"
+ />
+
+ <Button disabled={isPending} onPress={onSubmit}>
+ <Text>Save</Text>
+ </Button>
+ </ScrollView>
+ );
+}
diff --git a/apps/mobile/app/dashboard/tags/new.tsx b/apps/mobile/app/dashboard/tags/new.tsx
new file mode 100644
index 00000000..edb2bcfc
--- /dev/null
+++ b/apps/mobile/app/dashboard/tags/new.tsx
@@ -0,0 +1,64 @@
+import { useState } from "react";
+import { ScrollView } from "react-native";
+import { router } from "expo-router";
+import { Button } from "@/components/ui/Button";
+import { Input } from "@/components/ui/Input";
+import { Text } from "@/components/ui/Text";
+import { useToast } from "@/components/ui/Toast";
+
+import { useCreateTag } from "@karakeep/shared-react/hooks/tags";
+
+export default function NewTagPage() {
+ const [name, setName] = useState("");
+ const { toast } = useToast();
+ const { mutate: createTag, isPending } = useCreateTag({
+ onSuccess: () => {
+ toast({ message: "Tag created", variant: "success" });
+ router.back();
+ },
+ onError: (error) => {
+ const message = error.data?.zodError
+ ? Object.values(error.data.zodError.fieldErrors).flat().join("\n")
+ : error.message;
+ toast({
+ message: message || "Something went wrong",
+ variant: "destructive",
+ });
+ },
+ });
+
+ const onSubmit = () => {
+ const trimmedName = name.trim();
+ if (!trimmedName) {
+ toast({ message: "Tag name can't be empty", variant: "destructive" });
+ return;
+ }
+
+ createTag({ name: trimmedName });
+ };
+
+ return (
+ <ScrollView
+ contentInsetAdjustmentBehavior="automatic"
+ keyboardShouldPersistTaps="handled"
+ contentContainerClassName="gap-4 px-4 pb-8"
+ >
+ <Input
+ label="Tag Name"
+ labelClasses="text-sm text-muted-foreground"
+ inputClasses="bg-card"
+ onChangeText={setName}
+ onSubmitEditing={onSubmit}
+ value={name}
+ placeholder="Reading"
+ autoFocus
+ autoCapitalize="sentences"
+ returnKeyType="done"
+ />
+
+ <Button disabled={isPending} onPress={onSubmit}>
+ <Text>Save</Text>
+ </Button>
+ </ScrollView>
+ );
+}