A self-hostable bookmark-everything app (links, notes and images) with AI-based automatic tagging and full text search
feat(mobile): emoji selector on mobile for list names
Mohamed Bassem428d1f22a4b8
diff --git a/apps/mobile/app/dashboard/lists/[slug]/edit.tsx b/apps/mobile/app/dashboard/lists/[slug]/edit.tsxindex 01a431bb..0b13c706 100644--- a/apps/mobile/app/dashboard/lists/[slug]/edit.tsx+++ b/apps/mobile/app/dashboard/lists/[slug]/edit.tsx@@ -1,8 +1,9 @@import { useEffect, useState } from "react";-import { View } from "react-native";+import { ScrollView, View } from "react-native";import { router, useLocalSearchParams } from "expo-router";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 { Input } from "@/components/ui/Input";import { Text } from "@/components/ui/Text";@@ -15,6 +16,7 @@ import { useTRPC } from "@karakeep/shared-react/trpc";const EditListPage = () => {const { slug: listId } = useLocalSearchParams<{ slug?: string | string[] }>();const [text, setText] = useState("");+ const [icon, setIcon] = useState("π");const [query, setQuery] = useState("");const { toast } = useToast();const api = useTRPC();@@ -60,8 +62,9 @@ const EditListPage = () => {useEffect(() => {if (!list) return;setText(list.name ?? "");+ setIcon(list.icon || "π");setQuery(list.query ?? "");- }, [list?.id, list?.query, list?.name]);+ }, [list?.icon, list?.id, list?.query, list?.name]);const onSubmit = () => {if (!text.trim()) {@@ -80,6 +83,7 @@ const EditListPage = () => {mutate({listId,name: text.trim(),+ icon,query: list?.type === "smart" ? query.trim() : undefined,});};@@ -93,7 +97,11 @@ const EditListPage = () => {{editIsPending ? (<FullPageSpinner />) : (- <View className="gap-3 px-4">+ <ScrollView+ contentInsetAdjustmentBehavior="automatic"+ keyboardShouldPersistTaps="handled"+ contentContainerClassName="gap-4 px-4 pb-8"+ >{/* List Type Info - not editable */}<View className="gap-2"><Text className="text-sm text-muted-foreground">List Type</Text>@@ -117,18 +125,18 @@ const EditListPage = () => {</View></View>- {/* List Name */}- <View className="flex flex-row items-center gap-1">- <Text className="shrink p-2">{list?.icon || "π"}</Text>- <Input- className="flex-1 bg-card"- onChangeText={setText}- value={text}- placeholder="List Name"- autoFocus- autoCapitalize={"none"}- />- </View>+ <EmojiPicker value={icon} onChange={setIcon} />++ <Input+ className="bg-card"+ label="List Name"+ labelClasses="text-sm text-muted-foreground"+ onChangeText={setText}+ value={text}+ placeholder="Reading list"+ autoFocus+ autoCapitalize="sentences"+ />{/* Smart List Query Input */}{list?.type === "smart" && (@@ -153,7 +161,7 @@ const EditListPage = () => {<Button disabled={editIsPending} onPress={onSubmit}><Text>Save</Text></Button>- </View>+ </ScrollView>)}</>);diff --git a/apps/mobile/app/dashboard/lists/new.tsx b/apps/mobile/app/dashboard/lists/new.tsxindex 1fd9593a..da571b82 100644--- a/apps/mobile/app/dashboard/lists/new.tsx+++ b/apps/mobile/app/dashboard/lists/new.tsx@@ -1,7 +1,8 @@import React, { useState } from "react";-import { View } from "react-native";+import { ScrollView, View } from "react-native";import { router } from "expo-router";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";@@ -16,6 +17,7 @@ const NewListPage = () => {};const { toast } = useToast();const [text, setText] = useState("");+ const [icon, setIcon] = useState("π");const [listType, setListType] = useState<ListType>("manual");const [query, setQuery] = useState("");@@ -52,14 +54,18 @@ const NewListPage = () => {mutate({name: text,- icon: "π",+ icon,type: listType,query: listType === "smart" ? query : undefined,});};return (- <View className="gap-3 px-4">+ <ScrollView+ contentInsetAdjustmentBehavior="automatic"+ keyboardShouldPersistTaps="handled"+ contentContainerClassName="gap-4 px-4 pb-8"+ >{/* List Type Selector */}<View className="gap-2"><Text className="text-sm text-muted-foreground">List Type</Text>@@ -83,17 +89,17 @@ const NewListPage = () => {</View></View>- {/* List Name */}- <View className="flex flex-row items-center gap-1">- <Text className="shrink p-2">π</Text>- <Input- className="flex-1 bg-card"- onChangeText={setText}- placeholder="List Name"- autoFocus- autoCapitalize={"none"}- />- </View>+ <EmojiPicker value={icon} onChange={setIcon} />++ <Input+ className="bg-card"+ label="List Name"+ labelClasses="text-sm text-muted-foreground"+ onChangeText={setText}+ placeholder="Reading list"+ autoFocus+ autoCapitalize="sentences"+ />{/* Smart List Query Input */}{listType === "smart" && (@@ -115,7 +121,7 @@ const NewListPage = () => {<Button disabled={isPending} onPress={onSubmit}><Text>Save</Text></Button>- </View>+ </ScrollView>);};diff --git a/apps/mobile/components/ui/emoji-picker.tsx b/apps/mobile/components/ui/emoji-picker.tsxnew file mode 100644index 00000000..f2f14148--- /dev/null+++ b/apps/mobile/components/ui/emoji-picker.tsx@@ -0,0 +1,323 @@+import type { Emoji, EmojiMartData } from "@emoji-mart/data";+import { memo, useCallback, useEffect, useMemo, useRef, useState } from "react";+import {+ KeyboardAvoidingView,+ Modal,+ Pressable,+ ScrollView,+ useWindowDimensions,+ View,+} from "react-native";+import * as Haptics from "expo-haptics";+import { useSafeAreaInsets } from "react-native-safe-area-context";+import emojiData from "@emoji-mart/data";+import type { FlashListRef } from "@shopify/flash-list";+import { FlashList } from "@shopify/flash-list";+import { ChevronDown, Search, X } from "lucide-react-native";++import { useColorScheme } from "@/lib/useColorScheme";++import { Input } from "./Input";+import { Text } from "./Text";++const data = emojiData as EmojiMartData;++const CATEGORY_DETAILS: Record<string, { label: string; icon: string }> = {+ people: { label: "Smileys & people", icon: "π" },+ nature: { label: "Animals & nature", icon: "π»" },+ foods: { label: "Food & drink", icon: "π" },+ activity: { label: "Activities", icon: "β½οΈ" },+ places: { label: "Travel & places", icon: "π" },+ objects: { label: "Objects", icon: "π‘" },+ symbols: { label: "Symbols", icon: "β€οΈ" },+ flags: { label: "Flags", icon: "π³οΈ" },+};++const COLUMN_COUNT = 8;++interface EmojiChoice extends Emoji {+ categoryId: string;+ searchText: string;+}++const emojiCategories = data.categories.filter(+ (category) => CATEGORY_DETAILS[category.id],+);++const emojisByCategory = Object.fromEntries(+ emojiCategories.map((category) => [+ category.id,+ category.emojis+ .map((id) => {+ const emoji = data.emojis[id];+ if (!emoji) return undefined;+ return {+ ...emoji,+ categoryId: category.id,+ searchText: [emoji.id, emoji.name, ...emoji.keywords]+ .join(" ")+ .toLocaleLowerCase(),+ } satisfies EmojiChoice;+ })+ .filter((emoji): emoji is EmojiChoice => emoji !== undefined),+ ]),+) as Record<string, EmojiChoice[]>;++const allEmojis = emojiCategories.flatMap(+ (category) => emojisByCategory[category.id],+);++interface EmojiCellProps {+ emoji: EmojiChoice;+ selectedEmoji: string;+ size: number;+ onSelect: (emoji: string) => void;+}++const EmojiCell = memo(function EmojiCell({+ emoji,+ selectedEmoji,+ size,+ onSelect,+}: EmojiCellProps) {+ const glyph = emoji.skins[0].native;+ const selected = emoji.skins.some((skin) => skin.native === selectedEmoji);++ return (+ <Pressable+ accessibilityRole="button"+ accessibilityLabel={`Choose ${emoji.name}`}+ accessibilityState={{ selected }}+ className={+ selected+ ? "items-center justify-center rounded-xl bg-primary/15"+ : "items-center justify-center rounded-xl active:bg-primary/10"+ }+ style={{ width: size, height: size, borderCurve: "continuous" }}+ onPress={() => onSelect(glyph)}+ >+ <Text className="text-[27px] leading-9">{glyph}</Text>+ </Pressable>+ );+});++interface EmojiPickerProps {+ value: string;+ onChange: (emoji: string) => void;+}++export function EmojiPicker({ value, onChange }: EmojiPickerProps) {+ const [visible, setVisible] = useState(false);+ const [activeCategory, setActiveCategory] = useState("people");+ const [searchQuery, setSearchQuery] = useState("");+ const emojiListRef = useRef<FlashListRef<EmojiChoice>>(null);+ const { width, height } = useWindowDimensions();+ const insets = useSafeAreaInsets();+ const { colors } = useColorScheme();++ const sheetWidth = Math.min(width, 520);+ const emojiSize = Math.floor((sheetWidth - 24) / COLUMN_COUNT);+ const normalizedQuery = searchQuery.trim().toLocaleLowerCase();+ const visibleEmojis = useMemo(() => {+ if (!normalizedQuery) {+ return emojisByCategory[activeCategory] ?? [];+ }++ const terms = normalizedQuery.split(/\s+/);+ return allEmojis.filter((emoji) =>+ terms.every((term) => emoji.searchText.includes(term)),+ );+ }, [activeCategory, normalizedQuery]);++ useEffect(() => {+ emojiListRef.current?.scrollToOffset({ offset: 0, animated: false });+ }, [activeCategory, normalizedQuery]);++ const closePicker = useCallback(() => {+ setVisible(false);+ setSearchQuery("");+ }, []);++ const selectEmoji = useCallback(+ (emoji: string) => {+ if (process.env.EXPO_OS === "ios") {+ void Haptics.selectionAsync();+ }+ onChange(emoji);+ closePicker();+ },+ [closePicker, onChange],+ );++ const renderEmoji = useCallback(+ ({ item }: { item: EmojiChoice }) => (+ <EmojiCell+ emoji={item}+ selectedEmoji={value}+ size={emojiSize}+ onSelect={selectEmoji}+ />+ ),+ [emojiSize, selectEmoji, value],+ );++ const categoryLabel = normalizedQuery+ ? `${visibleEmojis.length} results`+ : CATEGORY_DETAILS[activeCategory].label;++ return (+ <>+ <View className="gap-1.5">+ <Text className="text-sm text-muted-foreground">Icon</Text>+ <Pressable+ accessibilityRole="button"+ accessibilityLabel={`List icon: ${value}. Open emoji picker`}+ className="h-14 flex-row items-center rounded-xl border border-input bg-card px-3 active:opacity-70"+ style={{ borderCurve: "continuous" }}+ onPress={() => setVisible(true)}+ >+ <View className="h-10 w-10 items-center justify-center rounded-lg bg-background">+ <Text className="text-2xl leading-8">{value}</Text>+ </View>+ <View className="flex-1 px-3">+ <Text className="font-medium">List icon</Text>+ <Text className="text-xs text-muted-foreground">+ Search the full emoji library+ </Text>+ </View>+ <ChevronDown size={18} color={colors.grey} />+ </Pressable>+ </View>++ <Modal+ visible={visible}+ transparent+ animationType="slide"+ onRequestClose={closePicker}+ >+ <KeyboardAvoidingView+ className="flex-1 items-center justify-end"+ behavior={process.env.EXPO_OS === "ios" ? "padding" : undefined}+ >+ <Pressable+ accessibilityLabel="Close emoji picker"+ className="absolute inset-0 bg-black/40"+ onPress={closePicker}+ />+ <View+ className="w-full overflow-hidden rounded-t-[28px] bg-card pt-3"+ style={{+ maxWidth: 520,+ height: Math.min(height * 0.82, 720),+ paddingBottom: Math.max(insets.bottom, 12),+ borderCurve: "continuous",+ }}+ >+ <View className="h-1 w-10 self-center rounded-full bg-muted" />+ <View className="flex-row items-center justify-between px-5 py-4">+ <Text className="text-xl font-semibold">Choose an icon</Text>+ <Pressable+ accessibilityRole="button"+ accessibilityLabel="Close"+ className="h-9 w-9 items-center justify-center rounded-full bg-background active:opacity-70"+ onPress={closePicker}+ >+ <X size={18} color={colors.foreground} />+ </Pressable>+ </View>++ <View className="px-3 pb-2">+ <View className="justify-center">+ <View+ pointerEvents="none"+ className="absolute left-3 z-10 items-center justify-center"+ >+ <Search size={18} color={colors.grey} />+ </View>+ <Input+ value={searchQuery}+ onChangeText={setSearchQuery}+ placeholder="Search emoji"+ autoCapitalize="none"+ autoCorrect={false}+ returnKeyType="done"+ inputClasses="h-11 rounded-xl bg-background pl-10 pr-10"+ />+ {searchQuery.length > 0 && (+ <Pressable+ accessibilityRole="button"+ accessibilityLabel="Clear search"+ className="absolute right-2 h-8 w-8 items-center justify-center rounded-full"+ onPress={() => setSearchQuery("")}+ >+ <X size={16} color={colors.grey} />+ </Pressable>+ )}+ </View>+ </View>++ <ScrollView+ horizontal+ className="h-12 flex-grow-0"+ showsHorizontalScrollIndicator={false}+ contentContainerClassName="gap-1 px-3 pb-2"+ keyboardShouldPersistTaps="handled"+ >+ {emojiCategories.map((category) => {+ const details = CATEGORY_DETAILS[category.id];+ const selected =+ !normalizedQuery && activeCategory === category.id;+ return (+ <Pressable+ key={category.id}+ accessibilityRole="tab"+ accessibilityLabel={details.label}+ accessibilityState={{ selected }}+ className={+ selected+ ? "h-10 w-10 items-center justify-center rounded-xl bg-primary/15"+ : "h-10 w-10 items-center justify-center rounded-xl active:bg-primary/10"+ }+ style={{ borderCurve: "continuous" }}+ onPress={() => {+ setSearchQuery("");+ setActiveCategory(category.id);+ }}+ >+ <Text className="text-xl leading-7">{details.icon}</Text>+ </Pressable>+ );+ })}+ </ScrollView>++ <View className="px-4 py-1">+ <Text className="text-sm font-medium text-muted-foreground">+ {categoryLabel}+ </Text>+ </View>++ <FlashList+ ref={emojiListRef}+ data={visibleEmojis}+ numColumns={COLUMN_COUNT}+ renderItem={renderEmoji}+ keyExtractor={(item) => item.id}+ keyboardDismissMode="interactive"+ keyboardShouldPersistTaps="handled"+ maintainVisibleContentPosition={{ disabled: true }}+ contentContainerStyle={{ paddingHorizontal: 12, paddingTop: 4 }}+ ListEmptyComponent={+ <View className="items-center gap-1 py-16">+ <Text className="text-lg font-medium">No emoji found</Text>+ <Text className="text-sm text-muted-foreground">+ Try a different search+ </Text>+ </View>+ }+ />+ </View>+ </KeyboardAvoidingView>+ </Modal>+ </>+ );+}diff --git a/apps/mobile/package.json b/apps/mobile/package.jsonindex 0e025bf8..f626391a 100644--- a/apps/mobile/package.json+++ b/apps/mobile/package.json@@ -20,6 +20,7 @@"typecheck": "tsc --noEmit"},"dependencies": {+ "@emoji-mart/data": "^1.1.2","@expo/dom-webview": "~56.0.6","@expo/metro-runtime": "~56.0.16","@expo/ui": "56.0.21",diff --git a/pnpm-lock.yaml b/pnpm-lock.yamlindex a5a05522..5cc4bcd7 100644--- a/pnpm-lock.yaml+++ b/pnpm-lock.yaml@@ -326,6 +326,9 @@ importers:apps/mobile:dependencies:+ '@emoji-mart/data':+ specifier: ^1.1.2+ version: 1.1.2'@expo/dom-webview':specifier: ~56.0.6version: 56.0.6([email protected])([email protected](patch_hash=7d74c7fbd33e9f3f3f8a8ba47a013acfc098948e39c7faab1232e6edca358ac1)(@babel/[email protected])(@react-native/[email protected](@babel/[email protected]))(@types/[email protected])([email protected]))([email protected])