From 7c04276bacf6e9ecc0cce4a2ece7a25dc8e5deaa Mon Sep 17 00:00:00 2001
From: MohamedBassem <me@mbassem.com>
Date: Tue, 20 Feb 2024 14:05:53 +0000
Subject: ui: hydrate the react query cache in the client side components

---
 .../app/dashboard/bookmarks/components/BookmarksGrid.tsx  | 15 ++++++++++++---
 1 file changed, 12 insertions(+), 3 deletions(-)

(limited to 'packages/web/app/dashboard/bookmarks/components/BookmarksGrid.tsx')

diff --git a/packages/web/app/dashboard/bookmarks/components/BookmarksGrid.tsx b/packages/web/app/dashboard/bookmarks/components/BookmarksGrid.tsx
index 1963a980..c1c8f3e0 100644
--- a/packages/web/app/dashboard/bookmarks/components/BookmarksGrid.tsx
+++ b/packages/web/app/dashboard/bookmarks/components/BookmarksGrid.tsx
@@ -3,7 +3,8 @@
 import { useLoadingCard } from "@/lib/hooks/use-loading-card";
 import BookmarkCardSkeleton from "./BookmarkCardSkeleton";
 import LinkCard from "./LinkCard";
-import { ZBookmark } from "@/lib/types/api/bookmarks";
+import { ZBookmark, ZGetBookmarksRequest } from "@/lib/types/api/bookmarks";
+import { api } from "@/lib/trpc";
 
 function renderBookmark(bookmark: ZBookmark) {
   switch (bookmark.content.type) {
@@ -12,16 +13,24 @@ function renderBookmark(bookmark: ZBookmark) {
   }
 }
 
+export const dynamic = "force-dynamic";
+
 export default function BookmarksGrid({
-  bookmarks,
+  query,
+  bookmarks: initialBookmarks,
 }: {
+  query: ZGetBookmarksRequest;
   bookmarks: ZBookmark[];
 }) {
+  const { data } = api.bookmarks.getBookmarks.useQuery(query, {
+    initialData: { bookmarks: initialBookmarks },
+    staleTime: Infinity,
+  });
   const { loading } = useLoadingCard();
   return (
     <div className="container grid grid-cols-1 gap-4 sm:grid-cols-1 md:grid-cols-2 lg:grid-cols-3">
       {loading && <BookmarkCardSkeleton />}
-      {bookmarks.map((b) => renderBookmark(b))}
+      {data.bookmarks.map((b) => renderBookmark(b))}
     </div>
   );
 }
-- 
cgit v1.2.3-70-g09d2

