A self-hostable bookmark-everything app (links, notes and images) with AI-based automatic tagging and full text search
feat(mobile): add parent list picker
Mohamed Bassem7ca5ee236b96
diff --git a/apps/mobile/app/dashboard/_layout.tsx b/apps/mobile/app/dashboard/_layout.tsxindex fac26cbb..e864c8ca 100644--- a/apps/mobile/app/dashboard/_layout.tsx+++ b/apps/mobile/app/dashboard/_layout.tsx@@ -178,6 +178,15 @@ export default function Dashboard() {sheetGrabberVisible: true,}}/>+ <Stack.Screen+ name="lists/select-parent"+ options={{+ headerTitle: "Parent List",+ headerBackTitle: "Back",+ headerLargeTitle: false,+ headerTransparent: false,+ }}+ /><Stack.Screenname="archive"options={{diff --git a/apps/mobile/app/dashboard/bookmarks/[slug]/manage_lists.tsx b/apps/mobile/app/dashboard/bookmarks/[slug]/manage_lists.tsxindex 00488c5b..11aa5fda 100644--- a/apps/mobile/app/dashboard/bookmarks/[slug]/manage_lists.tsx+++ b/apps/mobile/app/dashboard/bookmarks/[slug]/manage_lists.tsx@@ -1,13 +1,14 @@-import React from "react";-import { ActivityIndicator, Pressable, ScrollView, View } from "react-native";+import { Pressable, ScrollView } from "react-native";import { Link, Stack, useLocalSearchParams } from "expo-router";+import {+ ListPicker,+ listPathToPickerOption,+} from "@/components/lists/list-picker";import QueryPageState from "@/components/QueryPageState";-import { RowSeparator } from "@/components/ui/GroupedList";-import { Text } from "@/components/ui/Text";import { useToast } from "@/components/ui/Toast";import { useColorScheme } from "@/lib/useColorScheme";import { useQuery } from "@tanstack/react-query";-import { Check, Plus } from "lucide-react-native";+import { Plus } from "lucide-react-native";import { useHeaderHeight } from "expo-router/react-navigation";import type { ZBookmarkList } from "@karakeep/shared/types/lists";@@ -101,6 +102,19 @@ const ListPickerPage = () => {const filteredPaths = allPaths?.filter((path) => path[path.length - 1].userRole !== "viewer").filter((path) => path[path.length - 1].type !== "smart");+ const options =+ filteredPaths?.map((path) => {+ const option = listPathToPickerOption(path);++ return {+ ...option,+ state: isListLoading(option.id)+ ? ("loading" as const)+ : existingLists?.has(option.id)+ ? ("selected" as const)+ : undefined,+ };+ }) ?? [];if (!existingLists || !data) {return (@@ -143,48 +157,11 @@ const ListPickerPage = () => {}}className="flex-1 bg-background">- {filteredPaths && filteredPaths.length > 0 ? (- <View- className="overflow-hidden rounded-xl bg-card"- style={{ borderCurve: "continuous" }}- >- {filteredPaths.map((path, index) => {- const listId = path[path.length - 1].id;- const isLoading = isListLoading(listId);- const isChecked = existingLists?.has(listId);-- return (- <React.Fragment key={listId}>- {index > 0 && <RowSeparator />}- <Pressable- onPress={() => !isLoading && toggleList(listId)}- disabled={isLoading}- className="flex-row items-center justify-between px-4 py-3 active:opacity-70"- >- <Text className="flex-1 pr-3" numberOfLines={1}>- {path- .map((item) => `${item.icon} ${item.name}`)- .join(" / ")}- </Text>- {isLoading ? (- <ActivityIndicator size="small" />- ) : isChecked ? (- <Check- size={20}- color={colors.primary}- strokeWidth={2.5}- />- ) : null}- </Pressable>- </React.Fragment>- );- })}- </View>- ) : (- <View className="items-center py-12">- <Text color="tertiary">No lists available</Text>- </View>- )}+ <ListPicker+ options={options}+ onSelect={toggleList}+ emptyMessage="No lists available"+ /></ScrollView></>);diff --git a/apps/mobile/app/dashboard/lists/[slug]/edit.tsx b/apps/mobile/app/dashboard/lists/[slug]/edit.tsxindex 0b13c706..cd2b0201 100644--- a/apps/mobile/app/dashboard/lists/[slug]/edit.tsx+++ b/apps/mobile/app/dashboard/lists/[slug]/edit.tsx@@ -1,6 +1,7 @@import { useEffect, useState } from "react";import { ScrollView, View } from "react-native";import { router, useLocalSearchParams } from "expo-router";+import { ListParentField } from "@/components/lists/list-parent-field";import QueryPageState from "@/components/QueryPageState";import { Button } from "@/components/ui/Button";import { EmojiPicker } from "@/components/ui/emoji-picker";@@ -8,16 +9,21 @@ 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 { NO_PARENT_VALUE } from "@/lib/list-parent-selection";import { useQuery } from "@tanstack/react-query";import { useEditBookmarkList } from "@karakeep/shared-react/hooks/lists";import { useTRPC } from "@karakeep/shared-react/trpc";const EditListPage = () => {- const { slug: listId } = useLocalSearchParams<{ slug?: string | string[] }>();+ const { slug: listId, selectedParentId } = useLocalSearchParams<{+ slug?: string | string[];+ selectedParentId?: string | string[];+ }>();const [text, setText] = useState("");const [icon, setIcon] = useState("📁");const [query, setQuery] = useState("");+ const [parentId, setParentId] = useState<string | null>(null);const { toast } = useToast();const api = useTRPC();const { mutate, isPending: editIsPending } = useEditBookmarkList({@@ -64,7 +70,14 @@ const EditListPage = () => {setText(list.name ?? "");setIcon(list.icon || "📁");setQuery(list.query ?? "");- }, [list?.icon, list?.id, list?.query, list?.name]);+ setParentId(list.parentId);+ }, [list?.icon, list?.id, list?.parentId, list?.query, list?.name]);++ useEffect(() => {+ if (typeof selectedParentId !== "string") return;+ setParentId(selectedParentId === NO_PARENT_VALUE ? null : selectedParentId);+ router.setParams({ selectedParentId: undefined });+ }, [selectedParentId]);const onSubmit = () => {if (!text.trim()) {@@ -84,6 +97,7 @@ const EditListPage = () => {listId,name: text.trim(),icon,+ parentId,query: list?.type === "smart" ? query.trim() : undefined,});};@@ -138,6 +152,21 @@ const EditListPage = () => {autoCapitalize="sentences"/>+ <ListParentField+ value={parentId}+ onPress={() =>+ router.push({+ pathname: "/dashboard/lists/select-parent",+ params: {+ returnTo: "edit",+ listId,+ selectedParentId: parentId ?? NO_PARENT_VALUE,+ hideSubtreeOf: listId,+ },+ })+ }+ />+{/* Smart List Query Input */}{list?.type === "smart" && (<View className="gap-2">diff --git a/apps/mobile/app/dashboard/lists/new.tsx b/apps/mobile/app/dashboard/lists/new.tsxindex da571b82..1847244b 100644--- a/apps/mobile/app/dashboard/lists/new.tsx+++ b/apps/mobile/app/dashboard/lists/new.tsx@@ -1,17 +1,22 @@import React, { useState } from "react";import { ScrollView, View } from "react-native";-import { router } from "expo-router";+import { router, useLocalSearchParams } from "expo-router";+import { ListParentField } from "@/components/lists/list-parent-field";import { Button } from "@/components/ui/Button";import { EmojiPicker } from "@/components/ui/emoji-picker";import { Input } from "@/components/ui/Input";import { Text } from "@/components/ui/Text";import { useToast } from "@/components/ui/Toast";+import { NO_PARENT_VALUE } from "@/lib/list-parent-selection";import { useCreateBookmarkList } from "@karakeep/shared-react/hooks/lists";type ListType = "manual" | "smart";const NewListPage = () => {+ const { selectedParentId } = useLocalSearchParams<{+ selectedParentId?: string | string[];+ }>();const dismiss = () => {router.back();};@@ -20,6 +25,13 @@ const NewListPage = () => {const [icon, setIcon] = useState("📁");const [listType, setListType] = useState<ListType>("manual");const [query, setQuery] = useState("");+ const [parentId, setParentId] = useState<string | null>(null);++ React.useEffect(() => {+ if (typeof selectedParentId !== "string") return;+ setParentId(selectedParentId === NO_PARENT_VALUE ? null : selectedParentId);+ router.setParams({ selectedParentId: undefined });+ }, [selectedParentId]);const { mutate, isPending } = useCreateBookmarkList({onSuccess: () => {@@ -57,6 +69,7 @@ const NewListPage = () => {icon,type: listType,query: listType === "smart" ? query : undefined,+ parentId,});};@@ -101,6 +114,19 @@ const NewListPage = () => {autoCapitalize="sentences"/>+ <ListParentField+ value={parentId}+ onPress={() =>+ router.push({+ pathname: "/dashboard/lists/select-parent",+ params: {+ returnTo: "new",+ selectedParentId: parentId ?? NO_PARENT_VALUE,+ },+ })+ }+ />+{/* Smart List Query Input */}{listType === "smart" && (<View className="gap-2">diff --git a/apps/mobile/app/dashboard/lists/select-parent.tsx b/apps/mobile/app/dashboard/lists/select-parent.tsxnew file mode 100644index 00000000..92fa60e3--- /dev/null+++ b/apps/mobile/app/dashboard/lists/select-parent.tsx@@ -0,0 +1,116 @@+import { useMemo, useState } from "react";+import { ScrollView } from "react-native";+import { router, Stack, useLocalSearchParams } from "expo-router";+import {+ ListPicker,+ listPathToPickerOption,+} from "@/components/lists/list-picker";+import QueryPageState from "@/components/QueryPageState";+import { NO_PARENT_VALUE } from "@/lib/list-parent-selection";++import { useBookmarkLists } from "@karakeep/shared-react/hooks/lists";++function stringParam(value: string | string[] | undefined) {+ return typeof value === "string" ? value : undefined;+}++export default function SelectListParentPage() {+ const params = useLocalSearchParams<{+ returnTo?: string | string[];+ listId?: string | string[];+ selectedParentId?: string | string[];+ hideSubtreeOf?: string | string[];+ }>();+ const [search, setSearch] = useState("");+ const { data, error, refetch } = useBookmarkLists();+ const returnTo = stringParam(params.returnTo);+ const listId = stringParam(params.listId);+ const hideSubtreeOf = stringParam(params.hideSubtreeOf);+ const selectedParentId = stringParam(params.selectedParentId);+ const selectedId =+ selectedParentId === NO_PARENT_VALUE ? null : selectedParentId;++ const parentOptions = useMemo(() => {+ const normalizedSearch = search.trim().toLowerCase();++ return (data?.allPaths ?? [])+ .filter((path) => {+ const list = path[path.length - 1];+ return (+ list.userRole !== "viewer" &&+ (!hideSubtreeOf || !path.some((item) => item.id === hideSubtreeOf))+ );+ })+ .map(listPathToPickerOption)+ .filter(+ (option) =>+ !normalizedSearch ||+ option.label.toLowerCase().includes(normalizedSearch),+ );+ }, [data?.allPaths, hideSubtreeOf, search]);++ const selectParent = (parentId: string | null) => {+ const selectedParentId = parentId ?? NO_PARENT_VALUE;++ if (returnTo === "edit" && listId) {+ router.dismissTo({+ pathname: "/dashboard/lists/[slug]/edit",+ params: { slug: listId, selectedParentId },+ });+ return;+ }++ router.dismissTo({+ pathname: "/dashboard/lists/new",+ params: { selectedParentId },+ });+ };++ if (!data) {+ return <QueryPageState error={error} onRetry={() => refetch()} />;+ }++ const options = [+ ...(search+ ? []+ : [+ {+ id: NO_PARENT_VALUE,+ label: "No parent",+ state: selectedId === null ? ("selected" as const) : undefined,+ },+ ]),+ ...parentOptions.map((option) => ({+ ...option,+ state: option.id === selectedId ? ("selected" as const) : undefined,+ })),+ ];++ return (+ <>+ <Stack.Screen+ options={{+ headerTitle: "Parent List",+ headerSearchBarOptions: {+ placeholder: "Search Lists",+ autoCapitalize: "none",+ hideWhenScrolling: false,+ onChangeText: (event) => setSearch(event.nativeEvent.text),+ },+ }}+ />+ <ScrollView+ contentInsetAdjustmentBehavior="automatic"+ keyboardShouldPersistTaps="handled"+ contentContainerStyle={{ padding: 16, paddingBottom: 40 }}+ className="flex-1 bg-background"+ >+ <ListPicker+ options={options}+ onSelect={(id) => selectParent(id === NO_PARENT_VALUE ? null : id)}+ emptyMessage="No lists found"+ />+ </ScrollView>+ </>+ );+}diff --git a/apps/mobile/components/lists/list-parent-field.tsx b/apps/mobile/components/lists/list-parent-field.tsxnew file mode 100644index 00000000..cdcc7cfd--- /dev/null+++ b/apps/mobile/components/lists/list-parent-field.tsx@@ -0,0 +1,50 @@+import { ActivityIndicator, Pressable, View } from "react-native";+import { Text } from "@/components/ui/Text";+import { useColorScheme } from "@/lib/useColorScheme";+import { ChevronRight } from "lucide-react-native";++import { useBookmarkLists } from "@karakeep/shared-react/hooks/lists";+import { listNameFromPath } from "@karakeep/shared/utils/listUtils";++export function ListParentField({+ value,+ onPress,+}: {+ value: string | null;+ onPress: () => void;+}) {+ const { colors } = useColorScheme();+ const { data, isPending } = useBookmarkLists();+ const selectedPath = value ? data?.getPathById(value) : undefined;+ const selectedName =+ value === null+ ? "No parent"+ : selectedPath+ ? listNameFromPath(selectedPath)+ : isPending+ ? "Loading..."+ : "Parent unavailable";++ return (+ <View className="gap-2">+ <Text className="text-sm text-muted-foreground">Parent List</Text>+ <Pressable+ accessibilityLabel={`Parent list: ${selectedName}`}+ accessibilityHint="Opens the parent list selection screen"+ accessibilityRole="button"+ onPress={onPress}+ className="min-h-11 flex-row items-center justify-between gap-3 rounded-xl border border-input bg-card px-4 py-3 active:opacity-70"+ style={{ borderCurve: "continuous" }}+ >+ <Text className="flex-1" numberOfLines={1}>+ {selectedName}+ </Text>+ {isPending && value !== null ? (+ <ActivityIndicator size="small" />+ ) : (+ <ChevronRight size={18} color={colors.grey} />+ )}+ </Pressable>+ </View>+ );+}diff --git a/apps/mobile/components/lists/list-picker.tsx b/apps/mobile/components/lists/list-picker.tsxnew file mode 100644index 00000000..62fb2bf5--- /dev/null+++ b/apps/mobile/components/lists/list-picker.tsx@@ -0,0 +1,80 @@+import { ActivityIndicator, Pressable, View } from "react-native";+import { RowSeparator } from "@/components/ui/GroupedList";+import { Text } from "@/components/ui/Text";+import { useColorScheme } from "@/lib/useColorScheme";+import { Check } from "lucide-react-native";++import type { ZBookmarkList } from "@karakeep/shared/types/lists";+import { listNameFromPath } from "@karakeep/shared/utils/listUtils";++export interface ListPickerOption {+ id: string;+ label: string;+ state?: "selected" | "loading";+}++export function listPathToPickerOption(+ path: ZBookmarkList[],+): ListPickerOption {+ return {+ id: path[path.length - 1].id,+ label: listNameFromPath(path),+ };+}++export function ListPicker({+ options,+ onSelect,+ emptyMessage,+}: {+ options: ListPickerOption[];+ onSelect: (id: string) => void;+ emptyMessage: string;+}) {+ const { colors } = useColorScheme();++ if (options.length === 0) {+ return (+ <View className="items-center py-12">+ <Text color="tertiary">{emptyMessage}</Text>+ </View>+ );+ }++ return (+ <View+ className="overflow-hidden rounded-xl bg-card"+ style={{ borderCurve: "continuous" }}+ >+ {options.map((option, index) => {+ const isLoading = option.state === "loading";+ const isSelected = option.state === "selected";++ return (+ <View key={option.id}>+ {index > 0 && <RowSeparator />}+ <Pressable+ accessibilityRole="button"+ accessibilityState={{+ disabled: isLoading,+ selected: isSelected,+ }}+ disabled={isLoading}+ onPress={() => onSelect(option.id)}+ className="min-h-12 flex-row items-center justify-between gap-3 px-4 py-3 active:opacity-70"+ >+ <Text className="flex-1" numberOfLines={2}>+ {option.label}+ </Text>+ {isLoading ? (+ <ActivityIndicator size="small" />+ ) : isSelected ? (+ <Check size={20} color={colors.primary} strokeWidth={2.5} />+ ) : null}+ </Pressable>+ </View>+ );+ })}+ </View>+ );+}diff --git a/apps/mobile/lib/list-parent-selection.ts b/apps/mobile/lib/list-parent-selection.tsnew file mode 100644index 00000000..22725c36--- /dev/null+++ b/apps/mobile/lib/list-parent-selection.ts@@ -0,0 +1 @@+export const NO_PARENT_VALUE = "no-parent";