|
1 | 1 | import { useEffect, useState } from "react"; |
2 | | -import { FlatList, Pressable, View } from "react-native"; |
3 | | -import { Link } from "expo-router"; |
| 2 | +import { |
| 3 | + FlatList, |
| 4 | + Platform, |
| 5 | + PlatformColor, |
| 6 | + Pressable, |
| 7 | + View, |
| 8 | +} from "react-native"; |
| 9 | +import * as Haptics from "expo-haptics"; |
| 10 | +import { Link, router } from "expo-router"; |
4 | 11 | import QueryPageState from "@/components/QueryPageState"; |
5 | 12 | import ChevronRight from "@/components/ui/ChevronRight"; |
6 | 13 | import EmptyState from "@/components/ui/EmptyState"; |
| 14 | +import { FAB } from "@/components/ui/FAB"; |
7 | 15 | import { SearchInput } from "@/components/ui/SearchInput"; |
8 | 16 | import { Text } from "@/components/ui/Text"; |
9 | 17 | import { useQueryClient } from "@tanstack/react-query"; |
10 | | -import { Tag } from "lucide-react-native"; |
| 18 | +import { Plus, Tag } from "lucide-react-native"; |
11 | 19 |
|
12 | 20 | import { usePaginatedSearchTags } from "@karakeep/shared-react/hooks/tags"; |
13 | 21 | import { useDebounce } from "@karakeep/shared-react/hooks/use-debounce"; |
@@ -70,68 +78,86 @@ export default function Tags() { |
70 | 78 | }; |
71 | 79 |
|
72 | 80 | return ( |
73 | | - <FlatList |
74 | | - className="h-full" |
75 | | - contentInsetAdjustmentBehavior="automatic" |
76 | | - ListHeaderComponent={ |
77 | | - <SearchInput |
78 | | - containerClassName="mx-2 mb-2" |
79 | | - placeholder="Search tags..." |
80 | | - value={searchQuery} |
81 | | - onChangeText={setSearchQuery} |
82 | | - /> |
83 | | - } |
84 | | - contentContainerStyle={{ |
85 | | - gap: 6, |
86 | | - paddingBottom: 20, |
87 | | - }} |
88 | | - renderItem={(item) => ( |
89 | | - <View |
90 | | - className="mx-2 flex flex-row items-center rounded-xl bg-card px-4 py-2" |
91 | | - style={{ borderCurve: "continuous" }} |
92 | | - > |
93 | | - <Link |
94 | | - asChild |
95 | | - key={item.item.id} |
96 | | - href={item.item.href} |
97 | | - className="flex-1" |
| 81 | + <> |
| 82 | + <FlatList |
| 83 | + className="h-full" |
| 84 | + contentInsetAdjustmentBehavior="automatic" |
| 85 | + ListHeaderComponent={ |
| 86 | + <SearchInput |
| 87 | + containerClassName="mx-2 mb-2" |
| 88 | + placeholder="Search tags..." |
| 89 | + value={searchQuery} |
| 90 | + onChangeText={setSearchQuery} |
| 91 | + /> |
| 92 | + } |
| 93 | + contentContainerStyle={{ |
| 94 | + gap: 6, |
| 95 | + paddingBottom: 20, |
| 96 | + }} |
| 97 | + renderItem={(item) => ( |
| 98 | + <View |
| 99 | + className="mx-2 flex flex-row items-center rounded-xl bg-card px-4 py-2" |
| 100 | + style={{ borderCurve: "continuous" }} |
98 | 101 | > |
99 | | - <Pressable className="flex flex-row items-center justify-between"> |
100 | | - <View className="flex-1"> |
101 | | - <Text className="font-medium">{item.item.name}</Text> |
102 | | - <Text className="text-sm text-muted-foreground"> |
103 | | - {item.item.numBookmarks}{" "} |
104 | | - {item.item.numBookmarks === 1 ? "bookmark" : "bookmarks"} |
105 | | - </Text> |
106 | | - </View> |
107 | | - <ChevronRight /> |
108 | | - </Pressable> |
109 | | - </Link> |
110 | | - </View> |
111 | | - )} |
112 | | - data={tags} |
113 | | - refreshing={refreshing} |
114 | | - onRefresh={onRefresh} |
115 | | - onEndReached={handleLoadMore} |
116 | | - onEndReachedThreshold={0.5} |
117 | | - ListFooterComponent={ |
118 | | - isFetchingNextPage ? ( |
119 | | - <View className="py-4"> |
120 | | - <Text className="text-center text-muted-foreground"> |
121 | | - Loading more... |
122 | | - </Text> |
| 102 | + <Link |
| 103 | + asChild |
| 104 | + key={item.item.id} |
| 105 | + href={item.item.href} |
| 106 | + className="flex-1" |
| 107 | + > |
| 108 | + <Pressable className="flex flex-row items-center justify-between"> |
| 109 | + <View className="flex-1"> |
| 110 | + <Text className="font-medium">{item.item.name}</Text> |
| 111 | + <Text className="text-sm text-muted-foreground"> |
| 112 | + {item.item.numBookmarks}{" "} |
| 113 | + {item.item.numBookmarks === 1 ? "bookmark" : "bookmarks"} |
| 114 | + </Text> |
| 115 | + </View> |
| 116 | + <ChevronRight /> |
| 117 | + </Pressable> |
| 118 | + </Link> |
123 | 119 | </View> |
124 | | - ) : null |
125 | | - } |
126 | | - ListEmptyComponent={ |
127 | | - !isPending ? ( |
128 | | - <EmptyState |
129 | | - icon={Tag} |
130 | | - title="No Tags" |
131 | | - subtitle="Tags will appear as you organize your bookmarks" |
| 120 | + )} |
| 121 | + data={tags} |
| 122 | + refreshing={refreshing} |
| 123 | + onRefresh={onRefresh} |
| 124 | + onEndReached={handleLoadMore} |
| 125 | + onEndReachedThreshold={0.5} |
| 126 | + ListFooterComponent={ |
| 127 | + isFetchingNextPage ? ( |
| 128 | + <View className="py-4"> |
| 129 | + <Text className="text-center text-muted-foreground"> |
| 130 | + Loading more... |
| 131 | + </Text> |
| 132 | + </View> |
| 133 | + ) : null |
| 134 | + } |
| 135 | + ListEmptyComponent={ |
| 136 | + !isPending ? ( |
| 137 | + <EmptyState |
| 138 | + icon={Tag} |
| 139 | + title="No Tags" |
| 140 | + subtitle="Tags will appear as you organize your bookmarks" |
| 141 | + /> |
| 142 | + ) : null |
| 143 | + } |
| 144 | + /> |
| 145 | + <FAB> |
| 146 | + <Pressable |
| 147 | + accessibilityLabel="Create tag" |
| 148 | + accessibilityRole="button" |
| 149 | + className="h-full w-full items-center justify-center" |
| 150 | + onPress={() => { |
| 151 | + void Haptics.selectionAsync(); |
| 152 | + router.push("/dashboard/tags/new"); |
| 153 | + }} |
| 154 | + > |
| 155 | + <Plus |
| 156 | + size={24} |
| 157 | + color={Platform.OS === "ios" ? PlatformColor("label") : "white"} |
132 | 158 | /> |
133 | | - ) : null |
134 | | - } |
135 | | - /> |
| 159 | + </Pressable> |
| 160 | + </FAB> |
| 161 | + </> |
136 | 162 | ); |
137 | 163 | } |
0 commit comments