aboutsummaryrefslogtreecommitdiffstats
path: root/packages/mobile/components/bookmarks/BookmarkList.tsx
diff options
context:
space:
mode:
authorMohamedBassem <me@mbassem.com>2024-03-13 02:43:57 +0000
committerMohamedBassem <me@mbassem.com>2024-03-13 02:43:57 +0000
commitbe518d51eaf57a1f0e04b7608d9a4362a516eb85 (patch)
tree26661e3383c495006720d212304556072ad8f006 /packages/mobile/components/bookmarks/BookmarkList.tsx
parentf1d86812e9a045b474f4a1c8cd3621fe17b8b806 (diff)
downloadkarakeep-be518d51eaf57a1f0e04b7608d9a4362a516eb85.tar.zst
mobile: All bookmarks homepage
Diffstat (limited to 'packages/mobile/components/bookmarks/BookmarkList.tsx')
-rw-r--r--packages/mobile/components/bookmarks/BookmarkList.tsx48
1 files changed, 48 insertions, 0 deletions
diff --git a/packages/mobile/components/bookmarks/BookmarkList.tsx b/packages/mobile/components/bookmarks/BookmarkList.tsx
new file mode 100644
index 00000000..bb4b8668
--- /dev/null
+++ b/packages/mobile/components/bookmarks/BookmarkList.tsx
@@ -0,0 +1,48 @@
+import { useEffect, useState } from "react";
+import { FlatList } from "react-native";
+
+import BookmarkCard from "./BookmarkCard";
+
+import { api } from "@/lib/trpc";
+
+export default function BookmarkList({
+ favourited,
+ archived,
+}: {
+ favourited?: boolean;
+ archived?: boolean;
+}) {
+ const apiUtils = api.useUtils();
+ const [refreshing, setRefreshing] = useState(false);
+ const { data, isPending, isPlaceholderData } =
+ api.bookmarks.getBookmarks.useQuery({
+ favourited,
+ archived,
+ });
+
+ useEffect(() => {
+ setRefreshing(isPending || isPlaceholderData);
+ }, [isPending, isPlaceholderData]);
+
+ if (isPending || !data) {
+ // TODO: Add a spinner
+ return;
+ }
+
+ const onRefresh = () => {
+ apiUtils.bookmarks.getBookmarks.invalidate();
+ apiUtils.bookmarks.getBookmark.invalidate();
+ };
+
+ return (
+ <FlatList
+ contentContainerStyle={{
+ gap: 10,
+ }}
+ renderItem={(b) => <BookmarkCard key={b.item.id} bookmark={b.item} />}
+ data={data.bookmarks}
+ refreshing={refreshing}
+ onRefresh={onRefresh}
+ />
+ );
+}